mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-30 11:01:33 +00:00
Support an U-Boot script included in uimage instead of flashlayout file (text file in tsv format). This feature is used to execute this script directly when U-Boot is loaded in DDR (for update without STM32CubeProgrammer for example). A simple example with dfu-util only is: $> echo "dfu 0" > script.cmd $> mkimage -C none -A arm -T script -d script.cmd script.uimg $> mkimage -T stm32image -a 0xC0000000 -e 0xC0000000 -d script.uimg \ script.stm32 $> dfu-util -d 0483:df11 -a 1 -D tf-a.stm32 $> dfu-util -d 0483:df11 -a 0 -D script.stm32 $> dfu-util -d 0483:df11 -a 0 -D u-boot.stm32 $> dfu-util -d 0483:df11 -a 0 -e Then you can used dfu-utils to update your device To increase speed, you can also switch to fastboot protocol with: echo "fastboot 0" > script.cmd Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com> Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
164 lines
3.4 KiB
C
164 lines
3.4 KiB
C
// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
|
|
/*
|
|
* Copyright (C) 2020, STMicroelectronics - All Rights Reserved
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <command.h>
|
|
#include <dfu.h>
|
|
#include <image.h>
|
|
#include <asm/arch/stm32prog.h>
|
|
#include "stm32prog.h"
|
|
|
|
struct stm32prog_data *stm32prog_data;
|
|
|
|
static void enable_vidconsole(void)
|
|
{
|
|
#ifdef CONFIG_DM_VIDEO
|
|
char *stdname;
|
|
char buf[64];
|
|
|
|
stdname = env_get("stdout");
|
|
if (!stdname || !strstr(stdname, "vidconsole")) {
|
|
if (!stdname)
|
|
snprintf(buf, sizeof(buf), "serial,vidconsole");
|
|
else
|
|
snprintf(buf, sizeof(buf), "%s,vidconsole", stdname);
|
|
env_set("stdout", buf);
|
|
}
|
|
|
|
stdname = env_get("stderr");
|
|
if (!stdname || !strstr(stdname, "vidconsole")) {
|
|
if (!stdname)
|
|
snprintf(buf, sizeof(buf), "serial,vidconsole");
|
|
else
|
|
snprintf(buf, sizeof(buf), "%s,vidconsole", stdname);
|
|
env_set("stderr", buf);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
static int do_stm32prog(cmd_tbl_t *cmdtp, int flag, int argc,
|
|
char * const argv[])
|
|
{
|
|
ulong addr, size;
|
|
int dev, ret;
|
|
enum stm32prog_link_t link = LINK_UNDEFINED;
|
|
bool reset = false;
|
|
struct image_header_s header;
|
|
struct stm32prog_data *data;
|
|
|
|
if (argc < 3 || argc > 5)
|
|
return CMD_RET_USAGE;
|
|
|
|
if (!strcmp(argv[1], "usb"))
|
|
link = LINK_USB;
|
|
else if (!strcmp(argv[1], "serial"))
|
|
link = LINK_SERIAL;
|
|
|
|
if (link == LINK_UNDEFINED) {
|
|
pr_err("not supported link=%s\n", argv[1]);
|
|
return CMD_RET_USAGE;
|
|
}
|
|
|
|
dev = (int)simple_strtoul(argv[2], NULL, 10);
|
|
|
|
addr = STM32_DDR_BASE;
|
|
size = 0;
|
|
if (argc > 3) {
|
|
addr = simple_strtoul(argv[3], NULL, 16);
|
|
if (!addr)
|
|
return CMD_RET_FAILURE;
|
|
}
|
|
if (argc > 4)
|
|
size = simple_strtoul(argv[4], NULL, 16);
|
|
|
|
/* check STM32IMAGE presence */
|
|
if (size == 0 &&
|
|
!stm32prog_header_check((struct raw_header_s *)addr, &header)) {
|
|
size = header.image_length + BL_HEADER_SIZE;
|
|
|
|
/* uImage detected in STM32IMAGE, execute the script */
|
|
if (IMAGE_FORMAT_LEGACY ==
|
|
genimg_get_format((void *)(addr + BL_HEADER_SIZE)))
|
|
return image_source_script(addr + BL_HEADER_SIZE,
|
|
"script@1");
|
|
}
|
|
|
|
enable_vidconsole();
|
|
|
|
data = (struct stm32prog_data *)malloc(sizeof(*data));
|
|
|
|
if (!data) {
|
|
pr_err("Alloc failed.");
|
|
return CMD_RET_FAILURE;
|
|
}
|
|
stm32prog_data = data;
|
|
|
|
ret = stm32prog_init(data, addr, size);
|
|
if (ret)
|
|
printf("Invalid or missing layout file.");
|
|
|
|
/* prepare DFU for device read/write */
|
|
ret = stm32prog_dfu_init(data);
|
|
if (ret)
|
|
goto cleanup;
|
|
|
|
switch (link) {
|
|
case LINK_SERIAL:
|
|
ret = stm32prog_serial_init(data, dev);
|
|
if (ret)
|
|
goto cleanup;
|
|
reset = stm32prog_serial_loop(data);
|
|
break;
|
|
case LINK_USB:
|
|
reset = stm32prog_usb_loop(data, dev);
|
|
break;
|
|
default:
|
|
goto cleanup;
|
|
}
|
|
|
|
stm32prog_clean(data);
|
|
free(stm32prog_data);
|
|
stm32prog_data = NULL;
|
|
|
|
puts("Download done\n");
|
|
if (reset) {
|
|
puts("Reset...\n");
|
|
run_command("reset", 0);
|
|
}
|
|
|
|
return CMD_RET_SUCCESS;
|
|
|
|
cleanup:
|
|
stm32prog_clean(data);
|
|
free(stm32prog_data);
|
|
stm32prog_data = NULL;
|
|
|
|
return CMD_RET_FAILURE;
|
|
}
|
|
|
|
U_BOOT_CMD(stm32prog, 5, 0, do_stm32prog,
|
|
"<link> <dev> [<addr>] [<size>]\n"
|
|
"start communication with tools STM32Cubeprogrammer on <link> with Flashlayout at <addr>",
|
|
"<link> = serial|usb\n"
|
|
"<dev> = device instance\n"
|
|
"<addr> = address of flashlayout\n"
|
|
"<size> = size of flashlayout\n"
|
|
);
|
|
|
|
bool stm32prog_get_tee_partitions(void)
|
|
{
|
|
if (stm32prog_data)
|
|
return stm32prog_data->tee_detected;
|
|
|
|
return false;
|
|
}
|
|
|
|
bool stm32prog_get_fsbl_nor(void)
|
|
{
|
|
if (stm32prog_data)
|
|
return stm32prog_data->fsbl_nor_detected;
|
|
|
|
return false;
|
|
}
|