mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-14 08:57:58 +00:00
fc18f8d170
This patch fixes situation when one would like to write large file into medium with the file system (fat, ext4, etc). This change sets file size limitation to the DFU internal buffer size. Since u-boot is not supporting interrupts and seek on file systems, it becomes challenging to store large file appropriately. To reproduce this error - create large file (around 26 MiB) and sent it to the target board. Lets examine the flow of USB transactions: 0. DFU uses EP0 with 64B MPS [Max Packet Size] 1. Send file - OUT (PC->target) - dat_26MiB.img is sent with 4096 B transactions 2. Get status - OUT (PC->target) - wait for DFU_STATE_dfuDNLOAD_IDLE (0x05) sent from target board - IN transaction (target->PC) 3. The whole file content is sent to target - OUT (PC->target) with ZLP [Zero Length Packet] Now the interesting part starts: 4. OUT (PC->target) Setup transaction (request to share DFU state) 5. IN (target->PC) - reply the current DFU state - In the UDC driver the req->completion (with dfu_flush) is called after successful IN transfer. - The dfu_flush() (called from req->completion callback) saves the whole file at once (u-boot doesn't support seek on fs). Such operation takes considerable time. When the file is large - e.g. 26MiB - this time may be more than 5 seconds. 6. OUT (PC->target) - ZLP, is send in the same time when dfu_flush() writes data to eMMC memory. The dfu-util application has hard coded timeout on USB transaction completion set to 5 seconds (it uses libusb calls). When the file to store is large (e.g. 26 MiB) the time needed to write it may excess the dfu-util timeout and following error message will be displayed: "unable to read DFU status" on the HOST PC console. This change is supposed to leverage DFU's part responsible for storing files on file systems. Other DFU operations - i.e. raw/partition write to NAND and eMMC should work as before. The only functional change is the error reporting. When dfu_flush() fails the u-boot prompt will exit with error information and dfu-util application exits afterwards as well. Test HW: - Odroid XU3 (Exynos5433) - test with large file - Trats (Exynos4210) - test for regression - eMMC, raw, Signed-off-by: Lukasz Majewski <l.majewski@samsung.com> Reported-by: Alex Gdalevich <agdalevich@axion-biosystems.com> Tested-by: Stephen Warren <swarren@nvidia.com> Tested-by: Heiko Schocher <hs@denx.de>
133 lines
3.1 KiB
C
133 lines
3.1 KiB
C
/*
|
|
* cmd_dfu.c -- dfu command
|
|
*
|
|
* Copyright (C) 2015
|
|
* Lukasz Majewski <l.majewski@majess.pl>
|
|
*
|
|
* Copyright (C) 2012 Samsung Electronics
|
|
* authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
|
|
* Lukasz Majewski <l.majewski@samsung.com>
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <watchdog.h>
|
|
#include <dfu.h>
|
|
#include <console.h>
|
|
#include <g_dnl.h>
|
|
#include <usb.h>
|
|
#include <net.h>
|
|
|
|
static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|
{
|
|
bool dfu_reset = false;
|
|
|
|
if (argc < 4)
|
|
return CMD_RET_USAGE;
|
|
|
|
char *usb_controller = argv[1];
|
|
char *interface = argv[2];
|
|
char *devstring = argv[3];
|
|
|
|
int ret, i = 0;
|
|
#ifdef CONFIG_DFU_TFTP
|
|
unsigned long addr = 0;
|
|
if (!strcmp(argv[1], "tftp")) {
|
|
if (argc == 5)
|
|
addr = simple_strtoul(argv[4], NULL, 0);
|
|
|
|
return update_tftp(addr, interface, devstring);
|
|
}
|
|
#endif
|
|
|
|
ret = dfu_init_env_entities(interface, devstring);
|
|
if (ret)
|
|
goto done;
|
|
|
|
ret = CMD_RET_SUCCESS;
|
|
if (argc > 4 && strcmp(argv[4], "list") == 0) {
|
|
dfu_show_entities();
|
|
goto done;
|
|
}
|
|
|
|
int controller_index = simple_strtoul(usb_controller, NULL, 0);
|
|
board_usb_init(controller_index, USB_INIT_DEVICE);
|
|
g_dnl_clear_detach();
|
|
g_dnl_register("usb_dnl_dfu");
|
|
while (1) {
|
|
if (g_dnl_detach()) {
|
|
/*
|
|
* Check if USB bus reset is performed after detach,
|
|
* which indicates that -R switch has been passed to
|
|
* dfu-util. In this case reboot the device
|
|
*/
|
|
if (dfu_usb_get_reset()) {
|
|
dfu_reset = true;
|
|
goto exit;
|
|
}
|
|
|
|
/*
|
|
* This extra number of usb_gadget_handle_interrupts()
|
|
* calls is necessary to assure correct transmission
|
|
* completion with dfu-util
|
|
*/
|
|
if (++i == 10000)
|
|
goto exit;
|
|
}
|
|
|
|
if (ctrlc())
|
|
goto exit;
|
|
|
|
if (dfu_get_defer_flush()) {
|
|
/*
|
|
* Call to usb_gadget_handle_interrupts() is necessary
|
|
* to act on ZLP OUT transaction from HOST PC after
|
|
* transmitting the whole file.
|
|
*
|
|
* If this ZLP OUT packet is NAK'ed, the HOST libusb
|
|
* function fails after timeout (by default it is set to
|
|
* 5 seconds). In such situation the dfu-util program
|
|
* exits with error message.
|
|
*/
|
|
usb_gadget_handle_interrupts(controller_index);
|
|
ret = dfu_flush(dfu_get_defer_flush(), NULL, 0, 0);
|
|
dfu_set_defer_flush(NULL);
|
|
if (ret) {
|
|
error("Deferred dfu_flush() failed!");
|
|
goto exit;
|
|
}
|
|
}
|
|
|
|
WATCHDOG_RESET();
|
|
usb_gadget_handle_interrupts(controller_index);
|
|
}
|
|
exit:
|
|
g_dnl_unregister();
|
|
board_usb_cleanup(controller_index, USB_INIT_DEVICE);
|
|
done:
|
|
dfu_free_entities();
|
|
|
|
if (dfu_reset)
|
|
run_command("reset", 0);
|
|
|
|
g_dnl_clear_detach();
|
|
|
|
return ret;
|
|
}
|
|
|
|
U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
|
|
"Device Firmware Upgrade",
|
|
"<USB_controller> <interface> <dev> [list]\n"
|
|
" - device firmware upgrade via <USB_controller>\n"
|
|
" on device <dev>, attached to interface\n"
|
|
" <interface>\n"
|
|
" [list] - list available alt settings\n"
|
|
#ifdef CONFIG_DFU_TFTP
|
|
"dfu tftp <interface> <dev> [<addr>]\n"
|
|
" - device firmware upgrade via TFTP\n"
|
|
" on device <dev>, attached to interface\n"
|
|
" <interface>\n"
|
|
" [<addr>] - address where FIT image has been stored\n"
|
|
#endif
|
|
);
|