1 // SPDX-License-Identifier: Intel
2 /*
3 * Access to binman information at runtime
4 *
5 * Copyright 2019 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9 #include <common.h>
10 #include <binman.h>
11 #include <dm.h>
12
13 struct binman_info {
14 ofnode image;
15 };
16
17 static struct binman_info *binman;
18
binman_entry_find(const char * name,struct binman_entry * entry)19 int binman_entry_find(const char *name, struct binman_entry *entry)
20 {
21 ofnode node;
22 int ret;
23
24 node = ofnode_find_subnode(binman->image, name);
25 if (!ofnode_valid(node))
26 return log_msg_ret("no binman node", -ENOENT);
27
28 ret = ofnode_read_u32(node, "image-pos", &entry->image_pos);
29 if (ret)
30 return log_msg_ret("bad binman node1", ret);
31 ret = ofnode_read_u32(node, "size", &entry->size);
32 if (ret)
33 return log_msg_ret("bad binman node2", ret);
34
35 return 0;
36 }
37
binman_init(void)38 int binman_init(void)
39 {
40 binman = malloc(sizeof(struct binman_info));
41 if (!binman)
42 return log_msg_ret("space for binman", -ENOMEM);
43 binman->image = ofnode_path("/binman");
44 if (!ofnode_valid(binman->image))
45 return log_msg_ret("binman node", -EINVAL);
46
47 return 0;
48 }
49