Message ID | 20190428085128.8479-3-frank-w@public-files.de |
---|---|
State | Superseded |
Delegated to: | Tom Rini |
Headers | show |
Series | add command env erase | expand |
Am 28.04.2019 um 10:51 schrieb Frank Wunderlich: > this adds erase environment for mmc storage > > Signed-off-by: Frank Wunderlich <frank-w@public-files.de> I think this is still too complex. I'd drop patches 3/4 and 4/4 and just erase both redundant storages here in env/mmc.c by calling the actual erase function twice. To do that, it would help to do as I suggested in response to v3: copy the 2-function style used by the save env code, then you can just call that 2nd function twice with a different offset (all in env/mmc.c). Regards, Simon > > squashed fixes: > - fix bogus indent > - add CONFIG_CMD_ERASEENV > > Suggested-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> > =2D-- > env/mmc.c | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > > diff --git a/env/mmc.c b/env/mmc.c > index c3cf35d01b..9ae9b1a66a 100644 > =2D-- a/env/mmc.c > +++ b/env/mmc.c > @@ -242,6 +242,34 @@ fini: > fini_mmc_for_env(mmc); > return ret; > } > + > +#if defined(CONFIG_CMD_ERASEENV) > +static int env_mmc_erase(void) > +{ > + int dev =3D mmc_get_env_dev(); > + struct mmc *mmc =3D find_mmc_device(dev); > + int n, blk, cnt; > + > + if (!mmc) > + return CMD_RET_FAILURE; > + > + blk =3D CONFIG_ENV_OFFSET / mmc->read_bl_len; > + cnt =3D CONFIG_ENV_SIZE / mmc->read_bl_len; > + > + printf("\nMMC erase env: dev # %d, block # %d (0x%x), count %d (0x%x)\n"= > , > + dev, blk, blk * mmc->read_bl_len, > + cnt, cnt * mmc->read_bl_len); > + > + if (mmc_getwp(mmc) =3D=3D 1) { > + printf("Error: card is write protected!\n"); > + return CMD_RET_FAILURE; > + } > + n =3D blk_derase(mmc_get_blk_desc(mmc), blk, cnt); > + printf("%d blocks erased: %s\n", n, (n =3D=3D cnt) ? "OK" : "ERROR"); > + > + return (n =3D=3D cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; > +} > +#endif /* CONFIG_CMD_ERASEENV */ > #endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */ > > static inline int read_env(struct mmc *mmc, unsigned long size, > @@ -351,5 +379,8 @@ U_BOOT_ENV_LOCATION(mmc) =3D { > .load =3D env_mmc_load, > #ifndef CONFIG_SPL_BUILD > .save =3D env_save_ptr(env_mmc_save), > +#if defined(CONFIG_CMD_ERASEENV) > + .erase =3D env_mmc_erase, > +#endif > #endif > }; > =2D- > 2.17.1 >
You mean passing the offset (normal/redundant) instead of a bool? Am 24. Juni 2019 21:40:36 MESZ schrieb Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>: >Am 28.04.2019 um 10:51 schrieb Frank Wunderlich: >> this adds erase environment for mmc storage >> >> Signed-off-by: Frank Wunderlich <frank-w@public-files.de> > >I think this is still too complex. > >I'd drop patches 3/4 and 4/4 and just erase both redundant storages >here >in env/mmc.c by calling the actual erase function twice. > >To do that, it would help to do as I suggested in response to v3: copy >the 2-function style used by the save env code, then you can just call >that 2nd function twice with a different offset (all in env/mmc.c). > >Regards, >Simon > >> >> squashed fixes: >> - fix bogus indent >> - add CONFIG_CMD_ERASEENV >> >> Suggested-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> >> =2D-- >> env/mmc.c | 31 +++++++++++++++++++++++++++++++ >> 1 file changed, 31 insertions(+) >> >> diff --git a/env/mmc.c b/env/mmc.c >> index c3cf35d01b..9ae9b1a66a 100644 >> =2D-- a/env/mmc.c >> +++ b/env/mmc.c >> @@ -242,6 +242,34 @@ fini: >> fini_mmc_for_env(mmc); >> return ret; >> } >> + >> +#if defined(CONFIG_CMD_ERASEENV) >> +static int env_mmc_erase(void) >> +{ >> + int dev =3D mmc_get_env_dev(); >> + struct mmc *mmc =3D find_mmc_device(dev); >> + int n, blk, cnt; >> + >> + if (!mmc) >> + return CMD_RET_FAILURE; >> + >> + blk =3D CONFIG_ENV_OFFSET / mmc->read_bl_len; >> + cnt =3D CONFIG_ENV_SIZE / mmc->read_bl_len; >> + >> + printf("\nMMC erase env: dev # %d, block # %d (0x%x), count %d >(0x%x)\n"= >> , >> + dev, blk, blk * mmc->read_bl_len, >> + cnt, cnt * mmc->read_bl_len); >> + >> + if (mmc_getwp(mmc) =3D=3D 1) { >> + printf("Error: card is write protected!\n"); >> + return CMD_RET_FAILURE; >> + } >> + n =3D blk_derase(mmc_get_blk_desc(mmc), blk, cnt); >> + printf("%d blocks erased: %s\n", n, (n =3D=3D cnt) ? "OK" : >"ERROR"); >> + >> + return (n =3D=3D cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; >> +} >> +#endif /* CONFIG_CMD_ERASEENV */ >> #endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */ >> >> static inline int read_env(struct mmc *mmc, unsigned long size, >> @@ -351,5 +379,8 @@ U_BOOT_ENV_LOCATION(mmc) =3D { >> .load =3D env_mmc_load, >> #ifndef CONFIG_SPL_BUILD >> .save =3D env_save_ptr(env_mmc_save), >> +#if defined(CONFIG_CMD_ERASEENV) >> + .erase =3D env_mmc_erase, >> +#endif >> #endif >> }; >> =2D- >> 2.17.1 >>
Frank Wunderlich <frank-w@public-files.de> schrieb am Mo., 24. Juni 2019, 22:09: > You mean passing the offset (normal/redundant) instead of a bool? > Would you mind keeping the mail style of this list and stop top-responses please? I don't care where you make the difference between bool and actual offset, but you should keep all this as a changeset to env/mmc.c only to keep it consistent to existing redundant env code. Don't expose the bool to the env driver interface or the command file. Regards, Simon > Am 24. Juni 2019 21:40:36 MESZ schrieb Simon Goldschmidt < > simon.k.r.goldschmidt@gmail.com>: > >Am 28.04.2019 um 10:51 schrieb Frank Wunderlich: > >> this adds erase environment for mmc storage > >> > >> Signed-off-by: Frank Wunderlich <frank-w@public-files.de> > > > >I think this is still too complex. > > > >I'd drop patches 3/4 and 4/4 and just erase both redundant storages > >here > >in env/mmc.c by calling the actual erase function twice. > > > >To do that, it would help to do as I suggested in response to v3: copy > >the 2-function style used by the save env code, then you can just call > >that 2nd function twice with a different offset (all in env/mmc.c). > > > >Regards, > >Simon > > > >> > >> squashed fixes: > >> - fix bogus indent > >> - add CONFIG_CMD_ERASEENV > >> > >> Suggested-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> > >> =2D-- > >> env/mmc.c | 31 +++++++++++++++++++++++++++++++ > >> 1 file changed, 31 insertions(+) > >> > >> diff --git a/env/mmc.c b/env/mmc.c > >> index c3cf35d01b..9ae9b1a66a 100644 > >> =2D-- a/env/mmc.c > >> +++ b/env/mmc.c > >> @@ -242,6 +242,34 @@ fini: > >> fini_mmc_for_env(mmc); > >> return ret; > >> } > >> + > >> +#if defined(CONFIG_CMD_ERASEENV) > >> +static int env_mmc_erase(void) > >> +{ > >> + int dev =3D mmc_get_env_dev(); > >> + struct mmc *mmc =3D find_mmc_device(dev); > >> + int n, blk, cnt; > >> + > >> + if (!mmc) > >> + return CMD_RET_FAILURE; > >> + > >> + blk =3D CONFIG_ENV_OFFSET / mmc->read_bl_len; > >> + cnt =3D CONFIG_ENV_SIZE / mmc->read_bl_len; > >> + > >> + printf("\nMMC erase env: dev # %d, block # %d (0x%x), count %d > >(0x%x)\n"= > >> , > >> + dev, blk, blk * mmc->read_bl_len, > >> + cnt, cnt * mmc->read_bl_len); > >> + > >> + if (mmc_getwp(mmc) =3D=3D 1) { > >> + printf("Error: card is write protected!\n"); > >> + return CMD_RET_FAILURE; > >> + } > >> + n =3D blk_derase(mmc_get_blk_desc(mmc), blk, cnt); > >> + printf("%d blocks erased: %s\n", n, (n =3D=3D cnt) ? "OK" : > >"ERROR"); > >> + > >> + return (n =3D=3D cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE; > >> +} > >> +#endif /* CONFIG_CMD_ERASEENV */ > >> #endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */ > >> > >> static inline int read_env(struct mmc *mmc, unsigned long size, > >> @@ -351,5 +379,8 @@ U_BOOT_ENV_LOCATION(mmc) =3D { > >> .load =3D env_mmc_load, > >> #ifndef CONFIG_SPL_BUILD > >> .save =3D env_save_ptr(env_mmc_save), > >> +#if defined(CONFIG_CMD_ERASEENV) > >> + .erase =3D env_mmc_erase, > >> +#endif > >> #endif > >> }; > >> =2D- > >> 2.17.1 > >> >
diff --git a/env/mmc.c b/env/mmc.c index c3cf35d01b..9ae9b1a66a 100644 --- a/env/mmc.c +++ b/env/mmc.c @@ -242,6 +242,34 @@ fini: fini_mmc_for_env(mmc); return ret; } + +#if defined(CONFIG_CMD_ERASEENV) +static int env_mmc_erase(void) +{ + int dev = mmc_get_env_dev(); + struct mmc *mmc = find_mmc_device(dev); + int n, blk, cnt; + + 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%x), count %d (0x%x)\n", + dev, 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 /* CONFIG_CMD_ERASEENV */ #endif /* CONFIG_CMD_SAVEENV && !CONFIG_SPL_BUILD */ static inline int read_env(struct mmc *mmc, unsigned long size, @@ -351,5 +379,8 @@ U_BOOT_ENV_LOCATION(mmc) = { .load = env_mmc_load, #ifndef CONFIG_SPL_BUILD .save = env_save_ptr(env_mmc_save), +#if defined(CONFIG_CMD_ERASEENV) + .erase = env_mmc_erase, +#endif #endif };
this adds erase environment for mmc storage Signed-off-by: Frank Wunderlich <frank-w@public-files.de> squashed fixes: - fix bogus indent - add CONFIG_CMD_ERASEENV Suggested-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> --- env/mmc.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) -- 2.17.1