board: ti: common: Add support for dynamic dfu_alt_info
Add support for setting dfu_alt_info environment variable dynamically for SPI flash devices, the dfu_alt_info is populated from existing mtd partitions, there is no modification made to the environment variable if it already is defined. Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
This commit is contained in:
parent
11ca97f710
commit
63d23445ab
|
|
@ -3,3 +3,4 @@
|
||||||
|
|
||||||
obj-${CONFIG_TI_I2C_BOARD_DETECT} += board_detect.o
|
obj-${CONFIG_TI_I2C_BOARD_DETECT} += board_detect.o
|
||||||
obj-${CONFIG_CMD_EXTENSION} += cape_detect.o
|
obj-${CONFIG_CMD_EXTENSION} += cape_detect.o
|
||||||
|
obj-$(CONFIG_SET_DFU_ALT_INFO) += k3_dfu.o
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,77 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0+
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2023, Texas Instruments Incorporated - https://www.ti.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <common.h>
|
||||||
|
#include <blk.h>
|
||||||
|
#include <dm.h>
|
||||||
|
#include <dfu.h>
|
||||||
|
#include <env.h>
|
||||||
|
#include <memalign.h>
|
||||||
|
#include <misc.h>
|
||||||
|
#include <mtd.h>
|
||||||
|
#include <mtd_node.h>
|
||||||
|
|
||||||
|
#define DFU_ALT_BUF_LEN 512
|
||||||
|
|
||||||
|
static void board_get_alt_info_sf(struct mtd_info *mtd, char *buf)
|
||||||
|
{
|
||||||
|
struct mtd_info *part;
|
||||||
|
bool first = true;
|
||||||
|
const char *name;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
name = mtd->name;
|
||||||
|
len = strlen(buf);
|
||||||
|
|
||||||
|
list_for_each_entry(part, &mtd->partitions, node) {
|
||||||
|
if (!first)
|
||||||
|
len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, "; ");
|
||||||
|
first = false;
|
||||||
|
len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
|
||||||
|
"%s raw %llx %llx", part->name, part->offset, part->size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_dfu_alt_info(char *interface, char *devstr)
|
||||||
|
{
|
||||||
|
struct udevice *dev;
|
||||||
|
struct mtd_info *mtd;
|
||||||
|
char *st, *devstr_bkup;
|
||||||
|
unsigned int bus;
|
||||||
|
|
||||||
|
ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN);
|
||||||
|
|
||||||
|
if (env_get("dfu_alt_info"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
memset(buf, 0, sizeof(buf));
|
||||||
|
|
||||||
|
if (!strcmp(interface, "sf")) {
|
||||||
|
devstr_bkup = strdup(devstr);
|
||||||
|
st = strsep(&devstr_bkup, ":");
|
||||||
|
if (!st || !*st) {
|
||||||
|
printf("Invalid SPI bus %s\n", st);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
bus = simple_strtoul(st, NULL, 0);
|
||||||
|
|
||||||
|
if (uclass_get_device(UCLASS_SPI_FLASH, bus, &dev)) {
|
||||||
|
printf("Failed to get device on bus %d\n", bus);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (CONFIG_IS_ENABLED(MTD)) {
|
||||||
|
mtd_probe_devices();
|
||||||
|
mtd_for_each_device(mtd) {
|
||||||
|
if (!mtd_is_partition(mtd) && mtd->dev && dev == mtd->dev)
|
||||||
|
board_get_alt_info_sf(mtd, buf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("dynamic dfu_alt_info supported only for sf\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
env_set("dfu_alt_info", buf);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue