From 6d147efd19e42b03b812392c4bf8eee4e96b2d2d Mon Sep 17 00:00:00 2001 From: Max Krummenacher Date: Sat, 18 Feb 2023 12:28:56 +0100 Subject: board: verdin-am62: allow dfu update Detect if U-Boot proper was booted from DFU, if so start DFU for flashing U-boot to eMMC boot area followed by UMS for flashing eMMC user area. Upstream-Status: Pending Initial U-Boot to be used for bring-up and validation of the V1.0 design, we'll decide on the step forward to mainline this once the bring-up and validation will be done. Refactoring ideas: - `Detect DFU boot` moved into arch K3 specific code. - `Detect DFU boot` by DFUing to a 'DFU' address a magic pattern and test that address. - Have a special U-Boot configuration for DFU boots,. - With TEZI available for Verdin AM62 this commit can be dropped. - The TEZI U-Boot could then have in its boot flow: ... if (! dfu_boot()) load_the_TEZI_fitimage_from_eMMC(); boot_from_fitimage(); ... Signed-off-by: Max Krummenacher --- board/toradex/verdin-am62/verdin-am62.c | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/board/toradex/verdin-am62/verdin-am62.c b/board/toradex/verdin-am62/verdin-am62.c index 7116bd82bc..f1c0614e07 100644 --- a/board/toradex/verdin-am62/verdin-am62.c +++ b/board/toradex/verdin-am62/verdin-am62.c @@ -22,6 +22,15 @@ DECLARE_GLOBAL_DATA_PTR; +/* from 5.8 Boot Memory Maps */ +#define BOOT_PARAMETER_TABLE 0x43c3f298 +/* from 5.6.1 Common Header */ +#define BOOT_PARAMETER_PRIMARY_PERIPHERAL (*(u16 *)(BOOT_PARAMETER_TABLE + 0x04)) +#define BOOT_PARAMETER_SECONDARY_PERIPHERAL (*(u16 *)(BOOT_PARAMETER_TABLE + 0x204)) +#define BOOT_PARAMETER_EMMC 101 +#define BOOT_PARAMETER_SD 100 +#define BOOT_PARAMETER_USB_DFU 70 + #define PMIC_I2C_BUS 0x0 #define PMIC_I2C_ADDRESS 0x30 #define PMIC_BUCK1_VSET_850 0xa @@ -126,6 +135,42 @@ int ft_board_setup(void *blob, struct bd_info *bd) } #endif +#if !defined(CONFIG_SPL_BUILD) +/* Should check if we were booted over dfu, and if so go to DFU / UMS for download */ +void decide_on_dfu(void) +{ + /* + * SD boot with sdcard, 7000f290: 00000000 + * SD boot without sdcard, dfu, 7000f290: 00000001 + * eMMC Boot, eMMC flashed 7000f290: 00000000 + * eMMC Boot, eMMC zeroed 7000f290: 00000001 + * DFU Boot 7000f290: 00000000 + * + * If this Memory location will stay untouched in future versions is + * unknown, so the code might break. + * Compare with arch/arm/mach-k3/am625_init.c which however is SPL only + */ + u32 bootindex = *(u32 *)(CONFIG_SYS_K3_BOOT_PARAM_TABLE_INDEX); + u32 bootmode = bootindex & 1 ? BOOT_PARAMETER_SECONDARY_PERIPHERAL : + BOOT_PARAMETER_PRIMARY_PERIPHERAL; + + if (bootmode == BOOT_PARAMETER_USB_DFU) { + printf("DFU boot mode detected, going to DFU again for further downloads\n"); + env_set("bootcmd", "setenv dfu_alt_info $dfu_alt_info_emmc;" + "dfu 0 mmc 0; ums 0 mmc 0"); + } + + debug("Booting from %s boot device\n", bootindex & 1 ? "Secondary" : + "Primary"); + debug("Primary boot device as read from boot parameters %hd\n", + BOOT_PARAMETER_PRIMARY_PERIPHERAL); + debug("Secondary boot device as read from boot parameters %hd\n", + BOOT_PARAMETER_SECONDARY_PERIPHERAL); +} +#else +void decide_on_dfu(void) {} +#endif /* CONFIG_SPL_BUILD */ + static void select_dt_from_module_version(void) { char variant[32]; @@ -155,6 +200,9 @@ int board_late_init(void) { select_dt_from_module_version(); + /* set bootcmd to start DFU and then UMS mode if booted from DFU */ + decide_on_dfu(); + return 0; } -- cgit v1.2.3