From patchwork Mon Apr 28 19:13:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Zalega X-Patchwork-Id: 343524 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3E21C14008A for ; Tue, 29 Apr 2014 05:14:24 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EA5054BA3B; Mon, 28 Apr 2014 21:13:44 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AVA-RfljdDFf; Mon, 28 Apr 2014 21:13:44 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DA9C24BA44; Mon, 28 Apr 2014 21:12:32 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BA4884BA20 for ; Mon, 28 Apr 2014 21:12:27 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id F38-9mg16gJL for ; Mon, 28 Apr 2014 21:12:24 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mailout2.w1.samsung.com (mailout2.w1.samsung.com [210.118.77.12]) by theia.denx.de (Postfix) with ESMTPS id 5753D4B9F2 for ; Mon, 28 Apr 2014 21:12:12 +0200 (CEST) Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N4R00IJ99BZIX80@mailout2.w1.samsung.com> for u-boot@lists.denx.de; Mon, 28 Apr 2014 20:11:59 +0100 (BST) X-AuditID: cbfec7f4-b7fb36d000006ff7-52-535ea80935d6 Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 86.CC.28663.908AE535; Mon, 28 Apr 2014 20:12:09 +0100 (BST) Received: from AMDC2105.digital.local ([106.116.147.44]) by eusync3.samsung.com (Oracle Communications Messaging Server 7u4-23.01 (7.0.4.23.0) 64bit (built Aug 10 2011)) with ESMTPA id <0N4R00JBF9C85250@eusync3.samsung.com>; Mon, 28 Apr 2014 20:12:09 +0100 (BST) From: Mateusz Zalega To: u-boot@lists.denx.de Date: Mon, 28 Apr 2014 21:13:24 +0200 Message-id: <1398712412-15503-5-git-send-email-m.zalega@samsung.com> X-Mailer: git-send-email 1.9.0 In-reply-to: <1398712412-15503-1-git-send-email-m.zalega@samsung.com> References: <1389277919-15279-1-git-send-email-m.zalega@samsung.com> <1398712412-15503-1-git-send-email-m.zalega@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOJMWRmVeSWpSXmKPExsVy+t/xq7qcK+KCDeb8srY42/SG3WLuuylM Fh1HWhgt3u7tZHdg8Th7ZwejR9+WVYwBTFFcNimpOZllqUX6dglcGVe/9jAWfNWp2DnrGnMD 4xSVLkZODgkBE4kNlz4xQthiEhfurWfrYuTiEBJYyijR0Tkfyuljkvi+sZcdpIpNQFvixt75 YLaIgITEr/6rYN3MAlUSj84cBYpzcAgLmEl8ehMGEmYRUJXYcPknE4jNK+AicfX9B2aIZXIS U34vACvnFHCVmH1IESQsJFAv8fnyU5YJjLwLGBlWMYqmliYXFCel5xrqFSfmFpfmpesl5+du YoQExpcdjIuPWR1iFOBgVOLhXaEQEyzEmlhWXJl7iFGCg1lJhNe2NS5YiDclsbIqtSg/vqg0 J7X4ECMTB6dUA6NU4t6bgaEVX9NPMy45uWyS86yMkN9fJXd/7bYSvn7m3dk5Nqu+vOgX//nn f4NKbIz0vlkPFV2iY9yW6KS3fV51WWyyq96JiVYPrJr+JM0KiX6Y++yO2twfxm5+6/jbA0oy 56zXy5JIF63gDp7//NvDFTuyH+tnTtHUXP47vURSeZfXy6ufjmxRYinOSDTUYi4qTgQA9Sfv quoBAAA= Cc: Kyungmin Park Subject: [U-Boot] [PATCH v5 04/12] dfu: mmc: raw data write fix X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de When user attempted to perform a raw write using DFU (vide dfu_fill_entity_mmc) with MMC interface not initialized before, get_mmc_blk_size() reported invalid (zero) block size - it wasn't possible to write ie. a new u-boot image. This commit fixes that by initializing MMC device before use in dfu_fill_entity_mmc(). While fixing initialization sequence, I had to change about half of dfu_fill_entity_mmc's body, so I refactored it on the way to make it, IMHO, considerably more comprehensible. Being left as dead code, get_mmc_blk_size() was removed. Tested on Samsung Goni. Signed-off-by: Mateusz Zalega Signed-off-by: Kyungmin Park Acked-by: Lukasz Majewski Acked-by: Tom Rini Cc: Minkyu Kang --- Changes since v4: - added more detailed commit message - converted to C90-style - split into two patches: write fix and offset interpretation change --- drivers/dfu/dfu_mmc.c | 105 +++++++++++++++++++++++++++++++------------------- include/dfu.h | 5 --- 2 files changed, 65 insertions(+), 45 deletions(-) diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c index 651cfff..b41785d 100644 --- a/drivers/dfu/dfu_mmc.c +++ b/drivers/dfu/dfu_mmc.c @@ -184,66 +184,91 @@ int dfu_read_medium_mmc(struct dfu_entity *dfu, u64 offset, void *buf, return ret; } +/* + * @param s Parameter string containing space-separated arguments: + * 1st: + * raw (raw read/write) + * fat (files) + * ext4 (^) + * part (partition image) + * 2nd and 3rd: + * lba_start and lba_size, for raw write + * mmc_dev and mmc_part, for filesystems and part + */ int dfu_fill_entity_mmc(struct dfu_entity *dfu, char *s) { - int dev, part; - struct mmc *mmc; - block_dev_desc_t *blk_dev; - disk_partition_t partinfo; - char *st; + const char *entity_type; + size_t second_arg; + size_t third_arg; - dfu->dev_type = DFU_DEV_MMC; - st = strsep(&s, " "); - if (!strcmp(st, "mmc")) { - dfu->layout = DFU_RAW_ADDR; - dfu->data.mmc.lba_start = simple_strtoul(s, &s, 16); - dfu->data.mmc.lba_size = simple_strtoul(++s, &s, 16); - dfu->data.mmc.lba_blk_size = get_mmc_blk_size(dfu->dev_num); - } else if (!strcmp(st, "fat")) { - dfu->layout = DFU_FS_FAT; - } else if (!strcmp(st, "ext4")) { - dfu->layout = DFU_FS_EXT4; - } else if (!strcmp(st, "part")) { - - dfu->layout = DFU_RAW_ADDR; + struct mmc *mmc; - dev = simple_strtoul(s, &s, 10); - s++; - part = simple_strtoul(s, &s, 10); + const char *argv[3]; + const char **parg = argv; - mmc = find_mmc_device(dev); - if (mmc == NULL || mmc_init(mmc)) { - printf("%s: could not find mmc device #%d!\n", - __func__, dev); + for (; parg < argv + sizeof(argv) / sizeof(*argv); ++parg) { + *parg = strsep(&s, " "); + if (*parg == NULL) { + error("Invalid number of arguments.\n"); return -ENODEV; } + } - blk_dev = &mmc->block_dev; - if (get_partition_info(blk_dev, part, &partinfo) != 0) { - printf("%s: could not find partition #%d on mmc device #%d!\n", - __func__, part, dev); + entity_type = argv[0]; + second_arg = simple_strtoul(argv[1], NULL, 16); + third_arg = simple_strtoul(argv[2], NULL, 16); + + mmc = find_mmc_device(dfu->dev_num); + if (mmc == NULL) { + error("Couldn't find MMC device no. %d.\n", dfu->dev_num); + return -ENODEV; + } + + if (mmc_init(mmc)) { + error("Couldn't init MMC device.\n"); + return -ENODEV; + } + + if (!strcmp(entity_type, "raw")) { + dfu->layout = DFU_RAW_ADDR; + dfu->data.mmc.lba_start = second_arg; + dfu->data.mmc.lba_size = third_arg; + dfu->data.mmc.lba_blk_size = mmc->read_bl_len; + } else if (!strcmp(entity_type, "part")) { + disk_partition_t partinfo; + block_dev_desc_t *blk_dev = &mmc->block_dev; + int mmcdev = second_arg; + int mmcpart = third_arg; + + if (get_partition_info(blk_dev, mmcpart, &partinfo) != 0) { + error("Couldn't find part #%d on mmc device #%d\n", + mmcpart, mmcdev); return -ENODEV; } - dfu->data.mmc.lba_start = partinfo.start; - dfu->data.mmc.lba_size = partinfo.size; - dfu->data.mmc.lba_blk_size = partinfo.blksz; - + dfu->layout = DFU_RAW_ADDR; + dfu->data.mmc.lba_start = partinfo.start; + dfu->data.mmc.lba_size = partinfo.size; + dfu->data.mmc.lba_blk_size = partinfo.blksz; + } else if (!strcmp(entity_type, "fat")) { + dfu->layout = DFU_FS_FAT; + } else if (!strcmp(entity_type, "ext4")) { + dfu->layout = DFU_FS_EXT4; } else { - printf("%s: Memory layout (%s) not supported!\n", __func__, st); + error("Memory layout (%s) not supported!\n", entity_type); return -ENODEV; } - if (dfu->layout == DFU_FS_EXT4 || dfu->layout == DFU_FS_FAT) { - dfu->data.mmc.dev = simple_strtoul(s, &s, 10); - dfu->data.mmc.part = simple_strtoul(++s, &s, 10); + /* if it's NOT a raw write */ + if (strcmp(entity_type, "raw")) { + dfu->data.mmc.dev = second_arg; + dfu->data.mmc.part = third_arg; } + dfu->dev_type = DFU_DEV_MMC; dfu->read_medium = dfu_read_medium_mmc; dfu->write_medium = dfu_write_medium_mmc; dfu->flush_medium = dfu_flush_medium_mmc; - - /* initial state */ dfu->inited = 0; return 0; diff --git a/include/dfu.h b/include/dfu.h index 6c71ecb..dcd3215 100644 --- a/include/dfu.h +++ b/include/dfu.h @@ -64,11 +64,6 @@ struct ram_internal_data { unsigned int size; }; -static inline unsigned int get_mmc_blk_size(int dev) -{ - return find_mmc_device(dev)->read_bl_len; -} - #define DFU_NAME_SIZE 32 #define DFU_CMD_BUF_SIZE 128 #ifndef CONFIG_SYS_DFU_DATA_BUF_SIZE