diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index f86cd0d3b27..e95f4631bf2 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -90,6 +90,16 @@ wp-ro { image-pos = <0xf000>; size = <0x1000>; + used = <0x884>; + compress = "lz4"; + uncomp-size = <0xcf8>; + hash { + algo = "sha256"; + value = [00 01 02 03 04 05 06 07 + 08 09 0a 0b 0c 0d 0e 0f + 10 11 12 13 14 15 16 17 + 18 19 1a 1b 1c 1d 1e 1f]; + }; }; rw { image-pos = <0x10000>; diff --git a/drivers/core/of_extra.c b/drivers/core/of_extra.c index 6420e6ec448..653344529e6 100644 --- a/drivers/core/of_extra.c +++ b/drivers/core/of_extra.c @@ -14,16 +14,17 @@ int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry) { const char *prop; + ofnode subnode; if (ofnode_read_u32(node, "image-pos", &entry->offset)) { debug("Node '%s' has bad/missing 'image-pos' property\n", ofnode_get_name(node)); - return log_ret(-ENOENT); + return log_msg_ret("image-pos", -ENOENT); } if (ofnode_read_u32(node, "size", &entry->length)) { debug("Node '%s' has bad/missing 'size' property\n", ofnode_get_name(node)); - return log_ret(-ENOENT); + return log_msg_ret("size", -ENOENT); } entry->used = ofnode_read_s32_default(node, "used", entry->length); prop = ofnode_read_string(node, "compress"); @@ -31,18 +32,20 @@ int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry) if (!strcmp(prop, "lz4")) entry->compress_algo = FMAP_COMPRESS_LZ4; else - return log_msg_ret("Unknown compression algo", - -EINVAL); + return log_msg_ret("compression algo", -EINVAL); } else { entry->compress_algo = FMAP_COMPRESS_NONE; } entry->unc_length = ofnode_read_s32_default(node, "uncomp-size", entry->length); - prop = ofnode_read_string(node, "hash"); - if (prop) - entry->hash_size = strlen(prop); - entry->hash_algo = prop ? FMAP_HASH_SHA256 : FMAP_HASH_NONE; - entry->hash = (uint8_t *)prop; + subnode = ofnode_find_subnode(node, "hash"); + if (ofnode_valid(subnode)) { + prop = ofnode_read_prop(subnode, "value", &entry->hash_size); + + /* Assume it is sha256 */ + entry->hash_algo = prop ? FMAP_HASH_SHA256 : FMAP_HASH_NONE; + entry->hash = (uint8_t *)prop; + } return 0; } diff --git a/test/dm/Makefile b/test/dm/Makefile index afcabfacc1b..e70e50f4024 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -42,6 +42,7 @@ obj-y += fdtdec.o obj-$(CONFIG_UT_DM) += nop.o obj-y += ofnode.o obj-y += ofread.o +obj-y += of_extra.o obj-$(CONFIG_OSD) += osd.o obj-$(CONFIG_DM_VIDEO) += panel.o obj-$(CONFIG_DM_PCI) += pci.o diff --git a/test/dm/of_extra.c b/test/dm/of_extra.c new file mode 100644 index 00000000000..b19cd3787d8 --- /dev/null +++ b/test/dm/of_extra.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright 2021 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include +#include +#include + +static int dm_test_ofnode_read_fmap_entry(struct unit_test_state *uts) +{ + const char hash_expect[] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + }; + struct fmap_entry entry; + ofnode node; + + node = ofnode_path("/cros-ec/flash/wp-ro"); + ut_assertok(ofnode_read_fmap_entry(node, &entry)); + ut_asserteq(0xf000, entry.offset); + ut_asserteq(0x1000, entry.length); + ut_asserteq(0x884, entry.used); + ut_asserteq(FMAP_COMPRESS_LZ4, entry.compress_algo); + ut_asserteq(0xcf8, entry.unc_length); + ut_asserteq(FMAP_HASH_SHA256, entry.hash_algo); + ut_asserteq(SHA256_SUM_LEN, entry.hash_size); + ut_asserteq_mem(hash_expect, entry.hash, SHA256_SUM_LEN); + + return 0; +} +DM_TEST(dm_test_ofnode_read_fmap_entry, 0);