fwu_mdata.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (c) 2022, Linaro Limited
  4. */
  5. #include <command.h>
  6. #include <dm.h>
  7. #include <fwu.h>
  8. #include <fwu_mdata.h>
  9. #include <log.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <linux/types.h>
  13. static void print_mdata(struct fwu_mdata *mdata)
  14. {
  15. int i, j;
  16. struct fwu_image_entry *img_entry;
  17. struct fwu_image_bank_info *img_info;
  18. printf("\tFWU Metadata\n");
  19. printf("crc32: %#x\n", mdata->crc32);
  20. printf("version: %#x\n", mdata->version);
  21. printf("active_index: %#x\n", mdata->active_index);
  22. printf("previous_active_index: %#x\n", mdata->previous_active_index);
  23. printf("\tImage Info\n");
  24. for (i = 0; i < CONFIG_FWU_NUM_IMAGES_PER_BANK; i++) {
  25. img_entry = &mdata->img_entry[i];
  26. printf("\nImage Type Guid: %pUL\n",
  27. &img_entry->image_type_uuid);
  28. printf("Location Guid: %pUL\n", &img_entry->location_uuid);
  29. for (j = 0; j < CONFIG_FWU_NUM_BANKS; j++) {
  30. img_info = &img_entry->img_bank_info[j];
  31. printf("Image Guid: %pUL\n", &img_info->image_uuid);
  32. printf("Image Acceptance: %s\n",
  33. img_info->accepted == 0x1 ? "yes" : "no");
  34. }
  35. }
  36. }
  37. int do_fwu_mdata_read(struct cmd_tbl *cmdtp, int flag,
  38. int argc, char * const argv[])
  39. {
  40. int ret = CMD_RET_SUCCESS, res;
  41. struct fwu_mdata mdata;
  42. res = fwu_get_mdata(&mdata);
  43. if (res < 0) {
  44. log_err("Unable to get valid FWU metadata\n");
  45. ret = CMD_RET_FAILURE;
  46. goto out;
  47. }
  48. print_mdata(&mdata);
  49. out:
  50. return ret;
  51. }
  52. U_BOOT_CMD(
  53. fwu_mdata_read, 1, 1, do_fwu_mdata_read,
  54. "Read and print FWU metadata",
  55. ""
  56. );