blob: 393fcaeb7422d9ca206061c7e5209728601fc695 [file] [log] [blame]
Sughosh Ganuf62937c2020-12-30 19:27:03 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2020 Linaro Limited
4 */
5
Sughosh Ganuf62937c2020-12-30 19:27:03 +05306#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
13static 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
40void 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 Glassb8196212023-02-05 15:39:42 -070046 if (!IS_ENABLED(CONFIG_EFI_HAVE_CAPSULE_SUPPORT) &&
Sughosh Ganuccb36462022-04-15 11:29:34 +053047 env_get("dfu_alt_info"))
Sughosh Ganuf62937c2020-12-30 19:27:03 +053048 return;
49
Tom Rini426e30f2023-04-06 09:58:40 -040050 memset(buf, 0, DFU_ALT_BUF_LEN);
Sughosh Ganuf62937c2020-12-30 19:27:03 +053051
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}