xref: /OK3568_Linux_fs/yocto/poky/meta-yocto-bsp/lib/oeqa/controllers/edgeroutertarget.py (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# Copyright (C) 2014 Intel Corporation
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# Released under the MIT license (see COPYING.MIT)
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun# This module adds support to testimage.bbclass to deploy images and run
6*4882a593Smuzhiyun# tests on a Ubiquiti Networks EdgeRouter Lite. The device must be set up
7*4882a593Smuzhiyun# to boot into the master image already - the easiest way to do that is as
8*4882a593Smuzhiyun# follows:
9*4882a593Smuzhiyun#
10*4882a593Smuzhiyun# 1. Take out the internal USB drive and plug it into your PC
11*4882a593Smuzhiyun# 2. Repartition the USB drive so that you have three partitions in this
12*4882a593Smuzhiyun#    order:
13*4882a593Smuzhiyun#      1: vfat, labelled "boot" (it will need to be formatted with mkfs.vfat
14*4882a593Smuzhiyun#         for this to be possible, since FAT partitions formatted under
15*4882a593Smuzhiyun#         DOS/Windows will only support uppercase labels)
16*4882a593Smuzhiyun#      2: ext3 (for master image) labelled "testmaster"
17*4882a593Smuzhiyun#      3: ext3 (for image under test) labelled "testrootfs"
18*4882a593Smuzhiyun# 3. Copy the kernel to be used by the master image to the FAT partition
19*4882a593Smuzhiyun#    (it should be named "vmlinux.64" with the factory u-boot configuration)
20*4882a593Smuzhiyun# 4. Install the master image onto the "testmaster" ext3 partition. If
21*4882a593Smuzhiyun#    you do this by just extracting the contents of an image onto the
22*4882a593Smuzhiyun#    partition, you will also likely need to create the master image marker
23*4882a593Smuzhiyun#    file /etc/masterimage within this partition so that we can tell when
24*4882a593Smuzhiyun#    we're booted into it that it is the master image.
25*4882a593Smuzhiyun# 5. Put the USB drive back into the device, and ensure the console port
26*4882a593Smuzhiyun#    and first ethernet port are connected before powering on
27*4882a593Smuzhiyun#
28*4882a593Smuzhiyun# TEST_SERIALCONTROL_CMD will need to be set in local.conf so that we can
29*4882a593Smuzhiyun# interact with u-boot over the serial console port.
30*4882a593Smuzhiyun
31*4882a593Smuzhiyunimport os
32*4882a593Smuzhiyunimport bb
33*4882a593Smuzhiyunimport time
34*4882a593Smuzhiyunimport subprocess
35*4882a593Smuzhiyunimport sys
36*4882a593Smuzhiyunimport pexpect
37*4882a593Smuzhiyun
38*4882a593Smuzhiyunfrom oeqa.controllers.controllerimage import ControllerImageHardwareTarget
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun
41*4882a593Smuzhiyunclass EdgeRouterTarget(ControllerImageHardwareTarget):
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun    def __init__(self, d):
44*4882a593Smuzhiyun        super(EdgeRouterTarget, self).__init__(d)
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun        self.image_fstype = self.get_image_fstype(d)
47*4882a593Smuzhiyun        self.deploy_cmds = [
48*4882a593Smuzhiyun                'mount -L boot /boot',
49*4882a593Smuzhiyun                'mkdir -p /mnt/testrootfs',
50*4882a593Smuzhiyun                'mount -L testrootfs /mnt/testrootfs',
51*4882a593Smuzhiyun                'cp ~/test-kernel /boot',
52*4882a593Smuzhiyun                'rm -rf /mnt/testrootfs/*',
53*4882a593Smuzhiyun                'tar xvf ~/test-rootfs.%s -C /mnt/testrootfs' % self.image_fstype
54*4882a593Smuzhiyun                ]
55*4882a593Smuzhiyun        if not self.serialcontrol_cmd:
56*4882a593Smuzhiyun            bb.fatal("This TEST_TARGET needs a TEST_SERIALCONTROL_CMD defined in local.conf.")
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun    def _deploy(self):
60*4882a593Smuzhiyun        self.controller.run("umount /mnt/testrootfs;")
61*4882a593Smuzhiyun        self.controller.ignore_status = False
62*4882a593Smuzhiyun        self.controller.copy_to(self.kernel, "~/test-kernel")
63*4882a593Smuzhiyun        self.controller.copy_to(self.rootfs, "~/test-rootfs.%s" % self.image_fstype)
64*4882a593Smuzhiyun        for cmd in self.deploy_cmds:
65*4882a593Smuzhiyun            self.controller.run(cmd)
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun    def _start(self, params=None):
68*4882a593Smuzhiyun        self.power_cycle(self.controller)
69*4882a593Smuzhiyun        try:
70*4882a593Smuzhiyun            serialconn = pexpect.spawn(self.serialcontrol_cmd, env=self.origenv, logfile=sys.stdout)
71*4882a593Smuzhiyun            serialconn.expect("U-Boot")
72*4882a593Smuzhiyun            serialconn.sendline("a")
73*4882a593Smuzhiyun            serialconn.expect("Octeon ubnt_e100#")
74*4882a593Smuzhiyun            serialconn.sendline("fatload usb 0:1 $loadaddr test-kernel")
75*4882a593Smuzhiyun            serialconn.expect(" bytes read")
76*4882a593Smuzhiyun            serialconn.expect("Octeon ubnt_e100#")
77*4882a593Smuzhiyun            serialconn.sendline("bootoctlinux $loadaddr coremask=0x3 root=/dev/sda3 rw rootwait mtdparts=phys_mapped_flash:512k(boot0),512k(boot1),64k@3072k(eeprom)")
78*4882a593Smuzhiyun            serialconn.expect("login:", timeout=120)
79*4882a593Smuzhiyun            serialconn.close()
80*4882a593Smuzhiyun        except pexpect.ExceptionPexpect as e:
81*4882a593Smuzhiyun            bb.fatal('Serial interaction failed: %s' % str(e))
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun    def _wait_until_booted(self):
84*4882a593Smuzhiyun        try:
85*4882a593Smuzhiyun            serialconn = pexpect.spawn(self.serialcontrol_cmd, env=self.origenv, logfile=sys.stdout)
86*4882a593Smuzhiyun            serialconn.expect("login:", timeout=120)
87*4882a593Smuzhiyun            serialconn.close()
88*4882a593Smuzhiyun        except pexpect.ExceptionPexpect as e:
89*4882a593Smuzhiyun            bb.fatal('Serial interaction failed: %s' % str(e))
90