mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-17 18:34:42 +00:00
test_ut: Drop exeception handling
We don't need the fallback anymore. As a first step to removing it, drop the try...except clauses and unindent the code. This produces a large diff but there are no other code changes. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
d83143eb55
commit
ac1c547092
1 changed files with 78 additions and 91 deletions
|
@ -79,8 +79,7 @@ def setup_bootmenu_image(cons):
|
|||
fname, mnt = setup_image(cons, mmc_dev, 0x83)
|
||||
|
||||
complete = False
|
||||
try:
|
||||
script = '''# DO NOT EDIT THIS FILE
|
||||
script = '''# DO NOT EDIT THIS FILE
|
||||
#
|
||||
# Please edit /boot/armbianEnv.txt to set supported parameters
|
||||
#
|
||||
|
@ -154,45 +153,42 @@ booti ${kernel_addr_r} ${ramdisk_addr_r} ${fdt_addr_r}
|
|||
# Recompile with:
|
||||
# mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
|
||||
'''
|
||||
bootdir = os.path.join(mnt, 'boot')
|
||||
mkdir_cond(bootdir)
|
||||
cmd_fname = os.path.join(bootdir, 'boot.cmd')
|
||||
scr_fname = os.path.join(bootdir, 'boot.scr')
|
||||
with open(cmd_fname, 'w', encoding='ascii') as outf:
|
||||
print(script, file=outf)
|
||||
bootdir = os.path.join(mnt, 'boot')
|
||||
mkdir_cond(bootdir)
|
||||
cmd_fname = os.path.join(bootdir, 'boot.cmd')
|
||||
scr_fname = os.path.join(bootdir, 'boot.scr')
|
||||
with open(cmd_fname, 'w', encoding='ascii') as outf:
|
||||
print(script, file=outf)
|
||||
|
||||
infname = os.path.join(cons.config.source_dir,
|
||||
'test/py/tests/bootstd/armbian.bmp.xz')
|
||||
bmp_file = os.path.join(bootdir, 'boot.bmp')
|
||||
u_boot_utils.run_and_log(
|
||||
cons,
|
||||
['sh', '-c', f'xz -dc {infname} >{bmp_file}'])
|
||||
infname = os.path.join(cons.config.source_dir,
|
||||
'test/py/tests/bootstd/armbian.bmp.xz')
|
||||
bmp_file = os.path.join(bootdir, 'boot.bmp')
|
||||
u_boot_utils.run_and_log(
|
||||
cons,
|
||||
['sh', '-c', f'xz -dc {infname} >{bmp_file}'])
|
||||
|
||||
u_boot_utils.run_and_log(
|
||||
cons, f'mkimage -C none -A arm -T script -d {cmd_fname} {scr_fname}')
|
||||
u_boot_utils.run_and_log(
|
||||
cons, f'mkimage -C none -A arm -T script -d {cmd_fname} {scr_fname}')
|
||||
|
||||
kernel = 'vmlinuz-5.15.63-rockchip64'
|
||||
target = os.path.join(bootdir, kernel)
|
||||
with open(target, 'wb') as outf:
|
||||
print('kernel', outf)
|
||||
kernel = 'vmlinuz-5.15.63-rockchip64'
|
||||
target = os.path.join(bootdir, kernel)
|
||||
with open(target, 'wb') as outf:
|
||||
print('kernel', outf)
|
||||
|
||||
symlink = os.path.join(bootdir, 'Image')
|
||||
if os.path.exists(symlink):
|
||||
os.remove(symlink)
|
||||
u_boot_utils.run_and_log(
|
||||
cons, f'echo here {kernel} {symlink}')
|
||||
os.symlink(kernel, symlink)
|
||||
symlink = os.path.join(bootdir, 'Image')
|
||||
if os.path.exists(symlink):
|
||||
os.remove(symlink)
|
||||
u_boot_utils.run_and_log(
|
||||
cons, f'echo here {kernel} {symlink}')
|
||||
os.symlink(kernel, symlink)
|
||||
|
||||
fsfile = 'ext18M.img'
|
||||
u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}')
|
||||
u_boot_utils.run_and_log(cons, f'mkfs.ext4 {fsfile} -d {mnt}')
|
||||
u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1')
|
||||
complete = True
|
||||
except ValueError as exc:
|
||||
print(f'Falled to create image, failing back to prepared copy: {exc}')
|
||||
finally:
|
||||
u_boot_utils.run_and_log(cons, f'rm -rf {mnt}')
|
||||
u_boot_utils.run_and_log(cons, f'rm -f {fsfile}')
|
||||
fsfile = 'ext18M.img'
|
||||
u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}')
|
||||
u_boot_utils.run_and_log(cons, f'mkfs.ext4 {fsfile} -d {mnt}')
|
||||
u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1')
|
||||
complete = True
|
||||
u_boot_utils.run_and_log(cons, f'rm -rf {mnt}')
|
||||
u_boot_utils.run_and_log(cons, f'rm -f {fsfile}')
|
||||
|
||||
if not complete:
|
||||
copy_prepared_image(cons, mmc_dev, fname)
|
||||
|
@ -203,11 +199,10 @@ def setup_bootflow_image(cons):
|
|||
fname, mnt = setup_image(cons, mmc_dev, 0xc, second_part=True)
|
||||
|
||||
complete = False
|
||||
try:
|
||||
vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl'
|
||||
initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img'
|
||||
dtbdir = 'dtb-5.3.7-301.fc31.armv7hl'
|
||||
script = '''# extlinux.conf generated by appliance-creator
|
||||
vmlinux = 'vmlinuz-5.3.7-301.fc31.armv7hl'
|
||||
initrd = 'initramfs-5.3.7-301.fc31.armv7hl.img'
|
||||
dtbdir = 'dtb-5.3.7-301.fc31.armv7hl'
|
||||
script = '''# extlinux.conf generated by appliance-creator
|
||||
ui menu.c32
|
||||
menu autoboot Welcome to Fedora-Workstation-armhfp-31-1.9. Automatic boot in # second{,s}. Press a key for options.
|
||||
menu title Fedora-Workstation-armhfp-31-1.9 Boot Options.
|
||||
|
@ -220,39 +215,36 @@ label Fedora-Workstation-armhfp-31-1.9 (5.3.7-301.fc31.armv7hl)
|
|||
append ro root=UUID=9732b35b-4cd5-458b-9b91-80f7047e0b8a rhgb quiet LANG=en_US.UTF-8 cma=192MB cma=256MB
|
||||
fdtdir /%s/
|
||||
initrd /%s''' % (vmlinux, dtbdir, initrd)
|
||||
ext = os.path.join(mnt, 'extlinux')
|
||||
mkdir_cond(ext)
|
||||
ext = os.path.join(mnt, 'extlinux')
|
||||
mkdir_cond(ext)
|
||||
|
||||
conf = os.path.join(ext, 'extlinux.conf')
|
||||
with open(conf, 'w', encoding='ascii') as fd:
|
||||
print(script, file=fd)
|
||||
conf = os.path.join(ext, 'extlinux.conf')
|
||||
with open(conf, 'w', encoding='ascii') as fd:
|
||||
print(script, file=fd)
|
||||
|
||||
inf = os.path.join(cons.config.persistent_data_dir, 'inf')
|
||||
with open(inf, 'wb') as fd:
|
||||
fd.write(gzip.compress(b'vmlinux'))
|
||||
u_boot_utils.run_and_log(
|
||||
cons, f'mkimage -f auto -d {inf} {os.path.join(mnt, vmlinux)}')
|
||||
inf = os.path.join(cons.config.persistent_data_dir, 'inf')
|
||||
with open(inf, 'wb') as fd:
|
||||
fd.write(gzip.compress(b'vmlinux'))
|
||||
u_boot_utils.run_and_log(
|
||||
cons, f'mkimage -f auto -d {inf} {os.path.join(mnt, vmlinux)}')
|
||||
|
||||
with open(os.path.join(mnt, initrd), 'w', encoding='ascii') as fd:
|
||||
print('initrd', file=fd)
|
||||
with open(os.path.join(mnt, initrd), 'w', encoding='ascii') as fd:
|
||||
print('initrd', file=fd)
|
||||
|
||||
mkdir_cond(os.path.join(mnt, dtbdir))
|
||||
mkdir_cond(os.path.join(mnt, dtbdir))
|
||||
|
||||
dtb_file = os.path.join(mnt, f'{dtbdir}/sandbox.dtb')
|
||||
u_boot_utils.run_and_log(
|
||||
cons, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};')
|
||||
dtb_file = os.path.join(mnt, f'{dtbdir}/sandbox.dtb')
|
||||
u_boot_utils.run_and_log(
|
||||
cons, f'dtc -o {dtb_file}', stdin=b'/dts-v1/; / {};')
|
||||
|
||||
fsfile = 'vfat18M.img'
|
||||
u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}')
|
||||
u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}')
|
||||
u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/'])
|
||||
u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1')
|
||||
complete = True
|
||||
except ValueError as exc:
|
||||
print(f'Falled to create image, failing back to prepared copy: {exc}')
|
||||
finally:
|
||||
u_boot_utils.run_and_log(cons, f'rm -rf {mnt}')
|
||||
u_boot_utils.run_and_log(cons, f'rm -f {fsfile}')
|
||||
fsfile = 'vfat18M.img'
|
||||
u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}')
|
||||
u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}')
|
||||
u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -i {fsfile} {mnt}/* ::/'])
|
||||
u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1')
|
||||
complete = True
|
||||
u_boot_utils.run_and_log(cons, f'rm -rf {mnt}')
|
||||
u_boot_utils.run_and_log(cons, f'rm -f {fsfile}')
|
||||
if not complete:
|
||||
copy_prepared_image(cons, mmc_dev, fname)
|
||||
|
||||
|
@ -527,29 +519,24 @@ def setup_efi_image(cons):
|
|||
basename=basename)
|
||||
|
||||
complete = False
|
||||
try:
|
||||
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,
|
||||
'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())
|
||||
fsfile = 'vfat18M.img'
|
||||
u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}')
|
||||
u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}')
|
||||
u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -vs -i {fsfile} {mnt}/* ::/'])
|
||||
u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1')
|
||||
complete = True
|
||||
except ValueError as exc:
|
||||
print(f'Falled to create image, failing back to prepared copy: {exc}')
|
||||
|
||||
finally:
|
||||
u_boot_utils.run_and_log(cons, f'rm -rf {mnt}')
|
||||
u_boot_utils.run_and_log(cons, f'rm -f {fsfile}')
|
||||
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,
|
||||
'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())
|
||||
fsfile = 'vfat18M.img'
|
||||
u_boot_utils.run_and_log(cons, f'fallocate -l 18M {fsfile}')
|
||||
u_boot_utils.run_and_log(cons, f'mkfs.vfat {fsfile}')
|
||||
u_boot_utils.run_and_log(cons, ['sh', '-c', f'mcopy -vs -i {fsfile} {mnt}/* ::/'])
|
||||
u_boot_utils.run_and_log(cons, f'dd if={fsfile} of={fname} bs=1M seek=1')
|
||||
complete = True
|
||||
u_boot_utils.run_and_log(cons, f'rm -rf {mnt}')
|
||||
u_boot_utils.run_and_log(cons, f'rm -f {fsfile}')
|
||||
|
||||
if not complete:
|
||||
copy_prepared_image(cons, devnum, fname, basename)
|
||||
|
|
Loading…
Add table
Reference in a new issue