[U-Boot] [PATCH v2 04/11] drivers:dfu: new feature: separated bootloader alt setting

Przemyslaw Marczak
2014-06-12T09:46:27Z

This patch introduces new feature: initialization of the dfu
bootloader entity from a separate environmental variable which
can be set on a boot time.

By default, DFU always check environmental variable: $dfu_alt_info.

Changes:
- DFU will also look for environmental variable: $dfu_alt_bootloader
- if any of dfu_alt_* variable is properly defined, then function
dfu_init_env_entities() will return success.

Use case:
Some devices can boot from various media type (SD, eMMC, NAND, etc.)
or some board configs are common for more than one board type.
In a such case, bootloader is probably placed on a different
devices or even offsets. So such DFU feature is welcome.

Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>

---
Changes v2:
- new commit
---
drivers/dfu/dfu.c | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c
index a938109..8848624 100644
--- a/drivers/dfu/dfu.c
+++ b/drivers/dfu/dfu.c
@@ -44,24 +44,32 @@ static int dfu_find_alt_num(const char *s)

int dfu_init_env_entities(char *interface, int dev)
{
+ const char *alt_info[] = {"dfu_alt_info", "dfu_alt_bootloader"};
const char *str_env;
char *env_bkp;
- int ret;
+ int ret, i;
+ int alt_init_cnt = 0;
+
+ for (i = 0; i < ARRAY_SIZE(alt_info); i++) {
+ str_env = getenv(alt_info[i]);
+ if (!str_env)
+ continue;

- str_env = getenv("dfu_alt_info");
- if (!str_env) {
- error("\"dfu_alt_info\" env variable not defined!\n");
- return -EINVAL;
+ env_bkp = strdup(str_env);
+ ret = dfu_config_entities(env_bkp, interface, dev);
+ free(env_bkp);
+
+ if (ret)
+ continue;
+
+ alt_init_cnt++;
}

- env_bkp = strdup(str_env);
- ret = dfu_config_entities(env_bkp, interface, dev);
- if (ret) {
+ if (!alt_init_cnt) {
error("DFU entities configuration failed!\n");
- return ret;
+ return -1;
}

- free(env_bkp);
return 0;
}

--
1.9.1