blob: dc3a880882e973bafd2e83c2638dbea0fed9790b [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
Simon Glassdb6fb7d2020-07-07 21:32:02 -060015/**
16 * struct binman_info - Information needed by the binman library
17 *
18 * @image: Node describing the image we are running from
19 * @rom_offset: Offset from an image_pos to the memory-mapped address, or
20 * ROM_OFFSET_NONE if the ROM is not memory-mapped. Can be positive or
21 * negative
22 */
Simon Glass3c10dc92019-12-06 21:41:34 -070023struct binman_info {
24 ofnode image;
Simon Glassdb6fb7d2020-07-07 21:32:02 -060025 int rom_offset;
Simon Glass3c10dc92019-12-06 21:41:34 -070026};
27
Simon Glassdb6fb7d2020-07-07 21:32:02 -060028#define ROM_OFFSET_NONE (-1)
29
Simon Glass3c10dc92019-12-06 21:41:34 -070030static struct binman_info *binman;
31
32int binman_entry_find(const char *name, struct binman_entry *entry)
33{
34 ofnode node;
35 int ret;
36
37 node = ofnode_find_subnode(binman->image, name);
38 if (!ofnode_valid(node))
39 return log_msg_ret("no binman node", -ENOENT);
40
41 ret = ofnode_read_u32(node, "image-pos", &entry->image_pos);
42 if (ret)
43 return log_msg_ret("bad binman node1", ret);
44 ret = ofnode_read_u32(node, "size", &entry->size);
45 if (ret)
46 return log_msg_ret("bad binman node2", ret);
47
48 return 0;
49}
50
Simon Glassdb6fb7d2020-07-07 21:32:02 -060051void binman_set_rom_offset(int rom_offset)
52{
53 binman->rom_offset = rom_offset;
54}
55
Simon Glass3c10dc92019-12-06 21:41:34 -070056int binman_init(void)
57{
58 binman = malloc(sizeof(struct binman_info));
59 if (!binman)
60 return log_msg_ret("space for binman", -ENOMEM);
61 binman->image = ofnode_path("/binman");
62 if (!ofnode_valid(binman->image))
63 return log_msg_ret("binman node", -EINVAL);
Simon Glassdb6fb7d2020-07-07 21:32:02 -060064 binman->rom_offset = ROM_OFFSET_NONE;
Simon Glass3c10dc92019-12-06 21:41:34 -070065
66 return 0;
67}