Message ID | 20190406181235.7666-1-frank-w@public-files.de |
---|---|
State | Superseded |
Delegated to: | Tom Rini |
Headers | show |
Series | [U-Boot] mmc: add eraseenv command | expand |
Hi Frank, On 06/04/19 20:12, Frank Wunderlich wrote: > "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 > Signed-off-by: Frank Wunderlich <frank-w@public-files.de> > --- > cmd/mmc.c | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/cmd/mmc.c b/cmd/mmc.c > index 8bc3648193..b8e2c353b4 100644 > --- a/cmd/mmc.c > +++ b/cmd/mmc.c > @@ -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@lists.denx.de > https://lists.denx.de/listinfo/u-boot >
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 <sbabic@denx.de>: >Hi Frank, > >On 06/04/19 20:12, Frank Wunderlich wrote: >> "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 /.. ?
Hi Frank, On 07/04/19 17:20, Frank Wunderlich wrote: > 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 > Regards Frank > > Am 7. April 2019 14:55:42 MESZ schrieb Stefano Babic <sbabic@denx.de>: >> Hi Frank, >> >> On 06/04/19 20:12, Frank Wunderlich wrote: >>> "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 /.. ?
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 > Gesendet: Sonntag, 07. April 2019 um 17:58 Uhr > Von: "Stefano Babic" <sbabic@denx.de> > IMHO the U_BOOT_ENV_LOCATION should be extended to add a new function > pointer, and the generic command calls it.
Am 07.04.2019 um 19:32 schrieb Frank Wunderlich: > started to include erase in the global scope...hope i'm right. > > https://github.com/frank-w/u-boot/commits/eraseenv_new Yes, that looks like the correct approach. > > 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 > > regards Frank > > >> Gesendet: Sonntag, 07. April 2019 um 17:58 Uhr >> Von: "Stefano Babic" <sbabic@denx.de> >> IMHO the U_BOOT_ENV_LOCATION should be extended to add a new function >> pointer, and the generic command calls it.
diff --git a/cmd/mmc.c b/cmd/mmc.c index 8bc3648193..b8e2c353b4 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -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"
"mmc eraseenv" allows to erase the section on mmc where env is stored Signed-off-by: Frank Wunderlich <frank-w@public-files.de> --- cmd/mmc.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) -- 2.17.1