Message ID | 1596010394-32623-1-git-send-email-philippe.reynes@softathome.com |
---|---|
State | Accepted |
Headers | show |
Series | [v2] handlers: ubivol: add property always-remove | expand |
On 29.07.20 10:13, Philippe Reynes wrote: > This commit add the property always-remove > for the ubi volume handler. Before flashing > an image on an ubi volume, this ubi volume > is removed. This propoerty should be used > with property auto-resize to force the ubi > volume to be removed and created. > > Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> > --- > > Changelog: > v2: > - avoid adding a new function remove_volume, simply modify a check > in resize_volume > > doc/source/handlers.rst | 20 ++++++++++++++++++++ > handlers/ubivol_handler.c | 22 +++++++++++++++++++++- > 2 files changed, 41 insertions(+), 1 deletion(-) > > diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst > index 629bece..bb38037 100644 > --- a/doc/source/handlers.rst > +++ b/doc/source/handlers.rst > @@ -208,6 +208,26 @@ on an image, the ubi volume is resized to fit exactly the image. > > WARNING: when this property is used, the device must be defined. > > +volume always remove > +.................... > + > +The UBI volume handler has support to always remove ubi volume > +before flashing with the property ``always-remove``. When this property > +is set on an image, the ubi volume is always removed. This property > +should be used with property ``auto-resize``. > + > +:: > + > + { > + filename = "u-boot.img"; > + device = "mtd0"; > + volume = "u-boot_r"; > + properties: { > + always-remove = "true"; > + auto-resize = "true"; > + } > + } > + > Lua Handlers > ------------ > > diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c > index 008e9f7..5cfc0dd 100644 > --- a/handlers/ubivol_handler.c > +++ b/handlers/ubivol_handler.c > @@ -128,6 +128,25 @@ static int swap_volnames(libubi_t libubi, > return ubi_rnvols(libubi, masternode, &rnvol); > } > > +/** > + * check_ubi_alwaysremove - check the property always-remove for this image > + * @img: image information > + * > + * Return: 1 if the property always-remove is true, otherwise 0. > + */ > +static int check_ubi_alwaysremove(struct img_type *img) > +{ > + char *always; > + int ret = 0; > + > + always = dict_get_value(&img->properties, "always-remove"); > + > + if (always && !strcmp(always, "true")) > + ret = 1; > + > + return ret; > +} > + > static int update_volume(libubi_t libubi, struct img_type *img, > struct ubi_vol_info *vol) > { > @@ -289,7 +308,8 @@ static int resize_volume(struct img_type *cfg, long long size) > allocated_lebs = ubivol->vol_info.rsvd_bytes / mtd_info->dev_info.leb_size; > > if (requested_lebs == allocated_lebs && > - req_vol_type == ubivol->vol_info.type) { > + req_vol_type == ubivol->vol_info.type && > + !check_ubi_alwaysremove(cfg)) { > TRACE("skipping volume %s (same size and type)", > ubivol->vol_info.name); > return 0; > Reviewed-by: Stefano Babic <sbabic@denx.de> Best regards, Stefano Babic
diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst index 629bece..bb38037 100644 --- a/doc/source/handlers.rst +++ b/doc/source/handlers.rst @@ -208,6 +208,26 @@ on an image, the ubi volume is resized to fit exactly the image. WARNING: when this property is used, the device must be defined. +volume always remove +.................... + +The UBI volume handler has support to always remove ubi volume +before flashing with the property ``always-remove``. When this property +is set on an image, the ubi volume is always removed. This property +should be used with property ``auto-resize``. + +:: + + { + filename = "u-boot.img"; + device = "mtd0"; + volume = "u-boot_r"; + properties: { + always-remove = "true"; + auto-resize = "true"; + } + } + Lua Handlers ------------ diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c index 008e9f7..5cfc0dd 100644 --- a/handlers/ubivol_handler.c +++ b/handlers/ubivol_handler.c @@ -128,6 +128,25 @@ static int swap_volnames(libubi_t libubi, return ubi_rnvols(libubi, masternode, &rnvol); } +/** + * check_ubi_alwaysremove - check the property always-remove for this image + * @img: image information + * + * Return: 1 if the property always-remove is true, otherwise 0. + */ +static int check_ubi_alwaysremove(struct img_type *img) +{ + char *always; + int ret = 0; + + always = dict_get_value(&img->properties, "always-remove"); + + if (always && !strcmp(always, "true")) + ret = 1; + + return ret; +} + static int update_volume(libubi_t libubi, struct img_type *img, struct ubi_vol_info *vol) { @@ -289,7 +308,8 @@ static int resize_volume(struct img_type *cfg, long long size) allocated_lebs = ubivol->vol_info.rsvd_bytes / mtd_info->dev_info.leb_size; if (requested_lebs == allocated_lebs && - req_vol_type == ubivol->vol_info.type) { + req_vol_type == ubivol->vol_info.type && + !check_ubi_alwaysremove(cfg)) { TRACE("skipping volume %s (same size and type)", ubivol->vol_info.name); return 0;
This commit add the property always-remove for the ubi volume handler. Before flashing an image on an ubi volume, this ubi volume is removed. This propoerty should be used with property auto-resize to force the ubi volume to be removed and created. Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> --- Changelog: v2: - avoid adding a new function remove_volume, simply modify a check in resize_volume doc/source/handlers.rst | 20 ++++++++++++++++++++ handlers/ubivol_handler.c | 22 +++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-)