Enable mmc to write sparse images
cover Enable mmc to write sparse images
From: Jassi Brar <[email protected]>
Hi,
Having capability to flash sparse images from mmc subsystem could be useful.
For example, non-android/fastboot platforms could leverage the concept. Or some platforms that need to 'pull' updates (get images over tftp and flash using mmc). Or when we want to flash image at some non-zero offset from the start of a partition. Or simply when USB-Device has issues for fastboot to work (my itch).
This patchset first cleans and makes write_sparse_image agnostic of
fastboot and then adds a new 'swrite' command to 'mmc'.
Jassi Brar (3):
fastboot: sparse: remove redundant argument to write_sparse_image
fastboot: sparse: make write_sparse_image useable for non-fastboot
mmc: support writing sparse images
cmd/mmc.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ common/fb_mmc.c | 7 +++-- common/fb_nand.c | 6 +++-- common/image-sparse.c | 69 +++++++++++++++++++++++--------------------------- include/image-sparse.h | 6 +++-- 5 files changed, 112 insertions(+), 43 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/3 fastboot: sparse: remove redundant argument to write_sparse_image
From: Jassi Brar <[email protected]>
'sz' has no use for write_sparse_image, remove it simplifying the api.
--- common/fb_mmc.c | 3 +-- common/fb_nand.c | 3 +-- common/image-sparse.c | 2 +- include/image-sparse.h | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-)
common/fb_mmc.c +1 -2
@@ -343,8 +343,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer, sparse.start); sparse.priv = &sparse_priv; -write_sparse_image (&sparse, cmd, download_buffer, - download_bytes); +write_sparse_image (&sparse, cmd, download_buffer); }else {write_raw_image (dev_desc, &info, cmd, download_buffer, download_bytes);
common/fb_nand.c +1 -2
@@ -180,8 +180,7 @@ void fb_nand_flash_write(const char *cmd, void *download_buffer, sparse.start); sparse.priv = &sparse_priv; -write_sparse_image (&sparse, cmd, download_buffer, - download_bytes); +write_sparse_image (&sparse, cmd, download_buffer); }else {printf ("Flashing raw image at offset 0x%llx\n" , part->offset);
common/image-sparse.c +1 -1
@@ -51,7 +51,7 @@void write_sparse_image (struct sparse_storage *info,const char *part_name, -void *data,unsigned sz) +void *data) {lbaint_t blk;lbaint_t blkcnt;
include/image-sparse.h +1 -1
@@ -37,4 +37,4 @@ static inline int is_sparse_image(void *buf) }void write_sparse_image (struct sparse_storage *info,const char *part_name, -void *data,unsigned sz); +void *data);
Signature · 1 line
2.7.4
PATCH 1/3 fastboot: sparse: remove redundant argument to write_sparse_image
Quoted 5 lines · jassisinghbrar at gmail.com
From: Jassi Brar <[email protected]>
'sz' has no use for
write_sparse_image, remove it simplifying the api.Signed-off-by Jassi Brar <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180508/b74e644e/attachment.sig>
PATCH 2/3 fastboot: sparse: make write_sparse_image useable for non-fastboot
In reply to jassisinghbrar at gmail.comFrom: Jassi Brar <[email protected]>
write_sparse_image could be useful for non-fastboot users. For ex a platform, without usb-device/fastboot support, could get sparse images over tftp and write using the mmc command. Or non-android systems could also leverage the sparse format.
Towards that, this patch removes anything fastboot specific from the write_sparse_image implementation. Which includes making the function return integer as error code and calls for fastboot logging via an optional callback function 'mssg'.
--- common/fb_mmc.c | 6 ++++- common/fb_nand.c | 5 +++- common/image-sparse.c | 69 +++++++++++++++++++++++--------------------------- include/image-sparse.h | 6 +++-- 4 files changed, 45 insertions(+), 41 deletions(-)
common/fb_mmc.c +5 -1
@@ -330,6 +330,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer,if (is_sparse_image (download_buffer)) {struct fb_mmc_sparse sparse_priv;struct sparse_storage sparse; +int err; sparse_priv.dev_desc = dev_desc;
@@ -338,12 +339,15 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer, sparse.size = info.size; sparse.write = fb_mmc_sparse_write; sparse.reserve = fb_mmc_sparse_reserve; + sparse.mssg = fastboot_fail;printf ("Flashing sparse image at offset " LBAFU "\n" , sparse.start); sparse.priv = &sparse_priv; -write_sparse_image (&sparse, cmd, download_buffer); + err =write_sparse_image (&sparse, cmd, download_buffer); +if (!err) +fastboot_okay ("" ); }else {write_raw_image (dev_desc, &info, cmd, download_buffer, download_bytes);
common/fb_nand.c +4 -1
@@ -175,12 +175,15 @@ void fb_nand_flash_write(const char *cmd, void *download_buffer, sparse.size = part->size / sparse.blksz; sparse.write = fb_nand_sparse_write; sparse.reserve = fb_nand_sparse_reserve; + sparse.mssg = fastboot_fail;printf ("Flashing sparse image at offset " LBAFU "\n" , sparse.start); sparse.priv = &sparse_priv; -write_sparse_image (&sparse, cmd, download_buffer); + ret =write_sparse_image (&sparse, cmd, download_buffer); +if (!ret) +fastboot_okay ("" ); }else {printf ("Flashing raw image at offset 0x%llx\n" , part->offset);
common/image-sparse.c +32 -37
153 lines not on this page · raw message
include/image-sparse.h +4 -2
@@ -23,6 +23,8 @@ struct sparse_storage {lbaint_t (*reserve)(struct sparse_storage *info,lbaint_t blk,lbaint_t blkcnt); + +void (*mssg)(const char *str); };static inline int is_sparse_image (void *buf)
@@ -36,5 +38,5 @@ static inline int is_sparse_image(void *buf)return 0 ; } -void write_sparse_image (struct sparse_storage *info,const char *part_name, -void *data); +int write_sparse_image (struct sparse_storage *info,const char *part_name, +void *data);
Signature · 1 line
2.7.4
PATCH 2/3 fastboot: sparse: make write_sparse_image useable for non-fastboot
Quoted 7 lines · jassisinghbrar at gmail.com
From: Jassi Brar <[email protected]>
write_sparse_imagecould be useful for non-fastboot users. For ex a platform, without usb-device/fastboot support, could get sparse images over tftp and write using the mmc command. Or non-android systems could also leverage the sparse format.
Quoted 6 lines
Towards that, this patch removes anything fastboot specific from the
write_sparse_imageimplementation. Which includes making the function return integer as error code and calls for fastboot logging via an optional callback function 'mssg'.Signed-off-by Jassi Brar <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180508/d575f86c/attachment.sig>
PATCH 3/3 mmc: support writing sparse images
In reply to jassisinghbrar at gmail.comFrom: Jassi Brar <[email protected]>
Provide an alternate path for sparse-images to be written to MMC. For example, via tftp on platforms that don't support fastboot protocol. Or when an image is to written at some offset, rather than the start of a partition.
--- cmd/mmc.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)
cmd/mmc.c +67 -0
@@ -9,6 +9,8 @@#include <command.h> #include <console.h> #include <mmc.h> +#include <sparse_format.h> +#include <image-sparse.h> static int curr_device =-1 ;
@@ -308,6 +310,69 @@ static int do_mmc_read(cmd_tbl_t *cmdtp, int flag, }#if CONFIG_IS_ENABLED (MMC_WRITE ) +static lbaint_t mmc_sparse_write (struct sparse_storage *info,lbaint_t blk, +lbaint_t blkcnt,const void *buffer) +{ +struct blk_desc *dev_desc = info->priv; + +return blk_dwrite (dev_desc, blk, blkcnt, buffer); +} + +static lbaint_t mmc_sparse_reserve (struct sparse_storage *info, +lbaint_t blk,lbaint_t blkcnt) +{ +return blkcnt; +} + +static int do_mmc_sparse_write (cmd_tbl_t *cmdtp,int flag, +int argc,char *const argv[]) +{ +struct sparse_storage sparse; +struct blk_desc *dev_desc; +struct mmc *mmc; +char dest[11 ]; +void *addr; +u32 blk; + +if (argc !=3 ) +return CMD_RET_USAGE ; + + addr = (void *)simple_strtoul (argv[1 ],NULL ,16 ); + blk =simple_strtoul (argv[2 ],NULL ,16 ); + +if (!is_sparse_image (addr)) { +printf ("Not a sparse image\n" ); +return CMD_RET_FAILURE ; + } + + mmc =init_mmc_device (curr_device, false); +if (!mmc) +return CMD_RET_FAILURE ; + +printf ("\nMMC Sparse write: dev # %d, block # %d ... " , + curr_device, blk); + +if (mmc_getwp (mmc) ==1 ) { +printf ("Error: card is write protected!\n" ); +return CMD_RET_FAILURE ; + } + + dev_desc =mmc_get_blk_desc (mmc); + sparse.priv = dev_desc; + sparse.blksz =512 ; + sparse.start = blk; + sparse.size = dev_desc->lba - blk; + sparse.write = mmc_sparse_write; + sparse.reserve = mmc_sparse_reserve; + sparse.mssg =NULL ; +sprintf (dest,"0x%08lX" , sparse.start * sparse.blksz); + +if (write_sparse_image (&sparse, dest, addr)) +return CMD_RET_FAILURE ; +else +return CMD_RET_SUCCESS ; +} +static int do_mmc_write (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) {
@@ -802,6 +867,7 @@ static cmd_tbl_t cmd_mmc[] = { U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""),#if CONFIG_IS_ENABLED (MMC_WRITE )U_BOOT_CMD_MKENT (write,4 ,0 , do_mmc_write,"" ,"" ), +U_BOOT_CMD_MKENT (swrite,3 ,0 , do_mmc_sparse_write,"" ,"" ),U_BOOT_CMD_MKENT (erase,3 ,0 , do_mmc_erase,"" ,"" ), #endif U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""),
@@ -858,6 +924,7 @@ U_BOOT_CMD("info - display info of the current MMC device\n" "mmc read addr blk# cnt\n" "mmc write addr blk# cnt\n" +"mmc swrite addr blk#\n" "mmc erase blk# cnt\n" "mmc rescan\n" "mmc part - lists available partition on current mmc device\n"
Signature · 1 line
2.7.4
PATCH 3/3 mmc: support writing sparse images
Quoted 9 lines · jassisinghbrar at gmail.com
From: Jassi Brar <[email protected]>
Provide an alternate path for sparse-images to be written to MMC. For example, via tftp on platforms that don't support fastboot protocol. Or when an image is to written at some offset, rather than the start of a partition.
Signed-off-by Jassi Brar <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180508/beda500c/attachment.sig>
PATCH 3/3 mmc: support writing sparse images
Hi Tom,
Quoted 10 lines · Tom Rini
Quoted 8 lines · jassisinghbrar at gmail.com
From: Jassi Brar <[email protected]>
Provide an alternate path for sparse-images to be written to MMC. For example, via tftp on platforms that don't support fastboot protocol. Or when an image is to written at some offset, rather than the start of a partition.
Quoted 4 lines
Quoted 1 line
Signed-off-by Jassi Brar <[email protected]>Applied to u-boot/master, thanks!
I see you modified the patch to protect the feature with CONFIG_FASTBOOT_FLASH, which kills the purpose -- this feature is for platforms that don't support fastboot.
Do you want me to send the patch to revert the protection?
Thanks.
PATCH 3/3 mmc: support writing sparse images
Quoted 15 lines · Jassi Brar
Hi Tom,
Quoted 12 lines · Tom Rini
Quoted 9 lines · jassisinghbrar at gmail.com
From: Jassi Brar <[email protected]>
Provide an alternate path for sparse-images to be written to MMC. For example, via tftp on platforms that don't support fastboot protocol. Or when an image is to written at some offset, rather than the start of a partition.
Signed-off-by Jassi Brar <[email protected]>
Quoted 7 lines
Quoted 1 line
Applied to u-boot/master, thanks!
I see you modified the patch to protect the feature with
CONFIG_FASTBOOT_FLASH, which kills the purpose -- this feature is for platforms that don't support fastboot.Do you want me to send the patch to revert the protection?
Sorry, I guess maybe things weren't clear enough all around, and we should (functionally) revert patches 2 and 3 and try something different. It is OK to say "lets make writing sparse images more widely available". It's not OK to make every platform with MMC write grow a decent bit in binary size. Making a quick pass at re-enabling things on a platform without fastboot support already grew things by nearly 2KiB. The other part which is I believe got me down this path was that without a change to common/Makefile to always (outside of SPL) include common/image-sparse.o things don't link.
In sum, a new patch to add an option to allow people to opt-in for swrite would be good. And please make sure to do something like:
common/Makefile +1 -0
@@ -120,6 +120,7 @@ ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV obj-y += fb_nand.o endif endif +obj-$(CONFIG_MMC_WRITE) += image-sparse.o endif ifdef CONFIG_CMD_EEPROM_LAYOUT
too so it links everywhere. Thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180514/d7364bbe/attachment.sig>
PATCH 3/3 mmc: support writing sparse images
Quoted 5 lines · Tom Rini
Quoted 4 lines · Jassi Brar
Hi Tom,
Quoted 1 line · Tom Rini
On Fri, Apr 06, 2018 at 12:05:24PM +0530, jassisinghbrar at gmail.com
Quoted 36 lines · wrote:
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
From: Jassi Brar <[email protected]>
Provide an alternate path for sparse-images to be written to MMC. For example, via tftp on platforms that don't support fastboot protocol. Or when an image is to written at some offset, rather than the start of a partition.
Signed-off-by Jassi Brar <[email protected]>Quoted 7 lines
Quoted 1 line
Applied to u-boot/master, thanks!
I see you modified the patch to protect the feature with
CONFIG_FASTBOOT_FLASH, which kills the purpose -- this feature is for platforms that don't support fastboot.Do you want me to send the patch to revert the protection?
Sorry, I guess maybe things weren't clear enough all around, and we should (functionally) revert patches 2 and 3 and try something different. It is OK to say "lets make writing sparse images more widely available". It's not OK to make every platform with MMC write grow a decent bit in binary size. Making a quick pass at re-enabling things on a platform without fastboot support already grew things by nearly 2KiB. The other part which is I believe got me down this path was that without a change to common/Makefile to always (outside of SPL) include
common/image-sparse.othings don't link.In sum, a new patch to add an option to allow people to opt-in for swrite would be good. And please make sure to do something like:
common/Makefile +0
-0
common/Makefile ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV · line 124
Quoted 5 lines
common/Makefile +1
-0@@ -120,6 +120,7 @@ ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV obj-y += fb_nand.o endif endif +obj-$(CONFIG_MMC_WRITE) += image-sparse.o endif
Isn't this just move image-sparse to lib and add a separate guard for it (LIB_IMAGE_SPARSE?) which can be selected by both FASTBOOT and a new command symbol (CMD_MMC_SWRITE)?
This is all overlapping with the UDP fastboot code I've been posting, so I'd kinda like it to fit nicely with that, rather than have to refactor it to fit something different!
--
Alex Kiernan
PATCH 3/3 mmc: support writing sparse images
Quoted 54 lines · Alex Kiernan
Quoted 5 lines · Tom Rini
Quoted 4 lines · Jassi Brar
Hi Tom,
Quoted 1 line · Tom Rini
On Fri, Apr 06, 2018 at 12:05:24PM +0530, jassisinghbrar at gmail.com
Quoted 36 lines · wrote:
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
From: Jassi Brar <[email protected]>
Provide an alternate path for sparse-images to be written to MMC. For example, via tftp on platforms that don't support fastboot protocol. Or when an image is to written at some offset, rather than the start of a partition.
Signed-off-by Jassi Brar <[email protected]>Quoted 7 lines
Quoted 1 line
Applied to u-boot/master, thanks!
I see you modified the patch to protect the feature with
CONFIG_FASTBOOT_FLASH, which kills the purpose -- this feature is for platforms that don't support fastboot.Do you want me to send the patch to revert the protection?
Sorry, I guess maybe things weren't clear enough all around, and we should (functionally) revert patches 2 and 3 and try something different. It is OK to say "lets make writing sparse images more widely available". It's not OK to make every platform with MMC write grow a decent bit in binary size. Making a quick pass at re-enabling things on a platform without fastboot support already grew things by nearly 2KiB. The other part which is I believe got me down this path was that without a change to common/Makefile to always (outside of SPL) include
common/image-sparse.othings don't link.In sum, a new patch to add an option to allow people to opt-in for swrite would be good. And please make sure to do something like:
common/Makefile +0
-0common/Makefile ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV · line 124
Quoted 5 lines
common/Makefile +1
-0@@ -120,6 +120,7 @@ ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV obj-y += fb_nand.o endif endif +obj-$(CONFIG_MMC_WRITE) += image-sparse.o endifIsn't this just move image-sparse to lib and add a separate guard for it (
LIB_IMAGE_SPARSE?) which can be selected by both FASTBOOT and a new command symbol (CMD_MMC_SWRITE)?
Quoted 3 lines
This is all overlapping with the UDP fastboot code I've been posting, so I'd kinda like it to fit nicely with that, rather than have to refactor it to fit something different!
That sounds like a good idea to me, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180514/44e1f35e/attachment.sig>
PATCH 3/3 mmc: support writing sparse images
Quoted 7 lines · Tom Rini
Quoted 6 lines · Alex Kiernan
Quoted 4 lines · Tom Rini
Quoted 3 lines · Jassi Brar
Hi Tom,
On Tue, May 8, 2018 at 10:45 PM, Tom Rini <[email protected]>
Quoted 11 lines · wrote:
Quoted 11 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
On Fri, Apr 06, 2018 at 12:05:24PM +0530, jassisinghbrar at gmail.com
Quoted 9 lines · wrote:
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
From: Jassi Brar <[email protected]>
Provide an alternate path for sparse-images to be written to MMC. For example, via tftp on platforms that don't support fastboot protocol. Or when an image is to written at some offset, rather than the start of a partition.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Jassi Brar <[email protected]>Applied to u-boot/master, thanks!
I see you modified the patch to protect the feature with
CONFIG_FASTBOOT_FLASH, which kills the purpose -- this feature is
for
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
platforms that don't support fastboot.
Do you want me to send the patch to revert the protection?
Sorry, I guess maybe things weren't clear enough all around, and we should (functionally) revert patches 2 and 3 and try something different. It is OK to say "lets make writing sparse images more
widely
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
available". It's not OK to make every platform with MMC write grow a decent bit in binary size. Making a quick pass at re-enabling things
on
Quoted 1 line
Quoted 1 line
Quoted 1 line
a platform without fastboot support already grew things by nearly
2KiB.
Quoted 1 line
Quoted 1 line
Quoted 1 line
The other part which is I believe got me down this path was that
without
Quoted 20 lines
Quoted 20 lines
Quoted 10 lines
a change to common/Makefile to always (outside of SPL) include
common/image-sparse.othings don't link.In sum, a new patch to add an option to allow people to opt-in for swrite would be good. And please make sure to do something like:
common/Makefile +0
-0common/Makefile ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV · line 124
Quoted 5 lines
common/Makefile +1
-0@@ -120,6 +120,7 @@ ifdef CONFIG_FASTBOOT_FLASH_NAND_DEV obj-y += fb_nand.o endif endif +obj-$(CONFIG_MMC_WRITE) += image-sparse.o endifIsn't this just move image-sparse to lib and add a separate guard for it (
LIB_IMAGE_SPARSE?) which can be selected by both FASTBOOT and a new command symbol (CMD_MMC_SWRITE)?
Quoted 2 lines
Quoted 2 lines
This is all overlapping with the UDP fastboot code I've been posting, so I'd kinda like it to fit nicely with that, rather than have to refactor
it
Quoted 3 lines
Quoted 1 line
to fit something different!
That sounds like a good idea to me, thanks!
I'll work it into that patch series... having just had a quick look at it, it's going to be easiest part way through it after I've done most of the Kconfig reworking.
Signature · 1 line
Alex Kiernan
cover Enable mmc to write sparse images
In reply to jassisinghbrar at gmail.comQuoted 19 lines · On Fri, Apr 6, 2018 at 12:04 PM, <[email protected]> wrote:
From: Jassi Brar <[email protected]>
Hi,
Having capability to flash sparse images from mmc subsystem could be useful.
For example, non-android/fastboot platforms could leverage the concept. Or some platforms that need to 'pull' updates (get images over tftp and flash using mmc). Or when we want to flash image at some non-zero offset from the start of a partition. Or simply when USB-Device has issues for fastboot to work (my itch).This patchset first cleans and makes
write_sparse_imageagnostic of
fastboot and then adds a new 'swrite' command to 'mmc'.Jassi Brar (3):
fastboot: sparse: remove redundant argument towrite_sparse_image
fastboot: sparse: makewrite_sparse_imageuseable for non-fastboot
mmc: support writing sparse images
Quoted 7 lines
cmd/mmc.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ common/fb_mmc.c | 7 +++-- common/fb_nand.c | 6 +++-- common/image-sparse.c | 69 +++++++++++++++++++++++--------------------------- include/image-sparse.h | 6 +++-- 5 files changed, 112 insertions(+), 43 deletions(-)
A polite reminder to look into the patchset please.
Thank