From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lukasz Majewski Date: Mon, 12 Aug 2013 16:37:52 +0200 Subject: [U-Boot] [PATCH] DFU: fix for raw data write In-Reply-To: <1375786266-11822-2-git-send-email-m.zalega@samsung.com> References: <1375786266-11822-1-git-send-email-m.zalega@samsung.com> <1375786266-11822-2-git-send-email-m.zalega@samsung.com> Message-ID: <20130812163752.2e99607b@amdc308.digital.local> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Hi Mateusz, > 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 device in get_mmc_blk_size() > when needed. > > Tested on Samsung Goni. > > Signed-off-by: Mateusz Zalega > Signed-off-by: Kyungmin Park > Cc: Lukasz Majewski > Cc: Minkyu Kang > --- > drivers/dfu/dfu.c | 22 ++++++++++++++++++++++ > drivers/dfu/dfu_mmc.c | 3 +++ > include/dfu.h | 7 ++----- > 3 files changed, 27 insertions(+), 5 deletions(-) > > diff --git a/drivers/dfu/dfu.c b/drivers/dfu/dfu.c > index d73d510..6979112 100644 > --- a/drivers/dfu/dfu.c > +++ b/drivers/dfu/dfu.c The mmc (or any other medium) related code shall NOT be added to generic dfu.c file. > @@ -414,3 +414,25 @@ struct dfu_entity *dfu_get_entity(int alt) > > return NULL; > } > + > +int get_mmc_blk_size(int dev) > +{ > + struct mmc *mmc = find_mmc_device(dev); > + > + if (mmc == NULL) { > + error("Couldn't find MMC device no. %d.\n", dev); > + return -ENODEV; > + } > + if (!mmc->has_init) { > + if (!mmc_init(mmc)) { > + if (!mmc->read_bl_len) { > + error("invalid block length\n"); > + return -ENODEV; > + } > + } else { > + error("Couldn't init MMC device.\n"); > + return -ENODEV; > + } > + } > + return mmc->read_bl_len; > +} The above code fits better at dfu_mmc.c file. My proposition would be to clean up the dfu_fill_entity_mmc() function and add the above code there. > diff --git a/drivers/dfu/dfu_mmc.c b/drivers/dfu/dfu_mmc.c > index 0871a77..c776e26 100644 > --- a/drivers/dfu/dfu_mmc.c > +++ b/drivers/dfu/dfu_mmc.c > @@ -235,5 +235,8 @@ int dfu_fill_entity_mmc(struct dfu_entity *dfu, > char *s) /* initial state */ > dfu->inited = 0; > > + /* better safe than sorry */ > + assert(dfu->data.mmc.lba_blk_size > 0); > + > return 0; > } > diff --git a/include/dfu.h b/include/dfu.h > index 1d4006d..67ca711 100644 > --- a/include/dfu.h > +++ b/include/dfu.h > @@ -40,6 +40,8 @@ struct mmc_internal_data { > unsigned int part; > }; > > +int get_mmc_blk_size(int dev); > + > struct nand_internal_data { > /* RAW programming */ > u64 start; > @@ -49,11 +51,6 @@ struct nand_internal_data { > unsigned int part; > }; > > -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 -- Best regards, Lukasz Majewski Samsung R&D Institute Poland (SRPOL) | Linux Platform Group