Sughosh Ganu | f62937c | 2020-12-30 19:27:03 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2020 Linaro Limited |
| 4 | */ |
| 5 | |
Sughosh Ganu | f62937c | 2020-12-30 19:27:03 +0530 | [diff] [blame] | 6 | #include <dfu.h> |
| 7 | #include <env.h> |
| 8 | #include <memalign.h> |
| 9 | #include <mtd.h> |
| 10 | |
| 11 | #define DFU_ALT_BUF_LEN SZ_1K |
| 12 | |
| 13 | static void board_get_alt_info(struct mtd_info *mtd, char *buf) |
| 14 | { |
| 15 | struct mtd_info *part; |
| 16 | bool first = true; |
| 17 | const char *name; |
| 18 | int len, partnum = 0; |
| 19 | |
| 20 | name = mtd->name; |
| 21 | len = strlen(buf); |
| 22 | |
| 23 | if (buf[0] != '\0') |
| 24 | len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, "&"); |
| 25 | len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, |
| 26 | "mtd %s=", name); |
| 27 | |
| 28 | list_for_each_entry(part, &mtd->partitions, node) { |
| 29 | partnum++; |
| 30 | if (!first) |
| 31 | len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, ";"); |
| 32 | first = false; |
| 33 | |
| 34 | len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, |
| 35 | "%s part %d", |
| 36 | part->name, partnum); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | void set_dfu_alt_info(char *interface, char *devstr) |
| 41 | { |
| 42 | struct mtd_info *mtd; |
| 43 | |
| 44 | ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); |
| 45 | |
Simon Glass | b819621 | 2023-02-05 15:39:42 -0700 | [diff] [blame] | 46 | if (!IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) && |
Sughosh Ganu | ccb3646 | 2022-04-15 11:29:34 +0530 | [diff] [blame] | 47 | env_get("dfu_alt_info")) |
Sughosh Ganu | f62937c | 2020-12-30 19:27:03 +0530 | [diff] [blame] | 48 | return; |
| 49 | |
Tom Rini | 426e30f | 2023-04-06 09:58:40 -0400 | [diff] [blame] | 50 | memset(buf, 0, DFU_ALT_BUF_LEN); |
Sughosh Ganu | f62937c | 2020-12-30 19:27:03 +0530 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * Currently dfu_alt_info is needed on Qemu ARM64 for |
| 54 | * capsule updates |
| 55 | */ |
| 56 | if (IS_ENABLED(CONFIG_EFI_CAPSULE_FIRMWARE_MANAGEMENT) && |
| 57 | IS_ENABLED(CONFIG_TARGET_QEMU_ARM_64BIT)) { |
| 58 | /* probe all MTD devices */ |
| 59 | mtd_probe_devices(); |
| 60 | |
| 61 | mtd = get_mtd_device_nm("nor0"); |
| 62 | if (!IS_ERR_OR_NULL(mtd)) |
| 63 | board_get_alt_info(mtd, buf); |
| 64 | } |
| 65 | |
| 66 | env_set("dfu_alt_info", buf); |
| 67 | printf("dfu_alt_info set\n"); |
| 68 | } |