board: stm32mp1: fix handling of DT OP-TEE reserved memory nodes
[oweals/u-boot.git] / lib / binman.c
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 #include <log.h>
13 #include <malloc.h>
14
15 struct binman_info {
16         ofnode image;
17 };
18
19 static struct binman_info *binman;
20
21 int 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
40 int 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 }