1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright 2021 Google LLC
4 * Written by Simon Glass <sjg@chromium.org>
5 */
6
7 #include <common.h>
8 #include <dm.h>
9 #include <dm/of_extra.h>
10 #include <dm/test.h>
11 #include <test/ut.h>
12 #include <u-boot/sha256.h>
13
dm_test_ofnode_read_fmap_entry(struct unit_test_state * uts)14 static int dm_test_ofnode_read_fmap_entry(struct unit_test_state *uts)
15 {
16 const char hash_expect[] = {
17 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
18 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
19 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
20 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
21 };
22 struct fmap_entry entry;
23 ofnode node;
24
25 node = ofnode_path("/cros-ec/flash/wp-ro");
26 ut_assertok(ofnode_read_fmap_entry(node, &entry));
27 ut_asserteq(0xf000, entry.offset);
28 ut_asserteq(0x1000, entry.length);
29 ut_asserteq(0x884, entry.used);
30 ut_asserteq(FMAP_COMPRESS_LZ4, entry.compress_algo);
31 ut_asserteq(0xcf8, entry.unc_length);
32 ut_asserteq(FMAP_HASH_SHA256, entry.hash_algo);
33 ut_asserteq(SHA256_SUM_LEN, entry.hash_size);
34 ut_asserteq_mem(hash_expect, entry.hash, SHA256_SUM_LEN);
35
36 return 0;
37 }
38 DM_TEST(dm_test_ofnode_read_fmap_entry, 0);
39