xref: /openbmc/u-boot/drivers/core/of_extra.c (revision baefb63a)
1 /*
2  * Copyright (c) 2017 Google, Inc
3  * Written by Simon Glass <sjg@chromium.org>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #include <common.h>
9 #include <libfdt.h>
10 #include <dm/of_access.h>
11 #include <dm/of_extra.h>
12 #include <dm/ofnode.h>
13 
14 int of_read_fmap_entry(ofnode node, const char *name,
15 		       struct fmap_entry *entry)
16 {
17 	const char *prop;
18 	u32 reg[2];
19 
20 	if (ofnode_read_u32_array(node, "reg", reg, 2)) {
21 		debug("Node '%s' has bad/missing 'reg' property\n", name);
22 		return -FDT_ERR_NOTFOUND;
23 	}
24 	entry->offset = reg[0];
25 	entry->length = reg[1];
26 	entry->used = ofnode_read_s32_default(node, "used", entry->length);
27 	prop = ofnode_read_string(node, "compress");
28 	entry->compress_algo = prop && !strcmp(prop, "lzo") ?
29 		FMAP_COMPRESS_LZO : FMAP_COMPRESS_NONE;
30 	prop = ofnode_read_string(node, "hash");
31 	if (prop)
32 		entry->hash_size = strlen(prop);
33 	entry->hash_algo = prop ? FMAP_HASH_SHA256 : FMAP_HASH_NONE;
34 	entry->hash = (uint8_t *)prop;
35 
36 	return 0;
37 }
38