Simon Glass | dd7fb9b | 2019-12-06 21:41:34 -0700 | [diff] [blame] | 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> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <malloc.h> |
Simon Glass | dd7fb9b | 2019-12-06 21:41:34 -0700 | [diff] [blame] | 13 | |
| 14 | struct binman_info { |
| 15 | ofnode image; |
| 16 | }; |
| 17 | |
| 18 | static struct binman_info *binman; |
| 19 | |
| 20 | int 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 | |
| 39 | int 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 | } |