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