]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: Update ofnode_read_fmap_entry() to read hashes
authorSimon Glass <sjg@chromium.org>
Thu, 21 Jan 2021 20:57:14 +0000 (13:57 -0700)
committerSimon Glass <sjg@chromium.org>
Sat, 30 Jan 2021 21:25:42 +0000 (14:25 -0700)
At present this function uses the old format for reading hashes. Add
support for the current format.

Add a test while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>
arch/sandbox/dts/test.dts
drivers/core/of_extra.c
test/dm/Makefile
test/dm/of_extra.c [new file with mode: 0644]

index f86cd0d3b27720e7cb0c245dd18691fa394a8cf8..e95f4631bf2f8296f2a113b71706094423fee7e2 100644 (file)
                        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>;
index 6420e6ec448091ebe62d679539e68776a88c9373..653344529e6982cd245cae2b8d4a04185e31c2ec 100644 (file)
 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;
 }
index afcabfacc1bd7a2b5ff1ba8bd794f0bca4da9acb..e70e50f4024396d3021af769e3d21c3b20207862 100644 (file)
@@ -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 (file)
index 0000000..b19cd37
--- /dev/null
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2021 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/of_extra.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <u-boot/sha256.h>
+
+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);