@@ -1515,7 +1515,7 @@
flash-stick@1 {
reg = <1>;
compatible = "sandbox,usb-flash";
- sandbox,filepath = "testflash1.bin";
+ sandbox,filepath = "flash1.img";
};
flash-stick@2 {
@@ -221,6 +221,10 @@ static int bootdev_test_order(struct unit_test_state *uts)
/* Use the environment variable to override it */
ut_assertok(env_set("boot_targets", "mmc1 mmc2 usb"));
ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow));
+
+ /* get the usb device which has a backing file (flash1.img) */
+ ut_asserteq(0, bootflow_scan_next(&iter, &bflow));
+
ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow));
ut_asserteq(5, iter.num_devs);
ut_asserteq_str("mmc1.bootdev", iter.dev_used[0]->name);
@@ -260,7 +264,11 @@ static int bootdev_test_order(struct unit_test_state *uts)
ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow));
ut_asserteq(2, iter.num_devs);
- /* Now scan past mmc1 and make sure that the 3 USB devices show up */
+ /*
+ * Now scan past mmc1 and make sure that the 3 USB devices show up. The
+ * first one has a backing file so returns success
+ */
+ ut_asserteq(0, bootflow_scan_next(&iter, &bflow));
ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow));
ut_asserteq(6, iter.num_devs);
ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name);
@@ -322,6 +330,10 @@ static int bootdev_test_prio(struct unit_test_state *uts)
/* 3 MMC and 3 USB bootdevs: MMC should come before USB */
ut_assertok(bootflow_scan_first(NULL, NULL, &iter, 0, &bflow));
+
+ /* get the usb device which has a backing file (flash1.img) */
+ ut_asserteq(0, bootflow_scan_next(&iter, &bflow));
+
ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow));
ut_asserteq(6, iter.num_devs);
ut_asserteq_str("mmc2.bootdev", iter.dev_used[0]->name);
@@ -339,6 +351,10 @@ static int bootdev_test_prio(struct unit_test_state *uts)
bootflow_iter_uninit(&iter);
ut_assertok(bootflow_scan_first(NULL, NULL, &iter, BOOTFLOWIF_HUNT,
&bflow));
+
+ /* get the usb device which has a backing file (flash1.img) */
+ ut_asserteq(0, bootflow_scan_next(&iter, &bflow));
+
ut_asserteq(-ENODEV, bootflow_scan_next(&iter, &bflow));
ut_asserteq(7, iter.num_devs);
ut_asserteq_str("usb_mass_storage.lun0.bootdev",
@@ -534,7 +534,7 @@ static int prep_mmc_bootdev(struct unit_test_state *uts, const char *mmc_dev,
order[2] = mmc_dev;
- /* Enable the mmc4 node since we need a second bootflow */
+ /* Enable the requested mmc node since we need a second bootflow */
root = oftree_root(oftree_default());
node = ofnode_find_subnode(root, mmc_dev);
ut_assert(ofnode_valid(node));
new file mode 100644
GIT binary patch
literal 4980
zcmeI0=Tj4i7R3`1KqLr)p-B}&4JFb+KqH94Kp+GJlp<0VkeU!Wgx;4TBDm5Pr7FED
zum+G$fT%1rNH5YmQu5x+`}FqBzPG!xyC2^87o53g&OP@x_f*N>%mM%aFAUe*q5%j3
z*#Q6mPG&xzN)-a1Spop=rzd*T-}PL~uF2S?6A#+6_UCgv&5T9A@HnTfgBnG<#29-G
zQ6tzw#X%K2(1UtSDtsp9_5%5!ac(BcwW3K00~9b=T*7bL&CqGC>h>p|X~|)K>Oqyf
z)h%5P@>EV`jkscdNBa6sNNkEw9L%R&;xk~xv&@anG4u<9j!i?nAJ@-!PXKu|X{>%I
zZpWZT=#_XhRjany-Yjih!mOd^fJ|n)KxKJ+=;>>I$k<PPB6f?p_#}{W{7hEb^j%Wq
zPI%}$`*xV|;a-X&g7#&_x;xQBUk5Uja<SyK4euLLr6}ip^QdJ9v{}nC{+0RM{5{%p
zN1bD@Pma-&xV|u%)%$l~WV5W3g17FoZEtA;Lids9a>LY^9L5>>7ZuAM(@XEUY|K5*
zAu`A5=kXg1qvfV_qr3a^%Rr*yh|R<2%A`u>6i4UTB(vk5YolsiJ^E$UJ}(TAq<$=W
z#=gnJSCw}>?DA&!8LqJArM;*mDQv0FK8HF83<Z6SS+02FriFO%K>^jUYxV`_L!EVr
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%fifxsp;DoP>5Od(C4
zq6x=m7aeu3GuDqlyKIYalzyMFh^iGU5J+e#DZ34s?gL%6sLB;iv3b|{kr<m^`ZQ`8
z8?--dg5=|L*)d>g9J=u-YI;wxFMxP!AsSr8K5;3(JN}%jY##0`Wmn%BsC6^9X%?8P
zd0?UFwfqbzpe#M`*^z%Ca3NP~YinhvZnjRXTC`#2I%mR`{dx<=+O?Ie^yq_m8Amw}
zL!YEBKPHmqnur`MC;En#uoLaE?tIr*=D;lD(_BIByy7T~>AvE9LlKT<Wi@-}W)gHS
zhG@)`AeDV_=6M4W3V9gn9^)FUAvn7*T#-75!3^&(ghZ2`kJ2ZiHG&7VWF{eVj9%<%
z;trtcI~uZak2~=o)~Bkb_QAJz2XUt1&%the&7(_kub)a$rN2D;U+;=Pg+`4x<9&_4
zvDEKmDZ;ty09rsZ+hijifPdFOE`^7&1Av1f1OnlF18MMfWxL}s%|Cx@0I<2mKLF3g
ByL$it
literal 0
HcmV?d00001
@@ -28,21 +28,22 @@ def mkdir_cond(dirname):
if not os.path.exists(dirname):
os.mkdir(dirname)
-def setup_image(cons, mmc_dev, part_type, second_part=False):
+def setup_image(cons, devnum, part_type, second_part=False, basename='mmc'):
"""Create a 20MB disk image with a single partition
Args:
cons (ConsoleBase): Console to use
- mmc_dev (int): MMC device number to use, e.g. 1
+ devnum (int): Device number to use, e.g. 1
part_type (int): Partition type, e.g. 0xc for FAT32
second_part (bool): True to contain a small second partition
+ basename (str): Base name to use in the filename, e.g. 'mmc'
Returns:
tuple:
str: Filename of MMC image
str: Directory name of 'mnt' directory
"""
- fname = os.path.join(cons.config.source_dir, f'mmc{mmc_dev}.img')
+ fname = os.path.join(cons.config.source_dir, f'{basename}{devnum}.img')
mnt = os.path.join(cons.config.persistent_data_dir, 'mnt')
mkdir_cond(mnt)
@@ -78,16 +79,17 @@ def mount_image(cons, fname, mnt, fstype):
u_boot_utils.run_and_log(cons, f'sudo chown {getpass.getuser()} {mnt}')
return loop
-def copy_prepared_image(cons, mmc_dev, fname):
+def copy_prepared_image(cons, devnum, fname, basename='mmc'):
"""Use a prepared image since we cannot create one
Args:
cons (ConsoleBase): Console touse
- mmc_dev (int): MMC device number
+ devnum (int): device number
fname (str): Filename of MMC image
+ basename (str): Base name to use in the filename, e.g. 'mmc'
"""
infname = os.path.join(cons.config.source_dir,
- f'test/py/tests/bootstd/mmc{mmc_dev}.img.xz')
+ f'test/py/tests/bootstd/{basename}{devnum}.img.xz')
u_boot_utils.run_and_log(cons, ['sh', '-c', f'xz -dc {infname} >{fname}'])
def setup_bootmenu_image(cons):
@@ -549,6 +551,44 @@ def test_ut_dm_init(u_boot_console):
with open(fn, 'wb') as fh:
fh.write(data)
+
+def setup_efi_image(cons):
+ """Create a 20MB disk image with an EFI app on it"""
+ devnum = 1
+ basename = 'flash'
+ fname, mnt = setup_image(cons, devnum, 0xc, second_part=True,
+ basename=basename)
+
+ loop = None
+ mounted = False
+ complete = False
+ try:
+ loop = mount_image(cons, fname, mnt, 'ext4')
+ mounted = True
+ efi_dir = os.path.join(mnt, 'EFI')
+ mkdir_cond(efi_dir)
+ bootdir = os.path.join(efi_dir, 'BOOT')
+ mkdir_cond(bootdir)
+ efi_src = os.path.join(cons.config.build_dir,
+ f'lib/efi_loader/testapp.efi')
+ efi_dst = os.path.join(bootdir, 'BOOTSBOX.EFI')
+ with open(efi_src, 'rb') as inf:
+ with open(efi_dst, 'wb') as outf:
+ outf.write(inf.read())
+ complete = True
+ except ValueError as exc:
+ print(f'Falled to create image, failing back to prepared copy: {exc}')
+
+ finally:
+ if mounted:
+ u_boot_utils.run_and_log(cons, 'sudo umount --lazy %s' % mnt)
+ if loop:
+ u_boot_utils.run_and_log(cons, 'sudo losetup -d %s' % loop)
+
+ if not complete:
+ copy_prepared_image(cons, devnum, fname, basename)
+
+
@pytest.mark.buildconfigspec('cmd_bootflow')
@pytest.mark.buildconfigspec('sandbox')
def test_ut_dm_init_bootstd(u_boot_console):
@@ -559,6 +599,7 @@ def test_ut_dm_init_bootstd(u_boot_console):
setup_cedit_file(u_boot_console)
setup_cros_image(u_boot_console)
setup_android_image(u_boot_console)
+ setup_efi_image(u_boot_console)
# Restart so that the new mmc1.img is picked up
u_boot_console.restart_uboot()
Create a new disk for use with tests, which contains the new 'testapp' EFI app specifically intended for testing the EFI loader. Attach it to the USB device, since most testing is currently done with mmc. Initially this image will be used to test the EFI bootmeth. Fix a stale comment in prep_mmc_bootdev() while we are here. For now this uses sudo and a compressed fallback file, like all the other bootstd tests. Once this series is in, the patch which moves this to use user-space tools will be cleaned up and re-submitted. Signed-off-by: Simon Glass <sjg@chromium.org> --- Here is the patch to avoid sudo and CI fallback: [1] https://patchwork.ozlabs.org/project/uboot/patch/ 20240802093322.15240-1-richard@nod.at/ Changes in v9: - Mark the image as complete after writing it arch/sandbox/dts/test.dts | 2 +- test/boot/bootdev.c | 18 +++++++++- test/boot/bootflow.c | 2 +- test/py/tests/bootstd/flash1.img.xz | Bin 0 -> 4980 bytes test/py/tests/test_ut.py | 53 ++++++++++++++++++++++++---- 5 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 test/py/tests/bootstd/flash1.img.xz