aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/dm/Makefile1
-rw-r--r--test/dm/blkmap.c201
-rw-r--r--test/py/requirements.txt8
-rw-r--r--test/py/tests/test_android/test_abootimg.py136
4 files changed, 329 insertions, 17 deletions
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 7a79b6e1a2..e15bdbf04b 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -29,6 +29,7 @@ obj-$(CONFIG_ADC) += adc.o
obj-$(CONFIG_SOUND) += audio.o
obj-$(CONFIG_AXI) += axi.o
obj-$(CONFIG_BLK) += blk.o
+obj-$(CONFIG_BLKMAP) += blkmap.o
obj-$(CONFIG_BUTTON) += button.o
obj-$(CONFIG_DM_BOOTCOUNT) += bootcount.o
obj-$(CONFIG_DM_REBOOT_MODE) += reboot-mode.o
diff --git a/test/dm/blkmap.c b/test/dm/blkmap.c
new file mode 100644
index 0000000000..7a163d6eae
--- /dev/null
+++ b/test/dm/blkmap.c
@@ -0,0 +1,201 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2023 Addiva Elektronik
+ * Author: Tobias Waldekranz <tobias@waldekranz.com>
+ */
+
+#include <common.h>
+#include <blk.h>
+#include <blkmap.h>
+#include <dm.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+#define BLKSZ 0x200
+
+struct mapping {
+ int src;
+ int cnt;
+ int dst;
+};
+
+const struct mapping unordered_mapping[] = {
+ { 0, 1, 3 },
+ { 1, 3, 0 },
+ { 4, 2, 6 },
+ { 6, 2, 4 },
+
+ { 0, 0, 0 }
+};
+
+const struct mapping identity_mapping[] = {
+ { 0, 8, 0 },
+
+ { 0, 0, 0 }
+};
+
+static char identity[8 * BLKSZ];
+static char unordered[8 * BLKSZ];
+static char buffer[8 * BLKSZ];
+
+static void mkblob(void *base, const struct mapping *m)
+{
+ int nr;
+
+ for (; m->cnt; m++) {
+ for (nr = 0; nr < m->cnt; nr++) {
+ memset(base + (m->dst + nr) * BLKSZ,
+ m->src + nr, BLKSZ);
+ }
+ }
+}
+
+static int dm_test_blkmap_read(struct unit_test_state *uts)
+{
+ struct udevice *dev, *blk;
+ const struct mapping *m;
+
+ ut_assertok(blkmap_create("rdtest", &dev));
+ ut_assertok(blk_get_from_parent(dev, &blk));
+
+ /* Generate an ordered and an unordered pattern in memory */
+ mkblob(unordered, unordered_mapping);
+ mkblob(identity, identity_mapping);
+
+ /* Create a blkmap that cancels out the disorder */
+ for (m = unordered_mapping; m->cnt; m++) {
+ ut_assertok(blkmap_map_mem(dev, m->src, m->cnt,
+ unordered + m->dst * BLKSZ));
+ }
+
+ /* Read out the data via the blkmap device to another area,
+ * and verify that it matches the ordered pattern.
+ */
+ ut_asserteq(8, blk_read(blk, 0, 8, buffer));
+ ut_assertok(memcmp(buffer, identity, sizeof(buffer)));
+
+ ut_assertok(blkmap_destroy(dev));
+ return 0;
+}
+DM_TEST(dm_test_blkmap_read, 0);
+
+static int dm_test_blkmap_write(struct unit_test_state *uts)
+{
+ struct udevice *dev, *blk;
+ const struct mapping *m;
+
+ ut_assertok(blkmap_create("wrtest", &dev));
+ ut_assertok(blk_get_from_parent(dev, &blk));
+
+ /* Generate an ordered and an unordered pattern in memory */
+ mkblob(unordered, unordered_mapping);
+ mkblob(identity, identity_mapping);
+
+ /* Create a blkmap that mimics the disorder */
+ for (m = unordered_mapping; m->cnt; m++) {
+ ut_assertok(blkmap_map_mem(dev, m->src, m->cnt,
+ buffer + m->dst * BLKSZ));
+ }
+
+ /* Write the ordered data via the blkmap device to another
+ * area, and verify that the result matches the unordered
+ * pattern.
+ */
+ ut_asserteq(8, blk_write(blk, 0, 8, identity));
+ ut_assertok(memcmp(buffer, unordered, sizeof(buffer)));
+
+ ut_assertok(blkmap_destroy(dev));
+ return 0;
+}
+DM_TEST(dm_test_blkmap_write, 0);
+
+static int dm_test_blkmap_slicing(struct unit_test_state *uts)
+{
+ struct udevice *dev;
+
+ ut_assertok(blkmap_create("slicetest", &dev));
+
+ ut_assertok(blkmap_map_mem(dev, 8, 8, NULL));
+
+ /* Can't overlap on the low end */
+ ut_asserteq(-EBUSY, blkmap_map_mem(dev, 4, 5, NULL));
+ /* Can't be inside */
+ ut_asserteq(-EBUSY, blkmap_map_mem(dev, 10, 2, NULL));
+ /* Can't overlap on the high end */
+ ut_asserteq(-EBUSY, blkmap_map_mem(dev, 15, 4, NULL));
+
+ /* But we should be able to add slices right before and
+ * after
+ */
+ ut_assertok(blkmap_map_mem(dev, 4, 4, NULL));
+ ut_assertok(blkmap_map_mem(dev, 16, 4, NULL));
+
+ ut_assertok(blkmap_destroy(dev));
+ return 0;
+}
+DM_TEST(dm_test_blkmap_slicing, 0);
+
+static int dm_test_blkmap_creation(struct unit_test_state *uts)
+{
+ struct udevice *first, *second;
+
+ ut_assertok(blkmap_create("first", &first));
+
+ /* Can't have two "first"s */
+ ut_asserteq(-EBUSY, blkmap_create("first", &second));
+
+ /* But "second" should be fine */
+ ut_assertok(blkmap_create("second", &second));
+
+ /* Once "first" is destroyed, we should be able to create it
+ * again
+ */
+ ut_assertok(blkmap_destroy(first));
+ ut_assertok(blkmap_create("first", &first));
+
+ ut_assertok(blkmap_destroy(first));
+ ut_assertok(blkmap_destroy(second));
+ return 0;
+}
+DM_TEST(dm_test_blkmap_creation, 0);
+
+static int dm_test_cmd_blkmap(struct unit_test_state *uts)
+{
+ ulong loadaddr = env_get_hex("loadaddr", 0);
+ struct udevice *dev;
+
+ console_record_reset();
+
+ ut_assertok(run_command("blkmap info", 0));
+ ut_assert_console_end();
+
+ ut_assertok(run_command("blkmap create ramdisk", 0));
+ ut_assert_nextline("Created \"ramdisk\"");
+ ut_assert_console_end();
+
+ ut_assertnonnull((dev = blkmap_from_label("ramdisk")));
+
+ ut_assertok(run_commandf("blkmap map ramdisk 0 800 mem 0x%lx", loadaddr));
+ ut_assert_nextline("Block 0x0+0x800 mapped to 0x%lx", loadaddr);
+ ut_assert_console_end();
+
+ ut_assertok(run_command("blkmap info", 0));
+ ut_assert_nextline("Device 0: Vendor: U-Boot Rev: 1.0 Prod: blkmap");
+ ut_assert_nextline(" Type: Hard Disk");
+ ut_assert_nextline(" Capacity: 1.0 MB = 0.0 GB (2048 x 512)");
+ ut_assert_console_end();
+
+ ut_assertok(run_command("blkmap get ramdisk dev devnum", 0));
+ ut_asserteq(dev_seq(dev), env_get_hex("devnum", 0xdeadbeef));
+
+ ut_assertok(run_command("blkmap destroy ramdisk", 0));
+ ut_assert_nextline("Destroyed \"ramdisk\"");
+ ut_assert_console_end();
+
+ ut_assertok(run_command("blkmap info", 0));
+ ut_assert_console_end();
+ return 0;
+}
+DM_TEST(dm_test_cmd_blkmap, 0);
diff --git a/test/py/requirements.txt b/test/py/requirements.txt
index e241780f92..86d6266053 100644
--- a/test/py/requirements.txt
+++ b/test/py/requirements.txt
@@ -8,21 +8,21 @@ fixtures==3.0.0
importlib-metadata==0.23
linecache2==1.0.0
more-itertools==7.2.0
-packaging==19.2
+packaging==21.3
pbr==5.4.3
pluggy==0.13.0
py==1.10.0
pycryptodomex==3.9.8
pyelftools==0.27
pygit2==1.9.2
-pyparsing==2.4.2
+pyparsing==3.0.7
pytest==6.2.5
pytest-xdist==2.5.0
python-mimeparse==1.6.0
python-subunit==1.3.0
-requests==2.25.1
+requests==2.27.1
setuptools==58.3.0
-six==1.12.0
+six==1.16.0
testtools==2.3.0
traceback2==1.4.0
unittest2==1.1.0
diff --git a/test/py/tests/test_android/test_abootimg.py b/test/py/tests/test_android/test_abootimg.py
index 43a7099c46..6a8ff34538 100644
--- a/test/py/tests/test_android/test_abootimg.py
+++ b/test/py/tests/test_android/test_abootimg.py
@@ -32,6 +32,23 @@ Now one can obtain original boot.img from this hex dump like this:
$ xxd -r -p boot.img.gz.hex boot.img.gz
$ gunzip -9 boot.img.gz
+
+For boot image header version 4, these tests rely on two images that are generated
+using the same steps above :
+
+1- boot.img :
+ $ mkbootimg --kernel ./kernel --ramdisk ./ramdisk.img \
+ --cmdline "cmdline test" --dtb ./dtb.img \
+ --os_version R --os_patch_level 2019-06-05 \
+ --header_version 4 --output ./boot.img
+
+2- vendor_boot.img
+ $ mkbootimg --kernel ./kernel --ramdisk ./ramdisk.img \
+ --cmdline "cmdline test" --dtb ./dtb.img \
+ --os_version R --os_patch_level 2019-06-05 \
+ --pagesize 4096 --vendor_ramdisk ./ramdisk.img \
+ --header_version 4 --vendor_boot ./vboot.img \
+
"""
# boot.img.gz hex dump
@@ -44,6 +61,24 @@ b7762ffff07d345446c1281805e8a0868d81e117a45e111c0d8dc101b253
9c03c41a0c90f17fe85400986d82452b6c3680198a192a0ce17c3610ae34
d4a9820881a70f3873f35352731892f3730b124b32937252a96bb9119ae5
463a5546f82c1f05a360148c8251300a462e000085bf67f200200000"""
+
+# boot img v4 hex dump
+boot_img_hex = """1f8b080827b0cd630203626f6f742e696d6700edd8bd0d82601885d1d7c4
+58d8c808b88195bd098d8d246e40e42b083f1aa0717be99d003d277916b8
+e5bddc8a7b792d8e8788c896ce9b88d32ebe6c971e7ddd3543cae734cd01
+c0ffc84c0000b0766d1a87d4e5afeadd3dab7a6f10000000f84163d5d7cd
+d43a000000000000000060c53e7544995700400000"""
+
+# vendor boot image v4 hex dump
+vboot_img_hex = """1f8b0808baaecd63020376626f6f742e696d6700edd8310b824018c6f1b3
+222a08f41b3436b4280dcdd19c11d16ee9109d18d59042d047ec8b04cd0d
+d19d5a4345534bf6ffc173ef29272f38e93b1d0ec67dd79d548462aa1cd2
+d5d20b0000f8438678f90c18d584b8a4bbb3a557991ecb2a0000f80d6b2f
+f4179b656be5c532f2fc066f040000000080e23936af2755f62a3d918df1
+db2a7ab67f9ffdeb7df7cda3465ecb79c4ce7e5c577562bb9364b74449a5
+1e467e20c53c0a57de763193c1779b3b4fcd9d4ee27c6a0e00000000c0ff
+309ffea7010000000040f1dc004129855400400000"""
+
# Expected response for "abootimg dtb_dump" command
dtb_dump_resp="""## DTB area contents (concat format):
- DTB #0:
@@ -56,15 +91,21 @@ dtb_dump_resp="""## DTB area contents (concat format):
(DTB)compatible = y2,z2"""
# Address in RAM where to load the boot image ('abootimg' looks in $loadaddr)
loadaddr = 0x1000
+# Address in RAM where to load the vendor boot image ('abootimg' looks in $vloadaddr)
+vloadaddr= 0x10000
# Expected DTB #1 offset from the boot image start address
dtb1_offset = 0x187d
+# Expected DTB offset from the vendor boot image start address
+dtb2_offset = 0x207d
# DTB #1 start address in RAM
dtb1_addr = loadaddr + dtb1_offset
+# DTB #2 start address in RAM
+dtb2_addr = vloadaddr + dtb2_offset
class AbootimgTestDiskImage(object):
"""Disk image used by abootimg tests."""
- def __init__(self, u_boot_console):
+ def __init__(self, u_boot_console, image_name, hex_img):
"""Initialize a new AbootimgDiskImage object.
Args:
@@ -74,13 +115,13 @@ class AbootimgTestDiskImage(object):
Nothing.
"""
- gz_hex = u_boot_console.config.persistent_data_dir + '/boot.img.gz.hex'
- gz = u_boot_console.config.persistent_data_dir + '/boot.img.gz'
+ gz_hex = u_boot_console.config.persistent_data_dir + '/' + image_name + '.gz.hex'
+ gz = u_boot_console.config.persistent_data_dir + '/' + image_name + '.gz'
- filename = 'boot.img'
+ filename = image_name
persistent = u_boot_console.config.persistent_data_dir + '/' + filename
self.path = u_boot_console.config.result_dir + '/' + filename
-
+ u_boot_console.log.action('persistent is ' + persistent)
with u_boot_utils.persistent_file_helper(u_boot_console.log, persistent):
if os.path.exists(persistent):
u_boot_console.log.action('Disk image file ' + persistent +
@@ -89,19 +130,17 @@ class AbootimgTestDiskImage(object):
u_boot_console.log.action('Generating ' + persistent)
f = open(gz_hex, "w")
- f.write(img_hex)
+ f.write(hex_img)
f.close()
-
cmd = ('xxd', '-r', '-p', gz_hex, gz)
u_boot_utils.run_and_log(u_boot_console, cmd)
-
cmd = ('gunzip', '-9', gz)
u_boot_utils.run_and_log(u_boot_console, cmd)
cmd = ('cp', persistent, self.path)
u_boot_utils.run_and_log(u_boot_console, cmd)
-gtdi = None
+gtdi1 = None
@pytest.fixture(scope='function')
def abootimg_disk_image(u_boot_console):
"""pytest fixture to provide a AbootimgTestDiskImage object to tests.
@@ -109,10 +148,36 @@ def abootimg_disk_image(u_boot_console):
function-scoped. However, we don't need to actually do any function-scope
work, so this simply returns the same object over and over each time."""
- global gtdi
- if not gtdi:
- gtdi = AbootimgTestDiskImage(u_boot_console)
- return gtdi
+ global gtdi1
+ if not gtdi1:
+ gtdi1 = AbootimgTestDiskImage(u_boot_console, 'boot.img', img_hex)
+ return gtdi1
+
+gtdi2 = None
+@pytest.fixture(scope='function')
+def abootimgv4_disk_image_vboot(u_boot_console):
+ """pytest fixture to provide a AbootimgTestDiskImage object to tests.
+ This is function-scoped because it uses u_boot_console, which is also
+ function-scoped. However, we don't need to actually do any function-scope
+ work, so this simply returns the same object over and over each time."""
+
+ global gtdi2
+ if not gtdi2:
+ gtdi2 = AbootimgTestDiskImage(u_boot_console, 'vendor_boot.img', vboot_img_hex)
+ return gtdi2
+
+gtdi3 = None
+@pytest.fixture(scope='function')
+def abootimgv4_disk_image_boot(u_boot_console):
+ """pytest fixture to provide a AbootimgTestDiskImage object to tests.
+ This is function-scoped because it uses u_boot_console, which is also
+ function-scoped. However, we don't need to actually do any function-scope
+ work, so this simply returns the same object over and over each time."""
+
+ global gtdi3
+ if not gtdi3:
+ gtdi3 = AbootimgTestDiskImage(u_boot_console, 'bootv4.img', boot_img_hex)
+ return gtdi3
@pytest.mark.boardspec('sandbox')
@pytest.mark.buildconfigspec('android_boot_image')
@@ -157,3 +222,48 @@ def test_abootimg(abootimg_disk_image, u_boot_console):
u_boot_console.run_command('fdt get value v / model')
response = u_boot_console.run_command('env print v')
assert response == 'v=x2'
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('android_boot_image')
+@pytest.mark.buildconfigspec('cmd_abootimg')
+@pytest.mark.buildconfigspec('cmd_fdt')
+@pytest.mark.requiredtool('xxd')
+@pytest.mark.requiredtool('gunzip')
+def test_abootimgv4(abootimgv4_disk_image_vboot, abootimgv4_disk_image_boot, u_boot_console):
+ """Test the 'abootimg' command with boot image header v4."""
+
+ cons = u_boot_console
+ cons.log.action('Loading disk image to RAM...')
+ cons.run_command('setenv loadaddr 0x%x' % (loadaddr))
+ cons.run_command('setenv vloadaddr 0x%x' % (vloadaddr))
+ cons.run_command('host load hostfs - 0x%x %s' % (vloadaddr,
+ abootimgv4_disk_image_vboot.path))
+ cons.run_command('host load hostfs - 0x%x %s' % (loadaddr,
+ abootimgv4_disk_image_boot.path))
+ cons.run_command('abootimg addr 0x%x 0x%x' % (loadaddr, vloadaddr))
+ cons.log.action('Testing \'abootimg get ver\'...')
+ response = cons.run_command('abootimg get ver')
+ assert response == "4"
+ cons.run_command('abootimg get ver v')
+ response = cons.run_command('env print v')
+ assert response == 'v=4'
+
+ cons.log.action('Testing \'abootimg get recovery_dtbo\'...')
+ response = cons.run_command('abootimg get recovery_dtbo a')
+ assert response == 'Error: header version must be >= 1 and <= 2 to get dtbo'
+
+ cons.log.action('Testing \'abootimg get dtb_load_addr\'...')
+ cons.run_command('abootimg get dtb_load_addr a')
+ response = cons.run_command('env print a')
+ assert response == 'a=11f00000'
+
+ cons.log.action('Testing \'abootimg get dtb --index\'...')
+ cons.run_command('abootimg get dtb --index=1 dtb2_start')
+ response = cons.run_command('env print dtb2_start')
+ correct_str = "dtb2_start=%x" % (dtb2_addr)
+ assert response == correct_str
+
+ cons.run_command('fdt addr $dtb2_start')
+ cons.run_command('fdt get value v / model')
+ response = cons.run_command('env print v')
+ assert response == 'v=x2'