1 // SPDX-License-Identifier: Intel
3 * Access to binman information at runtime
5 * Copyright 2019 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
17 * struct binman_info - Information needed by the binman library
19 * @image: Node describing the image we are running from
20 * @rom_offset: Offset from an image_pos to the memory-mapped address, or
21 * ROM_OFFSET_NONE if the ROM is not memory-mapped. Can be positive or
29 #define ROM_OFFSET_NONE (-1)
31 static struct binman_info *binman;
33 static int binman_entry_find_internal(ofnode node, const char *name,
34 struct binman_entry *entry)
38 if (!ofnode_valid(node))
40 node = ofnode_find_subnode(node, name);
41 if (!ofnode_valid(node))
42 return log_msg_ret("node", -ENOENT);
44 ret = ofnode_read_u32(node, "image-pos", &entry->image_pos);
46 return log_msg_ret("image-pos", ret);
47 ret = ofnode_read_u32(node, "size", &entry->size);
49 return log_msg_ret("size", ret);
54 int binman_entry_find(const char *name, struct binman_entry *entry)
56 return binman_entry_find_internal(binman->image, name, entry);
59 int binman_entry_map(ofnode parent, const char *name, void **bufp, int *sizep)
61 struct binman_entry entry;
64 if (binman->rom_offset == ROM_OFFSET_NONE)
66 ret = binman_entry_find_internal(parent, name, &entry);
68 return log_msg_ret("entry", ret);
71 *bufp = map_sysmem(entry.image_pos + binman->rom_offset, entry.size);
76 ofnode binman_section_find_node(const char *name)
78 return ofnode_find_subnode(binman->image, name);
81 void binman_set_rom_offset(int rom_offset)
83 binman->rom_offset = rom_offset;
86 int binman_get_rom_offset(void)
88 return binman->rom_offset;
93 binman = malloc(sizeof(struct binman_info));
95 return log_msg_ret("space for binman", -ENOMEM);
96 binman->image = ofnode_path("/binman");
97 if (!ofnode_valid(binman->image))
98 return log_msg_ret("binman node", -EINVAL);
99 if (ofnode_read_bool(binman->image, "multiple-images")) {
100 ofnode node = ofnode_first_subnode(binman->image);
102 if (!ofnode_valid(node))
103 return log_msg_ret("first image", -ENOENT);
104 binman->image = node;
106 binman_set_rom_offset(ROM_OFFSET_NONE);