binman.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #include <common.h>
  9. #include <binman.h>
  10. #include <dm.h>
  11. #include <malloc.h>
  12. struct binman_info {
  13. ofnode image;
  14. };
  15. static struct binman_info *binman;
  16. int binman_entry_find(const char *name, struct binman_entry *entry)
  17. {
  18. ofnode node;
  19. int ret;
  20. node = ofnode_find_subnode(binman->image, name);
  21. if (!ofnode_valid(node))
  22. return log_msg_ret("no binman node", -ENOENT);
  23. ret = ofnode_read_u32(node, "image-pos", &entry->image_pos);
  24. if (ret)
  25. return log_msg_ret("bad binman node1", ret);
  26. ret = ofnode_read_u32(node, "size", &entry->size);
  27. if (ret)
  28. return log_msg_ret("bad binman node2", ret);
  29. return 0;
  30. }
  31. int binman_init(void)
  32. {
  33. binman = malloc(sizeof(struct binman_info));
  34. if (!binman)
  35. return log_msg_ret("space for binman", -ENOMEM);
  36. binman->image = ofnode_path("/binman");
  37. if (!ofnode_valid(binman->image))
  38. return log_msg_ret("binman node", -EINVAL);
  39. return 0;
  40. }