1eb8dc403SDave Cobbley# Copyright (C) 2014 Intel Corporation 2eb8dc403SDave Cobbley# 3eb8dc403SDave Cobbley# Released under the MIT license (see COPYING.MIT) 4eb8dc403SDave Cobbley 5eb8dc403SDave Cobbley# This module adds support to testimage.bbclass to deploy images and run 6eb8dc403SDave Cobbley# tests on a BeagleBone (original "white" or Black models). The device must 7eb8dc403SDave Cobbley# be set up as per README.hardware and the master image should be deployed 8eb8dc403SDave Cobbley# onto the card so that it boots into it by default. For booting into the 9eb8dc403SDave Cobbley# image under test we interact with u-boot over serial, so for the 10eb8dc403SDave Cobbley# BeagleBone Black you will need an additional TTL serial cable since a 11eb8dc403SDave Cobbley# serial interface isn't automatically provided over the USB connection as 12eb8dc403SDave Cobbley# it is on the original BeagleBone ("white") version. The separate ext3 13eb8dc403SDave Cobbley# partition that will contain the image to be tested must be labelled 14eb8dc403SDave Cobbley# "testrootfs" so that the deployment code below can find it. 15eb8dc403SDave Cobbley# 16eb8dc403SDave Cobbley# NOTE: for the BeagleBone "white" (original version) you may need to use 17eb8dc403SDave Cobbley# a script which handles the serial device disappearing on power down, such 18eb8dc403SDave Cobbley# as scripts/contrib/serdevtry in OE-Core. 19eb8dc403SDave Cobbley 20eb8dc403SDave Cobbleyimport os 21eb8dc403SDave Cobbleyimport bb 22eb8dc403SDave Cobbleyimport time 23eb8dc403SDave Cobbleyimport subprocess 24eb8dc403SDave Cobbleyimport sys 25eb8dc403SDave Cobbleyimport pexpect 26eb8dc403SDave Cobbley 27*7e0e3c0cSAndrew Geisslerfrom oeqa.controllers.controllerimage import ControllerImageHardwareTarget 28eb8dc403SDave Cobbley 29eb8dc403SDave Cobbley 30*7e0e3c0cSAndrew Geisslerclass BeagleBoneTarget(ControllerImageHardwareTarget): 31eb8dc403SDave Cobbley 32eb8dc403SDave Cobbley dtbs = {'uImage-am335x-bone.dtb': 'am335x-bone.dtb', 'uImage-am335x-boneblack.dtb': 'am335x-boneblack.dtb'} 33eb8dc403SDave Cobbley 34eb8dc403SDave Cobbley @classmethod 35eb8dc403SDave Cobbley def get_extra_files(self): 36eb8dc403SDave Cobbley return list(self.dtbs.keys()) 37eb8dc403SDave Cobbley 38eb8dc403SDave Cobbley def __init__(self, d): 39eb8dc403SDave Cobbley super(BeagleBoneTarget, self).__init__(d) 40eb8dc403SDave Cobbley 41eb8dc403SDave Cobbley self.image_fstype = self.get_image_fstype(d) 42eb8dc403SDave Cobbley self.deploy_cmds = [ 43eb8dc403SDave Cobbley 'mkdir -p /mnt/testrootfs', 44eb8dc403SDave Cobbley 'mount -L testrootfs /mnt/testrootfs', 45eb8dc403SDave Cobbley 'rm -rf /mnt/testrootfs/*', 46eb8dc403SDave Cobbley 'tar xvf ~/test-rootfs.%s -C /mnt/testrootfs' % self.image_fstype, 47eb8dc403SDave Cobbley '[ -e /mnt/testrootfs/boot/uImage ] || [ -L /mnt/testrootfs/boot/uImage ] || cp ~/test-kernel /mnt/testrootfs/boot/uImage', 48eb8dc403SDave Cobbley ] 49eb8dc403SDave Cobbley 50eb8dc403SDave Cobbley for _, dtbfn in self.dtbs.iteritems(): 51eb8dc403SDave Cobbley # Kernel and dtb files may not be in the image, so copy them if not 52eb8dc403SDave Cobbley self.deploy_cmds.append('[ -e /mnt/testrootfs/boot/{0} ] || cp ~/{0} /mnt/testrootfs/boot/'.format(dtbfn)) 53eb8dc403SDave Cobbley 54eb8dc403SDave Cobbley if not self.serialcontrol_cmd: 55eb8dc403SDave Cobbley bb.fatal("This TEST_TARGET needs a TEST_SERIALCONTROL_CMD defined in local.conf.") 56eb8dc403SDave Cobbley 57eb8dc403SDave Cobbley 58eb8dc403SDave Cobbley def _deploy(self): 59*7e0e3c0cSAndrew Geissler self.controller.run("umount /boot; umount /mnt/testrootfs;") 60*7e0e3c0cSAndrew Geissler self.controller.ignore_status = False 61eb8dc403SDave Cobbley # Kernel and dtb files may not be in the image, so copy them just in case 62*7e0e3c0cSAndrew Geissler self.controller.copy_to(self.kernel, "~/test-kernel") 63eb8dc403SDave Cobbley kernelpath = os.path.dirname(self.kernel) 64eb8dc403SDave Cobbley for dtborig, dtbfn in self.dtbs.iteritems(): 65eb8dc403SDave Cobbley dtbfile = os.path.join(kernelpath, dtborig) 66eb8dc403SDave Cobbley if os.path.exists(dtbfile): 67*7e0e3c0cSAndrew Geissler self.controller.copy_to(dtbfile, "~/%s" % dtbfn) 68*7e0e3c0cSAndrew Geissler self.controller.copy_to(self.rootfs, "~/test-rootfs.%s" % self.image_fstype) 69eb8dc403SDave Cobbley for cmd in self.deploy_cmds: 70*7e0e3c0cSAndrew Geissler self.controller.run(cmd) 71eb8dc403SDave Cobbley 72eb8dc403SDave Cobbley def _start(self, params=None): 73*7e0e3c0cSAndrew Geissler self.power_cycle(self.controller) 74eb8dc403SDave Cobbley try: 75eb8dc403SDave Cobbley serialconn = pexpect.spawn(self.serialcontrol_cmd, env=self.origenv, logfile=sys.stdout) 76eb8dc403SDave Cobbley # We'd wait for "U-Boot" here but sometimes we connect too late on BeagleBone white to see it 77eb8dc403SDave Cobbley serialconn.expect("NAND:") 78eb8dc403SDave Cobbley serialconn.expect("MMC:") 79eb8dc403SDave Cobbley serialconn.sendline("a") 80eb8dc403SDave Cobbley serialconn.expect("U-Boot#") 81eb8dc403SDave Cobbley serialconn.sendline("setenv bootpart 0:3") 82eb8dc403SDave Cobbley serialconn.expect("U-Boot#") 83eb8dc403SDave Cobbley serialconn.sendline("setenv mmcroot /dev/mmcblk0p3 ro") 84eb8dc403SDave Cobbley serialconn.expect("U-Boot#") 85eb8dc403SDave Cobbley serialconn.sendline("boot") 86eb8dc403SDave Cobbley serialconn.expect("login:", timeout=120) 87eb8dc403SDave Cobbley serialconn.close() 88eb8dc403SDave Cobbley except pexpect.ExceptionPexpect as e: 89eb8dc403SDave Cobbley bb.fatal('Serial interaction failed: %s' % str(e)) 90eb8dc403SDave Cobbley 91eb8dc403SDave Cobbley def _wait_until_booted(self): 92eb8dc403SDave Cobbley try: 93eb8dc403SDave Cobbley serialconn = pexpect.spawn(self.serialcontrol_cmd, env=self.origenv, logfile=sys.stdout) 94eb8dc403SDave Cobbley serialconn.expect("login:", timeout=120) 95eb8dc403SDave Cobbley serialconn.close() 96eb8dc403SDave Cobbley except pexpect.ExceptionPexpect as e: 97eb8dc403SDave Cobbley bb.fatal('Serial interaction failed: %s' % str(e)) 98