]>
git.ipfire.org Git - thirdparty/u-boot.git/blob - board/st/common/stm32mp_dfu.c
1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
3 * Copyright (C) 2020, STMicroelectronics - All Rights Reserved
15 #define DFU_ALT_BUF_LEN SZ_1K
17 static void board_get_alt_info_mmc(struct udevice
*dev
, char *buf
)
19 disk_partition_t info
;
24 struct blk_desc
*desc
;
26 mmc
= mmc_get_mmc_dev(dev
);
33 desc
= mmc_get_blk_desc(mmc
);
37 name
= blk_get_if_type_name(desc
->if_type
);
38 devnum
= desc
->devnum
;
42 len
+= snprintf(buf
+ len
,
43 DFU_ALT_BUF_LEN
- len
, "&");
44 len
+= snprintf(buf
+ len
, DFU_ALT_BUF_LEN
- len
,
45 "%s %d=", name
, devnum
);
47 if (IS_MMC(mmc
) && mmc
->capacity_boot
) {
48 len
+= snprintf(buf
+ len
, DFU_ALT_BUF_LEN
- len
,
49 "%s%d_boot1 raw 0x0 0x%llx mmcpart 1;",
50 name
, devnum
, mmc
->capacity_boot
);
51 len
+= snprintf(buf
+ len
, DFU_ALT_BUF_LEN
- len
,
52 "%s%d_boot2 raw 0x0 0x%llx mmcpart 2",
53 name
, devnum
, mmc
->capacity_boot
);
57 for (p
= 1; p
< MAX_SEARCH_PARTITIONS
; p
++) {
58 if (part_get_info(desc
, p
, &info
))
61 len
+= snprintf(buf
+ len
, DFU_ALT_BUF_LEN
- len
, ";");
63 len
+= snprintf(buf
+ len
, DFU_ALT_BUF_LEN
- len
,
65 name
, devnum
, info
.name
, devnum
, p
);
69 static void board_get_alt_info_mtd(struct mtd_info
*mtd
, char *buf
)
71 struct mtd_info
*part
;
80 len
+= snprintf(buf
+ len
, DFU_ALT_BUF_LEN
- len
, "&");
81 len
+= snprintf(buf
+ len
, DFU_ALT_BUF_LEN
- len
,
84 len
+= snprintf(buf
+ len
, DFU_ALT_BUF_LEN
- len
,
88 list_for_each_entry(part
, &mtd
->partitions
, node
) {
91 len
+= snprintf(buf
+ len
, DFU_ALT_BUF_LEN
- len
, ";");
94 len
+= snprintf(buf
+ len
, DFU_ALT_BUF_LEN
- len
,
96 name
, part
->name
, partnum
);
100 void set_dfu_alt_info(char *interface
, char *devstr
)
103 struct mtd_info
*mtd
;
105 ALLOC_CACHE_ALIGN_BUFFER(char, buf
, DFU_ALT_BUF_LEN
);
107 if (env_get("dfu_alt_info"))
110 memset(buf
, 0, sizeof(buf
));
112 snprintf(buf
, DFU_ALT_BUF_LEN
,
113 "ram 0=%s", CONFIG_DFU_ALT_RAM0
);
115 if (!uclass_get_device(UCLASS_MMC
, 0, &dev
))
116 board_get_alt_info_mmc(dev
, buf
);
118 if (!uclass_get_device(UCLASS_MMC
, 1, &dev
))
119 board_get_alt_info_mmc(dev
, buf
);
121 if (CONFIG_IS_ENABLED(MTD
)) {
122 /* probe all MTD devices */
125 /* probe SPI flash device on a bus */
126 if (!uclass_get_device(UCLASS_SPI_FLASH
, 0, &dev
)) {
127 mtd
= get_mtd_device_nm("nor0");
128 if (!IS_ERR_OR_NULL(mtd
))
129 board_get_alt_info_mtd(mtd
, buf
);
132 mtd
= get_mtd_device_nm("nand0");
133 if (!IS_ERR_OR_NULL(mtd
))
134 board_get_alt_info_mtd(mtd
, buf
);
136 mtd
= get_mtd_device_nm("spi-nand0");
137 if (!IS_ERR_OR_NULL(mtd
))
138 board_get_alt_info_mtd(mtd
, buf
);
141 #ifdef CONFIG_DFU_VIRT
142 strncat(buf
, "&virt 0=OTP", DFU_ALT_BUF_LEN
);
144 if (IS_ENABLED(CONFIG_PMIC_STPMIC1
))
145 strncat(buf
, "&virt 1=PMIC", DFU_ALT_BUF_LEN
);
148 env_set("dfu_alt_info", buf
);
149 puts("DFU alt info setting: done\n");
152 #if CONFIG_IS_ENABLED(DFU_VIRT)
154 #include <power/stpmic1.h>
156 static int dfu_otp_read(u64 offset
, u8
*buffer
, long *size
)
161 ret
= uclass_get_device_by_driver(UCLASS_MISC
,
162 DM_GET_DRIVER(stm32mp_bsec
),
167 ret
= misc_read(dev
, offset
+ STM32_BSEC_OTP_OFFSET
, buffer
, *size
);
176 static int dfu_pmic_read(u64 offset
, u8
*buffer
, long *size
)
179 #ifdef CONFIG_PMIC_STPMIC1
182 ret
= uclass_get_device_by_driver(UCLASS_MISC
,
183 DM_GET_DRIVER(stpmic1_nvm
),
188 ret
= misc_read(dev
, 0xF8 + offset
, buffer
, *size
);
193 if (ret
== -EACCES
) {
198 pr_err("PMIC update not supported");
205 int dfu_read_medium_virt(struct dfu_entity
*dfu
, u64 offset
,
206 void *buf
, long *len
)
208 switch (dfu
->data
.virt
.dev_num
) {
210 return dfu_otp_read(offset
, buf
, len
);
212 return dfu_pmic_read(offset
, buf
, len
);
218 int __weak
dfu_get_medium_size_virt(struct dfu_entity
*dfu
, u64
*size
)