mmc: add eraseenv command
PATCH 1/1 mmc: add eraseenv command
"mmc eraseenv" allows to erase the section on mmc where env is stored
--- cmd/mmc.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
cmd/mmc.c +33 -0
@@ -441,6 +441,37 @@ static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag,return (n == cnt) ?CMD_RET_SUCCESS :CMD_RET_FAILURE ; } + +static int do_mmc_erase_env (cmd_tbl_t *cmdtp,int flag, +int argc,char *const argv[]) +{ +struct mmc *mmc; +u32 blk, cnt, n; + +if (argc !=1 ) +return CMD_RET_USAGE ; + + mmc =init_mmc_device (curr_device, false); + +if (!mmc) +return CMD_RET_FAILURE ; + + blk =CONFIG_ENV_OFFSET / mmc->read_bl_len; + cnt =CONFIG_ENV_SIZE / mmc->read_bl_len; + +printf ("\nMMC erase env: dev # %d, block # %d (0x%8x), count %d (0x%8x)" , + curr_device, blk, blk * mmc->read_bl_len, + cnt, cnt * mmc->read_bl_len); + +if (mmc_getwp (mmc) ==1 ) { +printf ("Error: card is write protected!\n" ); +return CMD_RET_FAILURE ; + } + n =blk_derase (mmc_get_blk_desc (mmc), blk, cnt); +printf ("%d blocks erased: %s\n" , n, (n == cnt) ?"OK" :"ERROR" ); + +return (n == cnt) ?CMD_RET_SUCCESS :CMD_RET_FAILURE ; +}#endif static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag,
@@ -878,6 +909,7 @@ static cmd_tbl_t cmd_mmc[] = {#if CONFIG_IS_ENABLED (MMC_WRITE )U_BOOT_CMD_MKENT (write,4 ,0 , do_mmc_write,"" ,"" ),U_BOOT_CMD_MKENT (erase,3 ,0 , do_mmc_erase,"" ,"" ), +U_BOOT_CMD_MKENT (eraseenv,1 ,0 , do_mmc_erase_env,"" ,"" ), #endif #if CONFIG_IS_ENABLED(CMD_MMC_SWRITE) U_BOOT_CMD_MKENT(swrite, 3, 0, do_mmc_sparse_write, "", ""),
@@ -940,6 +972,7 @@ U_BOOT_CMD( "mmc swrite addr blk#\n"#endif "mmc erase blk# cnt\n" +"mmc eraseenv - erase environment\n" "mmc rescan\n" "mmc part - lists available partition on current mmc device\n" "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
--
2.17.1
PATCH 1/1 mmc: add eraseenv command
Hi Frank,
Quoted 2 lines · Frank Wunderlich
"mmc eraseenv" allows to erase the section on mmc where env is stored
Why do we need a specific command for MMC ? If we need such a command, should it not unaware of the storage ? That is a "env eraseenv", and this calls the corresponding function for SPI /MMC / NAND /.. ?
Best regards,
Stefano Babic
Quoted 71 lines
Signed-off-by Frank Wunderlich <[email protected]>--- cmd/mmc.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)cmd/mmc.c +33
-1@@ -441,6 +441,37 @@ static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag,return (n == cnt) ?CMD_RET_SUCCESS :CMD_RET_FAILURE ; } + +static int do_mmc_erase_env (cmd_tbl_t *cmdtp,int flag, +int argc,char *const argv[]) +{ +struct mmc *mmc; +u32 blk, cnt, n; + +if (argc !=1 ) +return CMD_RET_USAGE ; + + mmc =init_mmc_device (curr_device, false); + +if (!mmc) +return CMD_RET_FAILURE ; + + blk =CONFIG_ENV_OFFSET / mmc->read_bl_len; + cnt =CONFIG_ENV_SIZE / mmc->read_bl_len; + +printf ("\nMMC erase env: dev # %d, block # %d (0x%8x), count %d (0x%8x)" , + curr_device, blk, blk * mmc->read_bl_len, + cnt, cnt * mmc->read_bl_len); + +if (mmc_getwp (mmc) ==1 ) { +printf ("Error: card is write protected!\n" ); +return CMD_RET_FAILURE ; + } + n =blk_derase (mmc_get_blk_desc (mmc), blk, cnt); +printf ("%d blocks erased: %s\n" , n, (n == cnt) ?"OK" :"ERROR" ); + +return (n == cnt) ?CMD_RET_SUCCESS :CMD_RET_FAILURE ; +}#endif static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag,@@ -878,6 +909,7 @@ static cmd_tbl_t cmd_mmc[] = {#if CONFIG_IS_ENABLED (MMC_WRITE )U_BOOT_CMD_MKENT (write,4 ,0 , do_mmc_write,"" ,"" ),U_BOOT_CMD_MKENT (erase,3 ,0 , do_mmc_erase,"" ,"" ), +U_BOOT_CMD_MKENT (eraseenv,1 ,0 , do_mmc_erase_env,"" ,"" ), #endif #if CONFIG_IS_ENABLED(CMD_MMC_SWRITE) U_BOOT_CMD_MKENT(swrite, 3, 0, do_mmc_sparse_write, "", ""),@@ -940,6 +972,7 @@ U_BOOT_CMD( "mmc swrite addr blk#\n"#endif "mmc erase blk# cnt\n" +"mmc eraseenv - erase environment\n" "mmc rescan\n" "mmc part - lists available partition on current mmc device\n" "mmc dev [dev] [part] - show or set current mmc device [partition]\n" --2.17.1
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot
Signature · 5 lines
===================================================================== DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
PATCH 1/1 mmc: add eraseenv command
Hi Stefano,
I agree a global env erase which calls device-specific function is better than current implementation. I havn't figured out how i can implement it. Is there a simple example for this?
Regards Frank
Am 7. April 2019 14:55:42 MESZ schrieb Stefano Babic <[email protected]>:
Quoted 9 lines
Hi Frank,
Quoted 2 lines · Frank Wunderlich
"mmc eraseenv" allows to erase the section on mmc where env is stored
Why do we need a specific command for MMC ? If we need such a command, should it not unaware of the storage ? That is a "env eraseenv", and this calls the corresponding function for SPI /MMC / NAND /.. ?
PATCH 1/1 mmc: add eraseenv command
Hi Frank,
Quoted 4 lines · Frank Wunderlich
Hi Stefano,
I agree a global env erase which calls device-specific function is better than current implementation. I havn't figured out how i can implement it. Is there a simple example for this?
IMHO the U_BOOT_ENV_LOCATION should be extended to add a new function pointer, and the generic command calls it.
Regards,
Stefano
Quoted 12 lines
Regards Frank
Am 7. April 2019 14:55:42 MESZ schrieb Stefano Babic <[email protected]>:
Quoted 9 lines
Hi Frank,
Quoted 2 lines · Frank Wunderlich
"mmc eraseenv" allows to erase the section on mmc where env is stored
Why do we need a specific command for MMC ? If we need such a command, should it not unaware of the storage ? That is a "env eraseenv", and this calls the corresponding function for SPI /MMC / NAND /.. ?
Signature · 5 lines
===================================================================== DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de =====================================================================
A message that is not in the archive (sent off-list or not yet received): trinity-a55c8f4f-26b9-4729-9f37-b53b8ea6f5e5-1554658263983@3c-app-gmx-bs50
PATCH 1/1 mmc: add eraseenv command
started to include erase in the global scope...hope i'm right.
https://github.com/frank-w/u-boot/commits/eraseenv_new
where is the env-command (i need to add erase too) defined? i found no cmd/env*.[ch]...
regards Frank
Quoted 4 lines
Gesendet: Sonntag, 07. April 2019 um 17:58 Uhr
Von: "Stefano Babic" <[email protected]>
IMHO theU_BOOT_ENV_LOCATIONshould be extended to add a new function pointer, and the generic command calls it.
PATCH 1/1 mmc: add eraseenv command
Am 07.04.2019 um 19:32 schrieb Frank Wunderlich:
Quoted 3 lines
started to include erase in the global scope...hope i'm right.
Yes, that looks like the correct approach.
Quoted 2 lines
where is the env-command (i need to add erase too) defined? i found no cmd/env*.[ch]...
It's in cmd/nvedit.c, see function 'do_env'.
Regards,
Simon
Quoted 8 lines
regards Frank
Quoted 4 lines
Gesendet: Sonntag, 07. April 2019 um 17:58 Uhr
Von: "Stefano Babic" <[email protected]>
IMHO theU_BOOT_ENV_LOCATIONshould be extended to add a new function pointer, and the generic command calls it.