qemu_dfu.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2020 Linaro Limited
  4. */
  5. #include <common.h>
  6. #include <dfu.h>
  7. #include <env.h>
  8. #include <memalign.h>
  9. #include <mtd.h>
  10. #define DFU_ALT_BUF_LEN SZ_1K
  11. static void board_get_alt_info(struct mtd_info *mtd, char *buf)
  12. {
  13. struct mtd_info *part;
  14. bool first = true;
  15. const char *name;
  16. int len, partnum = 0;
  17. name = mtd->name;
  18. len = strlen(buf);
  19. if (buf[0] != '\0')
  20. len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, "&");
  21. len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
  22. "mtd %s=", name);
  23. list_for_each_entry(part, &mtd->partitions, node) {
  24. partnum++;
  25. if (!first)
  26. len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, ";");
  27. first = false;
  28. len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
  29. "%s part %d",
  30. part->name, partnum);
  31. }
  32. }
  33. void set_dfu_alt_info(char *interface, char *devstr)
  34. {
  35. struct mtd_info *mtd;
  36. ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
  37. if (!IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) &&
  38. env_get("dfu_alt_info"))
  39. return;
  40. memset(buf, 0, DFU_ALT_BUF_LEN);
  41. /*
  42. * Currently dfu_alt_info is needed on Qemu ARM64 for
  43. * capsule updates
  44. */
  45. if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT) &&
  46. IS_ENABLED(CONFIG_TARGET_QEMU_ARM_64BIT)) {
  47. /* probe all MTD devices */
  48. mtd_probe_devices();
  49. mtd = get_mtd_device_nm("nor0");
  50. if (!IS_ERR_OR_NULL(mtd))
  51. board_get_alt_info(mtd, buf);
  52. }
  53. env_set("dfu_alt_info", buf);
  54. printf("dfu_alt_info set\n");
  55. }