[PATCH 3/5] dfu: add 'SCRIPT' entity
Marek Szyprowski
m.szyprowski at samsung.com
Thu Dec 17 13:10:28 CET 2020
Define a new 'SCRIPT' type for DFU entities. The downloaded data are
treated as simple u-boot's scripts and executed with run_command_list()
function.
Flashing the 'SCRIPT' entity might result in changing the 'dfu_alt_info'
environment variable from the flashed script, so add a global variable
for tracking the potential need to reinitialize the dfu_alt_info related
structures.
Signed-off-by: Marek Szyprowski <m.szyprowski at samsung.com>
---
drivers/dfu/dfu.c | 6 +++++-
drivers/dfu/dfu_mmc.c | 23 +++++++++++++++++++++--
include/dfu.h | 3 +++
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
index fc32a53323..eccfb4c745 100644
--- a/drivers/dfu/dfu.c
+++ b/drivers/dfu/dfu.c
@@ -26,6 +26,8 @@ static struct hash_algo *dfu_hash_algo;
static unsigned long dfu_timeout = 0;
#endif
+bool dfu_reinit_needed = false;
+
/*
* The purpose of the dfu_flush_callback() function is to
* provide callback for dfu user
@@ -139,6 +141,8 @@ int dfu_init_env_entities(char *interface, char *devstr)
char *env_bkp;
int ret = 0;
+ dfu_reinit_needed = false;
+
#ifdef CONFIG_SET_DFU_ALT_INFO
set_dfu_alt_info(interface, devstr);
#endif
@@ -614,7 +618,7 @@ const char *dfu_get_dev_type(enum dfu_device_type t)
const char *dfu_get_layout(enum dfu_layout l)
{
const char *const dfu_layout[] = {NULL, "RAW_ADDR", "FAT", "EXT2",
- "EXT3", "EXT4", "RAM_ADDR", "SKIP" };
+ "EXT3", "EXT4", "RAM_ADDR", "SKIP", "SCRIPT" };
return dfu_layout[l];
}
diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c
index d1af11d94c..e63fa84ce4 100644
--- a/drivers/dfu/dfu_mmc.c
+++ b/drivers/dfu/dfu_mmc.c
@@ -16,6 +16,7 @@
#include <fat.h>
#include <mmc.h>
#include <part.h>
+#include <command.h>
static unsigned char *dfu_file_buf;
static u64 dfu_file_buf_len;
@@ -206,6 +207,9 @@ int dfu_write_medium_mmc(struct dfu_entity *dfu,
case DFU_FS_EXT4:
ret = mmc_file_buf_write(dfu, offset, buf, len);
break;
+ case DFU_SCRIPT:
+ ret = run_command_list(buf, *len, 0);
+ break;
case DFU_SKIP:
ret = 0;
break;
@@ -221,9 +225,21 @@ int dfu_flush_medium_mmc(struct dfu_entity *dfu)
{
int ret = 0;
- if (dfu->layout != DFU_RAW_ADDR) {
- /* Do stuff here. */
+ switch (dfu->layout) {
+ case DFU_FS_FAT:
+ case DFU_FS_EXT4:
ret = mmc_file_buf_write_finish(dfu);
+ break;
+ case DFU_SCRIPT:
+ /* script may have changed the dfu_alt_info */
+ dfu_reinit_needed = true;
+ break;
+ case DFU_RAW_ADDR:
+ case DFU_SKIP:
+ break;
+ default:
+ printf("%s: Layout (%s) not (yet) supported!\n", __func__,
+ dfu_get_layout(dfu->layout));
}
return ret;
@@ -243,6 +259,7 @@ int dfu_get_medium_size_mmc(struct dfu_entity *dfu, u64 *size)
if (ret < 0)
return ret;
return 0;
+ case DFU_SCRIPT:
case DFU_SKIP:
return 0;
default:
@@ -408,6 +425,8 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *devstr, char *s)
dfu->layout = DFU_FS_EXT4;
} else if (!strcmp(entity_type, "skip")) {
dfu->layout = DFU_SKIP;
+ } else if (!strcmp(entity_type, "script")) {
+ dfu->layout = DFU_SCRIPT;
} else {
pr_err("Memory layout (%s) not supported!\n", entity_type);
return -ENODEV;
diff --git a/include/dfu.h b/include/dfu.h
index 0b1dae0b3b..d18b701728 100644
--- a/include/dfu.h
+++ b/include/dfu.h
@@ -34,6 +34,7 @@ enum dfu_layout {
DFU_FS_EXT4,
DFU_RAM_ADDR,
DFU_SKIP,
+ DFU_SCRIPT,
};
enum dfu_op {
@@ -497,6 +498,8 @@ static inline int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr,
}
#endif
+extern bool dfu_reinit_needed;
+
#if CONFIG_IS_ENABLED(DFU_WRITE_ALT)
/**
* dfu_write_by_name() - write data to DFU medium
--
2.17.1
More information about the U-Boot
mailing list