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