test/py/test_efi_fit: test fdt and initrd
Add tests to check initrd and dtb loading Signed-off-by: Adriano Cordova <adriano.cordova@canonical.com>
This commit is contained in:

committed by
Heinrich Schuchardt

parent
92cf91119f
commit
8fdb8740b3
@@ -66,9 +66,29 @@ ITS_DATA = '''
|
|||||||
#address-cells = <1>;
|
#address-cells = <1>;
|
||||||
|
|
||||||
images {
|
images {
|
||||||
efi {
|
helloworld {
|
||||||
description = "Test EFI";
|
description = "Test EFI";
|
||||||
data = /incbin/("%(efi-bin)s");
|
data = /incbin/("%(hello-bin)s");
|
||||||
|
type = "%(kernel-type)s";
|
||||||
|
arch = "%(sys-arch)s";
|
||||||
|
os = "efi";
|
||||||
|
compression = "%(efi-comp)s";
|
||||||
|
load = <0x0>;
|
||||||
|
entry = <0x0>;
|
||||||
|
};
|
||||||
|
dtbdump {
|
||||||
|
description = "Test EFI fdtdump";
|
||||||
|
data = /incbin/("%(dtbdump-bin)s");
|
||||||
|
type = "%(kernel-type)s";
|
||||||
|
arch = "%(sys-arch)s";
|
||||||
|
os = "efi";
|
||||||
|
compression = "%(efi-comp)s";
|
||||||
|
load = <0x0>;
|
||||||
|
entry = <0x0>;
|
||||||
|
};
|
||||||
|
initrddump {
|
||||||
|
description = "Test EFI initrddump";
|
||||||
|
data = /incbin/("%(initrddump-bin)s");
|
||||||
type = "%(kernel-type)s";
|
type = "%(kernel-type)s";
|
||||||
arch = "%(sys-arch)s";
|
arch = "%(sys-arch)s";
|
||||||
os = "efi";
|
os = "efi";
|
||||||
@@ -83,18 +103,33 @@ ITS_DATA = '''
|
|||||||
arch = "%(sys-arch)s";
|
arch = "%(sys-arch)s";
|
||||||
compression = "%(fdt-comp)s";
|
compression = "%(fdt-comp)s";
|
||||||
};
|
};
|
||||||
|
initrd {
|
||||||
|
description = "Initial RAM Disk";
|
||||||
|
data = /incbin/("%(initrd-fs)s");
|
||||||
|
type = "ramdisk";
|
||||||
|
compression = "%(initrd-comp)s";
|
||||||
|
os = "efi";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
default = "config-efi-fdt";
|
default = "config-efi-fdt";
|
||||||
|
|
||||||
|
config-efi {
|
||||||
|
description = "EFI FIT w/o FDT";
|
||||||
|
kernel = "helloworld";
|
||||||
|
};
|
||||||
|
|
||||||
config-efi-fdt {
|
config-efi-fdt {
|
||||||
description = "EFI FIT w/ FDT";
|
description = "EFI FIT w/ FDT";
|
||||||
kernel = "efi";
|
kernel = "dtbdump";
|
||||||
fdt = "fdt";
|
fdt = "fdt";
|
||||||
};
|
};
|
||||||
config-efi-nofdt {
|
|
||||||
description = "EFI FIT w/o FDT";
|
config-efi-initrd {
|
||||||
kernel = "efi";
|
description = "EFI FIT w/ initrd";
|
||||||
|
kernel = "initrddump";
|
||||||
|
ramdisk = "initrd";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -108,7 +143,7 @@ FDT_DATA = '''
|
|||||||
#address-cells = <1>;
|
#address-cells = <1>;
|
||||||
#size-cells = <1>;
|
#size-cells = <1>;
|
||||||
|
|
||||||
model = "%(sys-arch)s %(fdt_type)s EFI FIT Boot Test";
|
model = "%(sys-arch)s %(fdt_type)s EFI FIT FDT Boot Test";
|
||||||
compatible = "%(sys-arch)s";
|
compatible = "%(sys-arch)s";
|
||||||
|
|
||||||
reset@0 {
|
reset@0 {
|
||||||
@@ -120,6 +155,7 @@ FDT_DATA = '''
|
|||||||
|
|
||||||
@pytest.mark.buildconfigspec('bootm_efi')
|
@pytest.mark.buildconfigspec('bootm_efi')
|
||||||
@pytest.mark.buildconfigspec('BOOTEFI_HELLO_COMPILE')
|
@pytest.mark.buildconfigspec('BOOTEFI_HELLO_COMPILE')
|
||||||
|
@pytest.mark.buildconfigspec('EFI_LOAD_FILE2_INITRD')
|
||||||
@pytest.mark.buildconfigspec('fit')
|
@pytest.mark.buildconfigspec('fit')
|
||||||
@pytest.mark.notbuildconfigspec('generate_acpi_table')
|
@pytest.mark.notbuildconfigspec('generate_acpi_table')
|
||||||
@pytest.mark.requiredtool('dtc')
|
@pytest.mark.requiredtool('dtc')
|
||||||
@@ -137,8 +173,10 @@ def test_efi_fit_launch(ubman):
|
|||||||
The following test cases are currently defined and enabled:
|
The following test cases are currently defined and enabled:
|
||||||
- Launch uncompressed FIT EFI & internal FDT
|
- Launch uncompressed FIT EFI & internal FDT
|
||||||
- Launch uncompressed FIT EFI & FIT FDT
|
- Launch uncompressed FIT EFI & FIT FDT
|
||||||
|
- Launch uncompressed FIT EFI & internal FDT & FIT initrd
|
||||||
- Launch compressed FIT EFI & internal FDT
|
- Launch compressed FIT EFI & internal FDT
|
||||||
- Launch compressed FIT EFI & FIT FDT
|
- Launch compressed FIT EFI & FIT FDT
|
||||||
|
- Launch compressed FIT EFI & internal FDT & FIT initrd
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def net_pre_commands():
|
def net_pre_commands():
|
||||||
@@ -210,7 +248,7 @@ def test_efi_fit_launch(ubman):
|
|||||||
|
|
||||||
return os.path.join(ubman.config.build_dir, file_name)
|
return os.path.join(ubman.config.build_dir, file_name)
|
||||||
|
|
||||||
def make_efi(fname, comp):
|
def make_efi(fname, efi_file, comp):
|
||||||
"""Create an UEFI binary.
|
"""Create an UEFI binary.
|
||||||
|
|
||||||
This simply copies lib/efi_loader/helloworld.efi into U-Boot
|
This simply copies lib/efi_loader/helloworld.efi into U-Boot
|
||||||
@@ -218,6 +256,7 @@ def test_efi_fit_launch(ubman):
|
|||||||
|
|
||||||
Args:
|
Args:
|
||||||
fname -- The target file name within U-Boot build dir.
|
fname -- The target file name within U-Boot build dir.
|
||||||
|
efi_file -- The source .efi application
|
||||||
comp -- Flag to enable gzip compression.
|
comp -- Flag to enable gzip compression.
|
||||||
Return:
|
Return:
|
||||||
The path of the created file.
|
The path of the created file.
|
||||||
@@ -225,7 +264,7 @@ def test_efi_fit_launch(ubman):
|
|||||||
|
|
||||||
bin_path = make_fpath(fname)
|
bin_path = make_fpath(fname)
|
||||||
utils.run_and_log(ubman,
|
utils.run_and_log(ubman,
|
||||||
['cp', make_fpath('lib/efi_loader/helloworld.efi'),
|
['cp', make_fpath(f'lib/efi_loader/{efi_file}'),
|
||||||
bin_path])
|
bin_path])
|
||||||
if comp:
|
if comp:
|
||||||
utils.run_and_log(ubman, ['gzip', '-f', bin_path])
|
utils.run_and_log(ubman, ['gzip', '-f', bin_path])
|
||||||
@@ -264,6 +303,27 @@ def test_efi_fit_launch(ubman):
|
|||||||
dtb += '.gz'
|
dtb += '.gz'
|
||||||
return dtb
|
return dtb
|
||||||
|
|
||||||
|
def make_initrd(comp):
|
||||||
|
"""Create a sample initrd.
|
||||||
|
|
||||||
|
Creates an initrd.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
comp -- Flag to enable gzip compression.
|
||||||
|
Return:
|
||||||
|
The path of the created file.
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Generate a test initrd file.
|
||||||
|
initrd = make_fpath('test-efi-initrd')
|
||||||
|
with open(initrd, 'w', encoding='ascii') as file:
|
||||||
|
file.write('test-efi-initrd')
|
||||||
|
|
||||||
|
if comp:
|
||||||
|
utils.run_and_log(ubman, ['gzip', '-f', initrd])
|
||||||
|
initrd += '.gz'
|
||||||
|
return initrd
|
||||||
|
|
||||||
def make_fit(comp):
|
def make_fit(comp):
|
||||||
"""Create a sample FIT image.
|
"""Create a sample FIT image.
|
||||||
|
|
||||||
@@ -275,22 +335,35 @@ def test_efi_fit_launch(ubman):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Generate resources referenced by ITS.
|
# Generate resources referenced by ITS.
|
||||||
|
hello_bin = os.path.basename(make_efi('test-efi-helloworld.efi', 'helloworld.efi', comp))
|
||||||
|
dtbdump_bin = os.path.basename(make_efi('test-efi-dtbdump.efi', 'dtbdump.efi', comp))
|
||||||
|
initrddump_bin = os.path.basename(make_efi('test-efi-initrddump.efi', 'initrddump.efi', comp))
|
||||||
|
fdt_bin = os.path.basename(make_dtb('user', comp))
|
||||||
|
initrd_fs = make_initrd(comp)
|
||||||
|
initrd_fs = os.path.basename(initrd_fs)
|
||||||
|
compression = 'gzip' if comp else 'none'
|
||||||
|
kernel_type = 'kernel' if comp else 'kernel_noload'
|
||||||
|
|
||||||
its_params = {
|
its_params = {
|
||||||
'sys-arch': sys_arch,
|
'sys-arch': sys_arch,
|
||||||
'efi-bin': os.path.basename(make_efi('test-efi-fit-helloworld.efi', comp)),
|
'hello-bin': hello_bin,
|
||||||
'kernel-type': 'kernel' if comp else 'kernel_noload',
|
'dtbdump-bin': dtbdump_bin,
|
||||||
'efi-comp': 'gzip' if comp else 'none',
|
'initrddump-bin': initrddump_bin,
|
||||||
'fdt-bin': os.path.basename(make_dtb('user', comp)),
|
'kernel-type': kernel_type,
|
||||||
'fdt-comp': 'gzip' if comp else 'none',
|
'efi-comp': compression,
|
||||||
|
'fdt-bin': fdt_bin,
|
||||||
|
'fdt-comp': compression,
|
||||||
|
'initrd-fs': initrd_fs,
|
||||||
|
'initrd-comp': compression,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generate a test ITS file.
|
# Generate a test ITS file.
|
||||||
its_path = make_fpath('test-efi-fit-helloworld.its')
|
its_path = make_fpath('test-efi-fit.its')
|
||||||
with open(its_path, 'w', encoding='ascii') as file:
|
with open(its_path, 'w', encoding='ascii') as file:
|
||||||
file.write(ITS_DATA % its_params)
|
file.write(ITS_DATA % its_params)
|
||||||
|
|
||||||
# Build the test ITS.
|
# Build the test ITS.
|
||||||
fit_path = make_fpath('test-efi-fit-helloworld.fit')
|
fit_path = make_fpath('test-efi-fit.fit')
|
||||||
utils.run_and_log(
|
utils.run_and_log(
|
||||||
ubman, [make_fpath('tools/mkimage'), '-f', its_path, fit_path])
|
ubman, [make_fpath('tools/mkimage'), '-f', its_path, fit_path])
|
||||||
return fit_path
|
return fit_path
|
||||||
@@ -357,7 +430,7 @@ def test_efi_fit_launch(ubman):
|
|||||||
|
|
||||||
return addr
|
return addr
|
||||||
|
|
||||||
def launch_efi(enable_fdt, enable_comp):
|
def launch_efi(enable_fdt, enable_initrd, enable_comp):
|
||||||
"""Launch U-Boot's helloworld.efi binary from a FIT image.
|
"""Launch U-Boot's helloworld.efi binary from a FIT image.
|
||||||
|
|
||||||
An external image file can be downloaded from TFTP, when related
|
An external image file can be downloaded from TFTP, when related
|
||||||
@@ -372,19 +445,20 @@ def test_efi_fit_launch(ubman):
|
|||||||
from the host filesystem.
|
from the host filesystem.
|
||||||
|
|
||||||
Once the load address is available on U-Boot console, the 'bootm'
|
Once the load address is available on U-Boot console, the 'bootm'
|
||||||
command is executed for either 'config-efi-fdt' or 'config-efi-nofdt'
|
command is executed for either 'config-efi', 'config-efi-fdt' or
|
||||||
FIT configuration, depending on the value of the 'enable_fdt' function
|
'config-efi-initrd' FIT configuration, depending on the value of the
|
||||||
argument.
|
'enable_fdt' and 'enable_initrd' function arguments.
|
||||||
|
|
||||||
Eventually the 'Hello, world' message is expected in the U-Boot console.
|
Eventually the 'Hello, world' message is expected in the U-Boot console.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
enable_fdt -- Flag to enable using the FDT blob inside FIT image.
|
enable_fdt -- Flag to enable using the FDT blob inside FIT image.
|
||||||
|
enable_initrd -- Flag to enable using an initrd inside FIT image.
|
||||||
enable_comp -- Flag to enable GZIP compression on EFI and FDT
|
enable_comp -- Flag to enable GZIP compression on EFI and FDT
|
||||||
generated content.
|
generated content.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
with ubman.log.section('FDT=%s;COMP=%s' % (enable_fdt, enable_comp)):
|
with ubman.log.section('FDT=%s;INITRD=%s;COMP=%s' % (enable_fdt, enable_initrd, enable_comp)):
|
||||||
if is_sandbox:
|
if is_sandbox:
|
||||||
fit = {
|
fit = {
|
||||||
'dn': ubman.config.build_dir,
|
'dn': ubman.config.build_dir,
|
||||||
@@ -420,14 +494,28 @@ def test_efi_fit_launch(ubman):
|
|||||||
addr = load_fit_from_host(fit) if is_sandbox else load_fit_from_tftp(fit)
|
addr = load_fit_from_host(fit) if is_sandbox else load_fit_from_tftp(fit)
|
||||||
|
|
||||||
# Select boot configuration.
|
# Select boot configuration.
|
||||||
fit_config = 'config-efi-fdt' if enable_fdt else 'config-efi-nofdt'
|
fit_config = 'config-efi'
|
||||||
|
fit_config = fit_config + '-fdt' if enable_fdt else fit_config
|
||||||
|
fit_config = fit_config + '-initrd' if enable_initrd else fit_config
|
||||||
|
|
||||||
# Try booting.
|
# Try booting.
|
||||||
|
ubman.run_command('setenv bootargs nocolor')
|
||||||
output = ubman.run_command('bootm %x#%s' % (addr, fit_config))
|
output = ubman.run_command('bootm %x#%s' % (addr, fit_config))
|
||||||
|
assert '## Application failed' not in output
|
||||||
if enable_fdt:
|
if enable_fdt:
|
||||||
assert 'Booting using the fdt blob' in output
|
assert 'Booting using the fdt blob' in output
|
||||||
assert 'Hello, world' in output
|
assert 'DTB Dump' in output
|
||||||
assert '## Application failed' not in output
|
if enable_initrd:
|
||||||
|
assert 'Loading ramdisk' in output
|
||||||
|
assert 'INITRD Dump' in output
|
||||||
|
if enable_fdt:
|
||||||
|
response = ubman.run_command(cmd = 'dump', wait_for_echo=False)
|
||||||
|
assert 'EFI FIT FDT Boot Test' in response
|
||||||
|
if enable_initrd:
|
||||||
|
response = ubman.run_command('load', wait_for_echo=False)
|
||||||
|
assert f"crc32: 0x0c77b025" in response
|
||||||
|
if not enable_fdt and not enable_initrd:
|
||||||
|
assert 'Hello, world' in output
|
||||||
ubman.restart_uboot()
|
ubman.restart_uboot()
|
||||||
|
|
||||||
# Array slice removes leading/trailing quotes.
|
# Array slice removes leading/trailing quotes.
|
||||||
@@ -449,16 +537,20 @@ def test_efi_fit_launch(ubman):
|
|||||||
ubman.config.dtb = control_dtb
|
ubman.config.dtb = control_dtb
|
||||||
|
|
||||||
# Run tests
|
# Run tests
|
||||||
# - fdt OFF, gzip OFF
|
# - fdt OFF, initrd OFF, gzip OFF
|
||||||
launch_efi(False, False)
|
launch_efi(False, False, False)
|
||||||
# - fdt ON, gzip OFF
|
# - fdt ON, initrd OFF, gzip OFF
|
||||||
launch_efi(True, False)
|
launch_efi(True, False, False)
|
||||||
|
# - fdt OFF, initrd ON, gzip OFF
|
||||||
|
launch_efi(False, True, False)
|
||||||
|
|
||||||
if is_sandbox:
|
if is_sandbox:
|
||||||
# - fdt OFF, gzip ON
|
# - fdt OFF, initrd OFF, gzip ON
|
||||||
launch_efi(False, True)
|
launch_efi(False, False, True)
|
||||||
# - fdt ON, gzip ON
|
# - fdt ON, initrd OFF, gzip ON
|
||||||
launch_efi(True, True)
|
launch_efi(True, False, True)
|
||||||
|
# - fdt OFF, initrd ON, gzip ON
|
||||||
|
launch_efi(False, True, True)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
if is_sandbox:
|
if is_sandbox:
|
||||||
|
Reference in New Issue
Block a user