blob: 6cf6dcfdad60558c45ef8c985a0c2d9eb2b0a609 [file] [log] [blame]
Simon Glass3c10dc92019-12-06 21:41:34 -07001// 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>
Simon Glass336d4612020-02-03 07:36:16 -070012#include <malloc.h>
Simon Glass3c10dc92019-12-06 21:41:34 -070013
14struct binman_info {
15 ofnode image;
16};
17
18static struct binman_info *binman;
19
20int binman_entry_find(const char *name, struct binman_entry *entry)
21{
22 ofnode node;
23 int ret;
24
25 node = ofnode_find_subnode(binman->image, name);
26 if (!ofnode_valid(node))
27 return log_msg_ret("no binman node", -ENOENT);
28
29 ret = ofnode_read_u32(node, "image-pos", &entry->image_pos);
30 if (ret)
31 return log_msg_ret("bad binman node1", ret);
32 ret = ofnode_read_u32(node, "size", &entry->size);
33 if (ret)
34 return log_msg_ret("bad binman node2", ret);
35
36 return 0;
37}
38
39int binman_init(void)
40{
41 binman = malloc(sizeof(struct binman_info));
42 if (!binman)
43 return log_msg_ret("space for binman", -ENOMEM);
44 binman->image = ofnode_path("/binman");
45 if (!ofnode_valid(binman->image))
46 return log_msg_ret("binman node", -EINVAL);
47
48 return 0;
49}