From 87e9ccb4af04f157bb12361b4fcf53654460a5d6 Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Fri, 15 May 2020 09:45:41 +0200 Subject: [PATCH] cmd: remote obsoleted nfsdown and usbdown commands Gneric Tizen Downloader based on the DFU framework, provides better replacement for those commands. Signed-off-by: Marek Szyprowski Change-Id: Ia0a0ccd5fb7e1b65c12f6c5653015ef7ae05e6be --- cmd/Kconfig | 19 +- cmd/Makefile | 2 - cmd/net.c | 2 +- cmd/nfsdown.c | 482 ----------------------------------------- cmd/usbdown.c | 583 -------------------------------------------------- 5 files changed, 2 insertions(+), 1086 deletions(-) delete mode 100644 cmd/nfsdown.c delete mode 100644 cmd/usbdown.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 40095e1357..7bef85ba85 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1216,11 +1216,6 @@ config CMD_USB help USB support. -config CMD_USBDOWN - bool "usbdown" - help - USB stroage download support for tizen - config CMD_USB_SDP bool "sdp" select USB_FUNCTION_SDP @@ -1247,7 +1242,7 @@ config CMD_TIZEN_DOWNLOAD bool "Tizen Downloader (NFS & USB)" select DFU select CMD_NFS - depends on NET && !CMD_NFS_DOWNLOAD && !CMD_USB_DOWNLOAD + depends on NET help Generic DFU based system image downloader for Tizen project. Supports NFS and USB download: nfsdown and usbdown commands. @@ -1502,18 +1497,6 @@ config CMD_LINK_LOCAL help Acquire a network IP address using the link-local protocol -config CMD_NFS_DOWNLOAD - bool "nfsdown" - help - Support the NFS download for tizen Odroid XU3/4 - -config CMD_NFS_READ_SIZE - int "Set the read packet size with nfs" - depends on CMD_NFS_DOWNLOAD - default 65536 - help - Use the read size of packet when nfsdown command is used - endif config CMD_ETHSW diff --git a/cmd/Makefile b/cmd/Makefile index 37bd656313..4928d5b5ed 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -147,7 +147,6 @@ obj-$(CONFIG_CMD_WDT) += wdt.o obj-$(CONFIG_CMD_LZMADEC) += lzmadec.o obj-$(CONFIG_CMD_USB) += usb.o disk.o -obj-$(CONFIG_CMD_USBDOWN) += usbdown.o obj-$(CONFIG_CMD_FASTBOOT) += fastboot.o obj-$(CONFIG_CMD_FS_UUID) += fs_uuid.o @@ -155,7 +154,6 @@ obj-$(CONFIG_CMD_USB_MASS_STORAGE) += usb_mass_storage.o obj-$(CONFIG_CMD_USB_SDP) += usb_gadget_sdp.o obj-$(CONFIG_CMD_THOR_DOWNLOAD) += thordown.o obj-$(CONFIG_CMD_TIZEN_DOWNLOAD) += tizendown.o -obj-$(CONFIG_CMD_NFS_DOWNLOAD) += nfsdown.o obj-$(CONFIG_CMD_XIMG) += ximg.o obj-$(CONFIG_CMD_YAFFS2) += yaffs2.o obj-$(CONFIG_CMD_SPL) += spl.o diff --git a/cmd/net.c b/cmd/net.c index 4d7e14143c..5880bd3b0a 100644 --- a/cmd/net.c +++ b/cmd/net.c @@ -274,7 +274,7 @@ static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc, return rcode; } -#if defined(CONFIG_CMD_TIZEN_DOWNLOAD) || defined(CONFIG_CMD_NFS_DOWNLOAD) +#if defined(CONFIG_CMD_TIZEN_DOWNLOAD) int netboot_nfs(unsigned long addr, const char *filename, unsigned long offset, unsigned long limit) { diff --git a/cmd/nfsdown.c b/cmd/nfsdown.c deleted file mode 100644 index 35ccf3d12f..0000000000 --- a/cmd/nfsdown.c +++ /dev/null @@ -1,482 +0,0 @@ -/* - * cmd_nfsdown.c -- Tizen "nfs" Downloader - * - * Copyright (C) 2017 Jiho Chu - * All rights reserved. - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define LEN_BUF 128 -#define LEN_NAME 32 - -#ifdef CONFIG_SYS_SDRAM_BASE -#define NFS_DOWNLOAD_ADDR CONFIG_SYS_SDRAM_BASE -#else -#define NFS_DOWNLOAD_ADDR 0x40000000 -#endif - -#define NFSDOWN_TRANSFER_SIZE SZ_256M - -enum img_layout { - RAW_ADDR, - FS_FAT, -}; - -struct img_info { - char name[LEN_NAME]; - enum img_layout layout; - - /* mmc info */ - uint hwpart; - uint part; - - /* block info */ - uint lba_start; - uint lba_size; - uint lba_blk_size; - - struct list_head list; -}; - -struct img_comp { - char name[LEN_NAME]; - uint size; - - struct list_head list; -}; - -#if defined(CONFIG_TARGET_RPI_3) || \ - defined(CONFIG_TARGET_RPI_4) || \ - defined(CONFIG_TARGET_RPI_3_32B) || \ - defined(CONFIG_TARGET_RPI_4_32B) -static char *g_update_image_names[] = { - "boot.img", - "rootfs.img", - "system-data.img", - "user.img", - "modules.img", - "ramdisk.img", - "ramdisk-recovery.img" -}; -#else -static char *g_update_image_names[] = { - "bl1.bin", - "bl2.bin", - "u-boot-mmc.bin", - "tzsw.bin", - "params.bin", - "boot.img", - "rootfs.img", - "system-data.img", - "user.img", - "modules.img", - "ramdisk.img" -}; -#endif - -#if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_HOST_ETHER) && !defined(CONFIG_DM_ETH) -extern char usb_started; - -static void do_usb_ether_start(void) -{ - bootstage_mark_name(BOOTSTAGE_ID_USB_START, "usb_start"); - if (usb_init() < 0) - return; - - bootstage_mark_name(BOOTSTAGE_ID_ETH_START, "eth_start"); - usb_host_eth_scan(1); -} -#endif - -#ifdef CONFIG_SET_DFU_ALT_INFO -#ifdef CONFIG_SET_DFU_ALT_BUF_LEN -#define DFU_ALT_BUF_LEN CONFIG_SET_DFU_ALT_BUF_LEN -#else -#define DFU_ALT_BUF_LEN (SZ_1K) -#endif - -static void set_dfu_alt_info(void) -{ - int buf_used; - ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); - - buf_used = snprintf(buf, DFU_ALT_BUF_LEN, "%s", - CONFIG_DFU_ALT_BOOT_EMMC); - - buf_used += snprintf(buf + buf_used, DFU_ALT_BUF_LEN, "%s%s", - buf_used ? ";" : "", CONFIG_DFU_ALT_SYSTEM); - - if (buf_used <= 0) - return; - - env_set("dfu_alt_info", buf); - - return; -} - -#else /* CONFIG_SET_DFU_ALT_INFO */ - -static void set_dfu_alt_info(void) -{ - return; -} - -#endif /* CONFIG_SET_DFU_ALT_INFO */ - -static int do_mmc_init(struct mmc **mmc) -{ - int ret; - - *mmc = find_mmc_device(0); - if (!*mmc) { - printk("Couldn't find MMC device no. 0.\n"); - return -ENODEV; - } - - ret = mmc_init(*mmc); - if (ret) { - printk("Couldn't init MMC device.\n"); - return ret; - } - - return 0; -} - -static int find_mmc_partition_info(struct mmc *mmc, uint hwpart, uint part, - disk_partition_t *partinfo) -{ - int ret; - - if (!mmc) - return -ENODEV; - - ret = blk_select_hwpart_devnum(IF_TYPE_MMC, 0, hwpart); - if (ret) - return ret; - -#ifndef CONFIG_BLK - ret = part_get_info(&mmc->block_dev, part, partinfo); -#else - ret = part_get_info(mmc_get_blk_desc(mmc), part, partinfo); -#endif - if (ret) { - printk("Couldn't find part #%d on mmc device #%d\n", - part, hwpart); - return ret; - } - - return 0; -} - -static struct img_info *create_img_info(struct mmc *mmc, char *str_info) -{ - struct img_info *info; - char *tok[6]; - int i; - int ret; - - info = calloc(1, sizeof(struct img_info)); - if (!info) { - printk("Cannot malloc!!\n"); - return NULL; - } - - for (i = 0; i < 6; i++) - tok[i] = strsep(&str_info, " \t"); - - if (strlen(tok[0]) >= LEN_NAME - 1) { - printk("img name is too long: %s\n", tok[0]); - goto create_img_err; - } - - for (i = 0; i < sizeof(g_update_image_names) / sizeof(char *); i++) - if (!strncmp(tok[0], g_update_image_names[i], strlen(tok[0]))) - sprintf(info->name, "%s", g_update_image_names[i]); - - if (!info->name[0]) - goto create_img_err; - - if (!strncmp(tok[1], "raw", 3)) { - info->layout = RAW_ADDR; - info->lba_start = simple_strtoul(tok[2], NULL, 0); - info->lba_size = simple_strtoul(tok[3], NULL, 0); - info->lba_blk_size = 512; - - if (tok[4] && !strncmp(tok[4], "mmcpart", 7)) - info->hwpart = simple_strtoul(tok[5], NULL, 0); - else - info->hwpart = 1; - } else if (!strncmp(tok[1], "part", 4)) { - disk_partition_t partinfo; - uint offset = 0; - - info->layout = RAW_ADDR; - info->hwpart = simple_strtoul(tok[2], NULL, 0); - info->part = simple_strtoul(tok[3], NULL, 0); - - ret = find_mmc_partition_info(mmc, info->hwpart, info->part, - &partinfo); - if (ret) { - printk("Cannot get partition info: %d\n", info->hwpart); - goto create_img_err; - } - - if (tok[4] && !strcmp(tok[4], "offset")) - offset = simple_strtoul(tok[5], NULL, 0); - - info->lba_start = partinfo.start + offset; - info->lba_size = partinfo.size - offset; - info->lba_blk_size = partinfo.blksz; - } else if (!strncmp(tok[1], "fat", 3)) { - info->layout = FS_FAT; - info->hwpart = simple_strtoul(tok[2], NULL, 0); - info->part = simple_strtoul(tok[3], NULL, 0); - } else { - printk("Unrecognized img type: %s", tok[0]); - goto create_img_err; - } - - return info; - -create_img_err: - free(info); - - return NULL; -} - -struct img_comp *create_img_comp(const char *name, uint size) -{ - struct img_comp *comp; - - comp = malloc(sizeof(struct img_comp)); - if (!comp) { - printk("Failed to alloc\n"); - return NULL; - } - - strncpy(comp->name, name, LEN_NAME); - comp->size = size; - - return comp; -} - -/** - * Donwload from nfs file and write to mmc stroage - * - * @param addr Download buffer address from NFS - * @param file_path Download file path from NFS - * @param part MMC partition - * @param offset img block offset - * @param size img block size - * @param blk_size MMC block size - * @return file_size written file size, return -1 if error occurs - */ -static int do_nfs_to_mmc(struct mmc *mmc, unsigned long addr, char *file_path, - uint part, uint offset, uint size, uint blk_size) -{ - uint _size; - uint done = 0; - int ret; - - ret = blk_select_hwpart_devnum(IF_TYPE_MMC, 0, part); - if (ret) { - printk("Couldn't change to hwpart: %d\n", part); - return -1; - } - - do { - printf("Getting %s, offset %u...\n", file_path, done); - ret = netboot_nfs((unsigned long)addr, file_path, done, - NFSDOWN_TRANSFER_SIZE); - if (ret != CMD_RET_SUCCESS) { - puts("nfs download failed!!\n"); - return -1; - } - - _size = (net_boot_file_size % blk_size) ? - net_boot_file_size / blk_size + 1 - : net_boot_file_size / blk_size; - - printf("MMC write: dev # %d, block # %d, count %d ...\n\n", - part, offset, _size); -#ifndef CONFIG_BLK - ret = mmc->block_dev.block_write(&mmc->block_dev, offset, _size, - addr); -#else - ret = blk_dwrite(mmc_get_blk_desc(mmc), offset, _size, - (void *)addr); -#endif - if (ret != _size) { - printk("Failed to write MMC: part(%d), start(%d), size(%d)", - part, offset, _size); - return -1; - } - done += net_boot_file_size; - offset += _size; - } while (net_boot_file_size == NFSDOWN_TRANSFER_SIZE); - - return (int)done; -} - -static int do_nfs_to_fat(unsigned long addr, char *file_path, char *file_name, - uint dev, uint part) -{ - uint _size; - int ret; - char buf[256]; - - ret = netboot_nfs((unsigned long)addr, file_path, 0, 0); - if (ret != CMD_RET_SUCCESS) { - puts("nfs download failed!!\n"); - return -1; - } - - _size = net_boot_file_size; - snprintf(buf, 256, "fatwrite mmc %d:%d %lx %s %x", dev, part, addr, - file_name, _size); - run_command(buf, 0); - - return _size; -} - -int do_nfs_down(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) -{ - char *nfs_path; - char *tmp, *buf; - char *line; - char src_path[LEN_BUF]; - const char *file_name = NULL; - int size; - int ret; - - struct img_info *info, *tmp_info; - struct img_comp *comp, *tmp_comp; - struct mmc *mmc; - - LIST_HEAD(img_info_list); - LIST_HEAD(img_comp_list); - - puts("TIZEN \"nfs\" Downloader\n"); - - switch (argc) { - case 2: - nfs_path = argv[1]; - break; - case 3: - nfs_path = argv[1]; - file_name = argv[2]; - break; - default: - return CMD_RET_USAGE; - } - - INIT_LIST_HEAD(&img_info_list); - INIT_LIST_HEAD(&img_comp_list); - - set_dfu_alt_info(); - - tmp = env_get("dfu_alt_info"); - if (!tmp) { - puts("No Default dfu_alt_info\n"); - return CMD_RET_FAILURE; - } - - buf = strdup(tmp); - if (!buf) { - puts("fail to parse dfu_alt_info\n"); - return CMD_RET_FAILURE; - } - - printf("\ndfu_alt_info = %s\n", buf); - - ret = do_mmc_init(&mmc); - if (ret) { - printk("failed to init mmc\n"); - ret = CMD_RET_FAILURE; - goto error_end; - } - -#if defined(CONFIG_CMD_USB) && defined(CONFIG_USB_HOST_ETHER) && !defined(CONFIG_DM_ETH) - if (!usb_started) - do_usb_ether_start(); -#endif - - line = strtok(buf, ";\n\0"); - while (line) { - struct img_info *new_info; - - new_info = create_img_info(mmc, line); - if (new_info) - list_add_tail(&new_info->list, &img_info_list); - - line = strtok(NULL, ";\n\0"); - } - - list_for_each_entry(info, &img_info_list, list) { - if (file_name && strcmp(file_name, info->name)) - continue; - - snprintf(src_path, LEN_BUF, "%s/%s", nfs_path, info->name); - - if (info->layout == FS_FAT) - size = do_nfs_to_fat(NFS_DOWNLOAD_ADDR, src_path, - info->name, info->hwpart, - info->part); - else - size = do_nfs_to_mmc(mmc, NFS_DOWNLOAD_ADDR, src_path, - info->hwpart, info->lba_start, - info->lba_size, - info->lba_blk_size); - if (size > 0) { - struct img_comp *new_comp; - - new_comp = create_img_comp(info->name, size); - if (new_comp) - list_add_tail(&new_comp->list, &img_comp_list); - } else { - printf("SKIP %s\n\n", src_path); - } - } - - puts("########################################\n"); - list_for_each_entry(comp, &img_comp_list, list) - printf("%20s -\t%10d Bytes\n", comp->name, comp->size); - puts("########################################\n"); - -error_end: - free(buf); - - list_for_each_entry_safe(comp, tmp_comp, &img_comp_list, list) { - list_del(&comp->list); - free(comp); - } - - list_for_each_entry_safe(info, tmp_info, &img_info_list, list) { - list_del(&info->list); - free(info); - } - - return ret; -} - -U_BOOT_CMD(nfsdown, CONFIG_SYS_MAXARGS, 1, do_nfs_down, - "TIZEN \"nfs\" downloader", - "[:] [image file name]\n" - " - device firmware upgrade via nfs for Tizen\n" - " fusing images from : to MMC.\n" - " - required to set env for ipaddr, serverip, gatewayip,\n" - " and netmask.\n" - "\n" - "(e.g) nfsdown 192.168.0.1:/nfs\n" -); diff --git a/cmd/usbdown.c b/cmd/usbdown.c deleted file mode 100644 index 05500c419a..0000000000 --- a/cmd/usbdown.c +++ /dev/null @@ -1,583 +0,0 @@ -/* - * usbdown.c -- Download the image from USB storage - * - * Copyright (C) 2016 Jaehoon Chung - * All rights reserved. - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define MAX_BLK_COUNT 0x2000000 /* 65536 * 512 */ - -#ifdef CONFIG_USB_STORAGE -static int usb_stor_curr_dev = -1; /* current device */ -#endif - -static LIST_HEAD(usbdown_list); - -static int alt_num_count; -static int is_config; -extern char usb_started; - -#define NAME_SIZE 32 -enum usbdown_layout { - RAW_ADDR = 1, - FS_FAT, - FS_EXT2, - FS_EXT3, - FS_EXT4, - RAM_ADDR, -}; - -struct usbdown_entity { - int dev_num; - char name[NAME_SIZE]; - int layout; - - /* RAW programming */ - unsigned int lba_start; - unsigned int lba_size; - unsigned int lba_blk_size; - - int alt_num; - - /* eMMC HW partition access */ - int hw_partition; - - /* FAT/EXT */ - unsigned int dev; - unsigned int part; - - struct list_head list; -}; - -static int find_alt_num(const char *s) -{ - int i = 0; - - for (; *s; s++) - if (*s == ';') - i++; - - return ++i; -} - -struct usbdown_entity *usbdown_get_entity(int alt) -{ - struct usbdown_entity *usb; - - list_for_each_entry(usb, &usbdown_list, list) { - if (usb->alt_num == alt) - return usb; - } - - return NULL; -} - -int usbdown_get_alt(const char *name) -{ - struct usbdown_entity *usb; - const char *argv[3]; - const char **parg = argv; - char *name_bkp = NULL; - const char *find_name; - char *str; - int ret = -ENODEV; - - if (name[0] == '/') { - name_bkp = strdup(name); - for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { - *parg = strsep(&name_bkp, "/"); - if (*parg == NULL) { - printk("Invalid number of arguments.\n"); - ret = -ENODEV; - goto out; - } - } - - find_name = argv[2]; - } else { - find_name = name; - } - - list_for_each_entry(usb, &usbdown_list, list) { - if (usb->name[0] != '/') { - if (!strncmp(usb->name, find_name, strlen(usb->name))) { - ret = usb->alt_num; - goto out; - } - } else { - str = strstr(usb->name, find_name); - if (!str) - continue; - if (strlen(usb->name) == - ((str - usb->name) + strlen(find_name))) { - ret = usb->alt_num; - goto out; - } - } - } - -out: - if (name_bkp) - free(name_bkp); - return ret; -} - -static int usb_fill_entity(struct usbdown_entity *usb, char *s, int alt_num, - char *interface, char *devstr) -{ - const char *entity_type; - const char *argv[3]; - const char **parg = argv; - size_t second_arg; - size_t third_arg; - struct mmc *mmc; - - mmc = find_mmc_device(0); - if (mmc == NULL) { - printf("Couldn't find MMC device no. 0.\n"); - return -ENODEV; - } - - if (mmc_init(mmc)) { - printf("Couldn't init MMC device.\n"); - return -ENODEV; - } - - for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { - *parg = strsep(&s, " "); - if (*parg == NULL) { - printf("Invalid number of arguments.\n"); - return -ENODEV; - } - } - - entity_type = argv[0]; - second_arg = simple_strtoul(argv[1], NULL, 0); - third_arg = simple_strtoul(argv[2], NULL, 0); - usb->alt_num = alt_num; - - if (!strncmp(entity_type, "raw", 3)) { - usb->layout = RAW_ADDR; - usb->lba_start = second_arg; - usb->lba_size = third_arg; - usb->lba_blk_size = 512; /* Set to 512 bytes */ - - if (s && !strcmp(strsep(&s, " "), "mmcpart")) - usb->hw_partition = simple_strtoul(s, NULL, 0); - - } else if (!strncmp(entity_type, "part", 4)) { - disk_partition_t partinfo; -#ifndef CONFIG_BLK - struct blk_desc *blk_dev = &mmc->block_dev; -#else - struct blk_desc *blk_dev = mmc_get_blk_desc(mmc); -#endif - int mmcdev = second_arg; - int mmcpart = third_arg; - int offset = 0; - - if (part_get_info(blk_dev, mmcpart, &partinfo) != 0) { - printf("Couldn't find part #%d on mmc device #%d\n", - mmcpart, mmcdev); - return -ENODEV; - } - - /* - * Check for an extra entry at dfu_alt_info env variable - * specifying the mmc HW defined partition number - */ - if (s && !strcmp(strsep(&s, " "), "offset")) - offset = simple_strtoul(s, NULL, 0); - - usb->layout = RAW_ADDR; - usb->lba_start = partinfo.start + offset; - usb->lba_size = partinfo.size - offset; - usb->lba_blk_size = partinfo.blksz; - - } else if (!strncmp(entity_type, "fat", 3)) { - usb->layout = FS_FAT; - usb->dev = second_arg; - usb->part = third_arg; - } else if (!strncmp(entity_type, "ext4", 4)) { - usb->layout = FS_EXT4; - usb->dev = second_arg; - usb->part = third_arg; - } else { - printf("layout (%s) not supported!\n", entity_type); - return -ENODEV; - } - - return 0; -} - -static void fill_entity_usbdown(char *interface, char *devstr) -{ - struct usbdown_entity *usbdown; - int alt_num, i, ret; - char *s, *st, *setting; - -#ifdef CONFIG_SET_DFU_ALT_INFO - int offset = 0; - char *alt_setting, *alt_sep; - size_t buf_size = CONFIG_SET_DFU_ALT_BUF_LEN; - ALLOC_CACHE_ALIGN_BUFFER(char, buf, buf_size); - - /* Reuse dfu information. Use the eMMC by default */ - env_set("dfu_alt_boot", CONFIG_DFU_ALT_BOOT_EMMC); - offset = snprintf(buf, buf_size, "%s", CONFIG_DFU_ALT_BOOT_EMMC); - - /* Reset the dfu_alt_boot environment for thor download */ - env_set("dfu_alt_boot", "Not supported!"); - - alt_setting = env_get("dfu_alt_system"); - if (alt_setting) { - if (offset) - alt_sep = ";"; - else - alt_sep = ""; - - offset += snprintf(buf + offset, buf_size - offset, - "%s%s", alt_sep, alt_setting); - } - - env_set("dfu_alt_info", buf); -#endif - setting = env_get("dfu_alt_info"); - - alt_num = find_alt_num(setting); - - usbdown = calloc(sizeof(*usbdown), alt_num); - if (!usbdown) { - printf("%s: Failed to allocate.\n", __func__); - return; - } - - for (i = 0; i < alt_num; i++) { - /* Parsing file name */ - s = strsep(&setting, ";"); - st = strsep(&s, " "); - strncpy(usbdown[i].name, st, NAME_SIZE - 1); - - ret = usb_fill_entity(&usbdown[i], s, alt_num_count, - interface, devstr); - if (ret) { - printf("%s Failed.\n", __func__); - return; - } - - list_add_tail(&usbdown[i].list, &usbdown_list); - alt_num_count++; - } -} - -static void do_usb_start(void) -{ - bootstage_mark_name(BOOTSTAGE_ID_USB_START, "usb_start"); - - if (usb_init() < 0) - return; - - /* Driver model will probe the devices as they are found */ -#ifndef CONFIG_DM_USB -# ifdef CONFIG_USB_STORAGE - /* try to recognize storage devices immediately */ - usb_stor_curr_dev = usb_stor_scan(1); -# endif -#endif /* !CONFIG_DM_USB */ -} - -int do_update(cmd_tbl_t *cmdtp, int flags, int argc, char * const argv[]) -{ - struct usbdown_entity *usbdown; - -#ifdef CONFIG_USB_STORAGE - struct blk_desc *stor_dev; -#endif - if (argc < 4) - return CMD_RET_USAGE; - - if (!usb_started) { - printf("\nUSB is stopped..starting USB first.\n\n"); - do_usb_start(); - } - - if (argc == 4) { - int dev = (int)simple_strtoul(argv[1], NULL, 10); - char *interface = argv[2]; - const char *filename = argv[3]; - loff_t len_read = 0, size = 0, offset = 0; - unsigned long addr = CONFIG_SYS_SDRAM_BASE; - int alt_num, ret = 0; - unsigned long len = 0; - struct mmc *mmc; - const char *fsname, *opname; - char cmd_buf[128]; - int part_num_bkp = 0; - const char *from = "usb"; - - /* Default MMC 0 */ - mmc = find_mmc_device(0); - if (!mmc) { - printf("Device MMC %d - not found!", 0); - return CMD_RET_FAILURE; - } - - if (mmc_init(mmc)) { - printf("Couldn't init MMC device.\n"); - return CMD_RET_FAILURE; - } - - /* Used the mmc 0 by default */ - if (!is_config) { - fill_entity_usbdown(interface, "0"); - is_config = 1; - - printf("USB device %d: ", dev); - stor_dev = blk_get_devnum_by_type(IF_TYPE_USB, dev); - if (stor_dev == NULL) { - printf("unknown device\n"); - return CMD_RET_FAILURE; - } - - printf("\n Device %d: ", dev); - dev_print(stor_dev); - if (stor_dev->type == DEV_TYPE_UNKNOWN) - return CMD_RET_FAILURE; - usb_stor_curr_dev = dev; - printf("... is now current device\n"); - } - - if (fs_set_blk_dev(from, argv[1], FS_TYPE_ANY)) { - printf("%d: Unknown block device..\n", __LINE__); - return CMD_RET_FAILURE; - } - - alt_num = usbdown_get_alt(filename); - if (alt_num < 0) { - printf("There is no %s information\n", filename); - return CMD_RET_FAILURE; - } - - ret = fs_size(filename, &size); - if (ret < 0) { - printf("There is no %s\n", filename); - /* if there is no file, then just pass through */ - return CMD_RET_SUCCESS; - } - - usbdown = usbdown_get_entity(alt_num); - if (!usbdown) { - printf("there is no information for %d\n", alt_num); - return CMD_RET_FAILURE; - } - -#ifdef CONFIG_SIG - /* It needs to check the signature about only u-boot image */ - if (!strncmp(usbdown->name, "u-boot", strlen(usbdown->name))) { - if (fs_set_blk_dev(from, argv[1], FS_TYPE_ANY)) - return CMD_RET_FAILURE; - - ret = fs_read(filename, (phys_addr_t)addr, 0, - size, &len_read); - if (ret) - return CMD_RET_FAILURE; - - ret = check_board_signature("u-boot-mmc.bin", - (phys_addr_t)addr, (phys_addr_t)size); - if (ret) - return CMD_RET_FAILURE; - } -#endif - - if (usbdown->layout == FS_FAT) { - /* loading File */ - fsname = "fat"; - opname = "load"; - - sprintf(cmd_buf, "%s%s usb %s", fsname, - opname, argv[1]); - sprintf(cmd_buf + strlen(cmd_buf), - " %p", (void *)addr); - sprintf(cmd_buf + strlen(cmd_buf), - " %s", filename); - ret = run_command(cmd_buf, 0); - if (ret != CMD_RET_SUCCESS) - return ret; - - /* Write file */ - opname = "write"; - sprintf(cmd_buf, "%s%s mmc %d:%d", fsname, opname, - usbdown->dev, usbdown->part); - sprintf(cmd_buf + strlen(cmd_buf), - " %p", (void *)addr); - sprintf(cmd_buf + strlen(cmd_buf), - " %s", usbdown->name); - sprintf(cmd_buf + strlen(cmd_buf), - " %llx", size); - - run_command(cmd_buf, 0); - - } else if (usbdown->layout == RAW_ADDR) { - if (usbdown->hw_partition >= 0) { -#ifndef CONFIG_BLK - part_num_bkp = mmc->block_dev.hwpart; -#else - part_num_bkp = mmc_get_blk_desc(mmc)->hwpart; -#endif - ret = blk_select_hwpart_devnum(IF_TYPE_MMC, - usbdown->dev_num, - usbdown->hw_partition); - if (ret) - return CMD_RET_FAILURE; - } - - while (size > 0) { - if (fs_set_blk_dev(from, argv[1], - FS_TYPE_ANY)) { - printf("Unknown block device..\n"); - if (usbdown->hw_partition >= 0) - blk_select_hwpart_devnum(IF_TYPE_MMC, - usbdown->dev_num, - part_num_bkp); - return -ENODEV; - } - if (size < MAX_BLK_COUNT) - len = size; - else - len = MAX_BLK_COUNT; - - ret = fs_read(filename, addr, offset, len, - &len_read); - if (ret < 0) { - printf("Failed to read %s file.\n", filename); - if (usbdown->hw_partition >= 0) - blk_select_hwpart_devnum(IF_TYPE_MMC, - usbdown->dev_num, - part_num_bkp); - return CMD_RET_FAILURE; - } - -#ifndef CONFIG_BLK - mmc->block_dev.block_write(&mmc->block_dev, - usbdown->lba_start + offset / 512, - len_read / 512, (void *)addr); -#else - blk_dwrite(mmc_get_blk_desc(mmc), - usbdown->lba_start + offset /512, - len_read / 512, (void *)addr); -#endif - - offset += len_read; - size -= len_read; - } - printf("Read %s Total %llu bytes\n", filename, offset); - } - - if (usbdown->hw_partition >= 0) { - ret = blk_select_hwpart_devnum(IF_TYPE_MMC, usbdown->dev_num, - part_num_bkp); - if (ret) - return CMD_RET_FAILURE; - } - - return CMD_RET_SUCCESS; - } - - return CMD_RET_USAGE; -} - -U_BOOT_CMD(update, 5, 1, do_update, - "Manually download Images with USB storage for Tizen", - " \n" - " (e,g update 0:0 mmc rootfs.img)\n" -); - -/* Only release image files are described */ -static char *name[] = { - "u-boot-mmc.bin", - "params.bin", - "boot.img", - "rootfs.img", - "system-data.img", - "user.img", - "modules.img", - "ramdisk.img", -}; - -static int do_usb_down(cmd_tbl_t *cmdtp, int flags, int argc, char * const argv[]) -{ - if (argc < 1) - return CMD_RET_USAGE; - - if (argc == 2) { - char cmd_buf[128]; - const char *interface, *dir, *part, *cmd; - int ret, i; - int files = sizeof(name) / sizeof(name[0]); - - if (!usb_started) { - printf("\nUSB is stopped..starting USB first.\n\n"); - do_usb_start(); - } - - /* Use command "update" */ - cmd = "update"; - - /* Fixed direcotry as /updateTizen */ - dir = "/updateTizen"; - - /* interface is fixed "mmc" by default */ - interface = "mmc"; - - /* Checking part 0:0 */ - part = "0:0"; - ret = file_exists("usb", part, dir, FS_TYPE_ANY); - if (!ret) { - part = "0:1"; - ret = file_exists("usb", part, dir, FS_TYPE_ANY); - if (!ret) { - printf("Can't find partition or directory\n"); - return CMD_RET_USAGE; - } - } - - for (i = 0; i < files; i++) { - sprintf(cmd_buf, "%s %s %s %s", - cmd, part, interface, dir); - sprintf(cmd_buf + strlen(cmd_buf), "/%s", name[i]); - ret = run_command(cmd_buf, 0); - if (ret == CMD_RET_FAILURE) - return ret; - printf("\n"); - } - - return CMD_RET_SUCCESS; - } - - return CMD_RET_USAGE; -} - -U_BOOT_CMD(usbdown, 2, 1, do_usb_down, - "Download automantically all image with USB storage for Tizen", - "all\n" - " (e,g usbdown all)\n" - "Note: All images have to be located in /updateTizen/ directory.\n" - " And part number is 0 or 1. - eg sdb or sdb1\n" -); -- 2.34.1