Blame view

lib/binman.c 1.03 KB
3c10dc95b   Simon Glass   binman: Add a lib...
1
2
3
4
5
6
7
8
9
10
11
  // SPDX-License-Identifier: Intel
  /*
   * Access to binman information at runtime
   *
   * Copyright 2019 Google LLC
   * Written by Simon Glass <sjg@chromium.org>
   */
  
  #include <common.h>
  #include <binman.h>
  #include <dm.h>
336d4615f   Simon Glass   dm: core: Create ...
12
  #include <malloc.h>
3c10dc95b   Simon Glass   binman: Add a lib...
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  
  struct binman_info {
  	ofnode image;
  };
  
  static struct binman_info *binman;
  
  int binman_entry_find(const char *name, struct binman_entry *entry)
  {
  	ofnode node;
  	int ret;
  
  	node = ofnode_find_subnode(binman->image, name);
  	if (!ofnode_valid(node))
  		return log_msg_ret("no binman node", -ENOENT);
  
  	ret = ofnode_read_u32(node, "image-pos", &entry->image_pos);
  	if (ret)
  		return log_msg_ret("bad binman node1", ret);
  	ret = ofnode_read_u32(node, "size", &entry->size);
  	if (ret)
  		return log_msg_ret("bad binman node2", ret);
  
  	return 0;
  }
  
  int binman_init(void)
  {
  	binman = malloc(sizeof(struct binman_info));
  	if (!binman)
  		return log_msg_ret("space for binman", -ENOMEM);
  	binman->image = ofnode_path("/binman");
  	if (!ofnode_valid(binman->image))
  		return log_msg_ret("binman node", -EINVAL);
  
  	return 0;
  }