From 240b93201007183d5fd651a210ddb4c50ee30980 Mon Sep 17 00:00:00 2001 From: Lokesh Vutla Date: Wed, 4 Sep 2019 16:01:26 +0530 Subject: dm: core: Add a function to count the children of a device Add a function to count the available children of a device. Signed-off-by: Lokesh Vutla --- test/dm/bus.c | 41 +++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 26 deletions(-) (limited to 'test/dm') diff --git a/test/dm/bus.c b/test/dm/bus.c index 93f3acd430..1ad45adb60 100644 --- a/test/dm/bus.c +++ b/test/dm/bus.c @@ -8,6 +8,7 @@ #include #endif #include +#include #include #include #include @@ -371,7 +372,6 @@ static int test_bus_parent_platdata(struct unit_test_state *uts) { struct dm_test_parent_platdata *plat; struct udevice *bus, *dev; - int child_count; /* Check that the bus has no children */ ut_assertok(uclass_find_device(UCLASS_TEST_BUS, 0, &bus)); @@ -380,7 +380,7 @@ static int test_bus_parent_platdata(struct unit_test_state *uts) ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); - for (device_find_first_child(bus, &dev), child_count = 0; + for (device_find_first_child(bus, &dev); dev; device_find_next_child(&dev)) { /* Check that platform data is allocated */ @@ -399,22 +399,20 @@ static int test_bus_parent_platdata(struct unit_test_state *uts) ut_asserteq_ptr(plat, dev_get_parent_platdata(dev)); ut_asserteq(1, plat->count); ut_assertok(device_probe(dev)); - child_count++; } - ut_asserteq(3, child_count); + ut_asserteq(3, device_get_child_count(bus)); /* Removing the bus should also have no effect (it is still bound) */ device_remove(bus, DM_REMOVE_NORMAL); - for (device_find_first_child(bus, &dev), child_count = 0; + for (device_find_first_child(bus, &dev); dev; device_find_next_child(&dev)) { /* Check that platform data is allocated */ plat = dev_get_parent_platdata(dev); ut_assert(plat != NULL); ut_asserteq(1, plat->count); - child_count++; } - ut_asserteq(3, child_count); + ut_asserteq(3, device_get_child_count(bus)); /* Unbind all the children */ do { @@ -425,16 +423,15 @@ static int test_bus_parent_platdata(struct unit_test_state *uts) /* Now the child platdata should be removed and re-added */ device_probe(bus); - for (device_find_first_child(bus, &dev), child_count = 0; + for (device_find_first_child(bus, &dev); dev; device_find_next_child(&dev)) { /* Check that platform data is allocated */ plat = dev_get_parent_platdata(dev); ut_assert(plat != NULL); ut_asserteq(0, plat->count); - child_count++; } - ut_asserteq(3, child_count); + ut_asserteq(3, device_get_child_count(bus)); return 0; } @@ -480,19 +477,17 @@ static int dm_test_bus_child_post_bind(struct unit_test_state *uts) { struct dm_test_parent_platdata *plat; struct udevice *bus, *dev; - int child_count; ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); - for (device_find_first_child(bus, &dev), child_count = 0; + for (device_find_first_child(bus, &dev); dev; device_find_next_child(&dev)) { /* Check that platform data is allocated */ plat = dev_get_parent_platdata(dev); ut_assert(plat != NULL); ut_asserteq(1, plat->bind_flag); - child_count++; } - ut_asserteq(3, child_count); + ut_asserteq(3, device_get_child_count(bus)); return 0; } @@ -503,19 +498,17 @@ static int dm_test_bus_child_post_bind_uclass(struct unit_test_state *uts) { struct dm_test_parent_platdata *plat; struct udevice *bus, *dev; - int child_count; ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); - for (device_find_first_child(bus, &dev), child_count = 0; + for (device_find_first_child(bus, &dev); dev; device_find_next_child(&dev)) { /* Check that platform data is allocated */ plat = dev_get_parent_platdata(dev); ut_assert(plat != NULL); ut_asserteq(2, plat->uclass_bind_flag); - child_count++; } - ut_asserteq(3, child_count); + ut_asserteq(3, device_get_child_count(bus)); return 0; } @@ -529,14 +522,13 @@ DM_TEST(dm_test_bus_child_post_bind_uclass, static int dm_test_bus_child_pre_probe_uclass(struct unit_test_state *uts) { struct udevice *bus, *dev; - int child_count; /* * See testfdt_drv_probe() which effectively checks that the uclass * flag is set before that method is called */ ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); - for (device_find_first_child(bus, &dev), child_count = 0; + for (device_find_first_child(bus, &dev); dev; device_find_next_child(&dev)) { struct dm_test_priv *priv = dev_get_priv(dev); @@ -549,9 +541,8 @@ static int dm_test_bus_child_pre_probe_uclass(struct unit_test_state *uts) ut_assert(priv != NULL); ut_asserteq(1, priv->uclass_flag); ut_asserteq(1, priv->uclass_total); - child_count++; } - ut_asserteq(3, child_count); + ut_asserteq(3, device_get_child_count(bus)); return 0; } @@ -565,14 +556,13 @@ DM_TEST(dm_test_bus_child_pre_probe_uclass, static int dm_test_bus_child_post_probe_uclass(struct unit_test_state *uts) { struct udevice *bus, *dev; - int child_count; /* * See testfdt_drv_probe() which effectively initializes that * the uclass postp flag is set to a value */ ut_assertok(uclass_get_device(UCLASS_TEST_BUS, 0, &bus)); - for (device_find_first_child(bus, &dev), child_count = 0; + for (device_find_first_child(bus, &dev); dev; device_find_next_child(&dev)) { struct dm_test_priv *priv = dev_get_priv(dev); @@ -584,9 +574,8 @@ static int dm_test_bus_child_post_probe_uclass(struct unit_test_state *uts) priv = dev_get_priv(dev); ut_assert(priv != NULL); ut_asserteq(0, priv->uclass_postp); - child_count++; } - ut_asserteq(3, child_count); + ut_asserteq(3, device_get_child_count(bus)); return 0; } -- cgit From 14d963d1b51fc7a57b8d561588f163d7cae8ed81 Mon Sep 17 00:00:00 2001 From: Lokesh Vutla Date: Wed, 4 Sep 2019 16:01:28 +0530 Subject: remoteproc: elf_loader: Always check the validity of the image before loading rproc_elf32_load_image() rely on user to send a valid address for elf loading. Instead do a sanity check on the address passed by user. This will help all rproc elf users to not call sanity_check explicitly before calling elf_loading. Signed-off-by: Lokesh Vutla Reviewed-by: Fabien Dessenne --- test/dm/remoteproc.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'test/dm') diff --git a/test/dm/remoteproc.c b/test/dm/remoteproc.c index a2c4be7c27..c77361c8f4 100644 --- a/test/dm/remoteproc.c +++ b/test/dm/remoteproc.c @@ -171,11 +171,8 @@ static int dm_test_remoteproc_elf(struct unit_test_state *uts) ut_assertnonnull(loaded_firmware); memset(loaded_firmware, 0, loaded_firmware_size); - /* Verify valid ELF format */ - ut_assertok(rproc_elf32_sanity_check((ulong)valid_elf32, size)); - /* Load firmware in loaded_firmware, and verify it */ - ut_assertok(rproc_elf32_load_image(dev, (unsigned long)valid_elf32)); + ut_assertok(rproc_elf32_load_image(dev, (ulong)valid_elf32, size)); ut_assertok(memcmp(loaded_firmware, valid_elf32, loaded_firmware_size)); unmap_physmem(loaded_firmware, MAP_NOCACHE); -- cgit From 81e39fbd9251bfbef3bc156735e95b67cd7a828f Mon Sep 17 00:00:00 2001 From: Lokesh Vutla Date: Wed, 4 Sep 2019 16:01:31 +0530 Subject: remoteproc: elf_loader: Introduce rproc_elf_get_boot_addr() api Introduce rproc_elf_get_boot_addr() that returns the entry point of the elf file. This api auto detects the 64/32 bit elf file and returns the boot addr accordingly. Signed-off-by: Lokesh Vutla --- test/dm/remoteproc.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/dm') diff --git a/test/dm/remoteproc.c b/test/dm/remoteproc.c index c77361c8f4..1d9a9b32d5 100644 --- a/test/dm/remoteproc.c +++ b/test/dm/remoteproc.c @@ -174,6 +174,8 @@ static int dm_test_remoteproc_elf(struct unit_test_state *uts) /* Load firmware in loaded_firmware, and verify it */ ut_assertok(rproc_elf32_load_image(dev, (ulong)valid_elf32, size)); ut_assertok(memcmp(loaded_firmware, valid_elf32, loaded_firmware_size)); + ut_asserteq(rproc_elf_get_boot_addr(dev, (unsigned long)valid_elf32), + 0x08000000); unmap_physmem(loaded_firmware, MAP_NOCACHE); /* Invalid ELF Magic */ -- cgit