dfu: add DFU virtual backend

Add a virtual DFU backend to allow board specific read and write
(for OTP update for example).

Acked-by: Lukasz Majewski <lukma@denx.de>
Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
This commit is contained in:
Patrick Delaunay
2019-10-14 09:28:06 +02:00
committed by Marek Vasut
parent d5640f700d
commit ec44cace4b
6 changed files with 114 additions and 2 deletions

View File

@@ -60,5 +60,12 @@ config DFU_MTD
help
This option enables using DFU to read and write to on any MTD device.
config DFU_VIRT
bool "VIRTUAL flash back end for DFU"
help
This option enables using DFU to read and write to VIRTUAL device
used at board level to manage specific behavior
(OTP update for example).
endif
endmenu

View File

@@ -10,3 +10,4 @@ obj-$(CONFIG_$(SPL_)DFU_NAND) += dfu_nand.o
obj-$(CONFIG_$(SPL_)DFU_RAM) += dfu_ram.o
obj-$(CONFIG_$(SPL_)DFU_SF) += dfu_sf.o
obj-$(CONFIG_$(SPL_)DFU_TFTP) += dfu_tftp.o
obj-$(CONFIG_$(SPL_)DFU_VIRT) += dfu_virt.o

View File

@@ -474,6 +474,9 @@ static int dfu_fill_entity(struct dfu_entity *dfu, char *s, int alt,
} else if (strcmp(interface, "sf") == 0) {
if (dfu_fill_entity_sf(dfu, devstr, s))
return -1;
} else if (strcmp(interface, "virt") == 0) {
if (dfu_fill_entity_virt(dfu, devstr, s))
return -1;
} else {
printf("%s: Device %s not (yet) supported!\n",
__func__, interface);
@@ -569,7 +572,7 @@ int dfu_config_entities(char *env, char *interface, char *devstr)
const char *dfu_get_dev_type(enum dfu_device_type t)
{
const char *const dev_t[] = {NULL, "eMMC", "OneNAND", "NAND", "RAM",
"SF", "MTD"};
"SF", "MTD", "VIRT"};
return dev_t[t];
}

49
drivers/dfu/dfu_virt.c Normal file
View File

@@ -0,0 +1,49 @@
// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
/*
* Copyright (C) 2019, STMicroelectronics - All Rights Reserved
*/
#include <common.h>
#include <dfu.h>
#include <errno.h>
#include <malloc.h>
int __weak dfu_write_medium_virt(struct dfu_entity *dfu, u64 offset,
void *buf, long *len)
{
debug("%s: off=0x%llx, len=0x%x\n", __func__, offset, (u32)*len);
return 0;
}
int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size)
{
*size = 0;
return 0;
}
int __weak dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset,
void *buf, long *len)
{
debug("%s: off=0x%llx, len=0x%x\n", __func__, offset, (u32)*len);
*len = 0;
return 0;
}
int dfu_fill_entity_virt(struct dfu_entity *dfu, char *devstr, char *s)
{
debug("%s: devstr = %s\n", __func__, devstr);
dfu->dev_type = DFU_DEV_VIRT;
dfu->layout = DFU_RAW_ADDR;
dfu->data.virt.dev_num = simple_strtoul(devstr, NULL, 10);
dfu->write_medium = dfu_write_medium_virt;
dfu->get_medium_size = dfu_get_medium_size_virt;
dfu->read_medium = dfu_read_medium_virt;
dfu->inited = 0;
return 0;
}