binman.c 1.0 KB

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