diff mbox series

[v2,2/3] ubivol_handler: always consider the 'static' flag

Message ID 20190508082254.5353-3-mk@mkio.de
State Accepted
Headers show
Series fixes and extensions to ubivol_handler | expand

Commit Message

Markus Klotzbuecher May 8, 2019, 8:22 a.m. UTC
Currently, the request to create a static ubi volume is ignored unless
the partition size changes. This patch changes the logic to always
recreate the volume if either the size or the type change.

Signed-off-by: Markus Klotzbuecher <markus.klotzbuecher@kistler.com>
Acked-by: Stefano Babic <sbabic@denx.de>
---
Changes in v2:
- Improved documentation for ubi partition keyword

 doc/source/sw-description.rst | 19 ++++++++++++-------
 handlers/ubivol_handler.c     | 27 ++++++++++++++++++---------
 2 files changed, 30 insertions(+), 16 deletions(-)

Comments

Stefano Babic May 17, 2019, 8:42 a.m. UTC | #1
On 08/05/19 10:22, Markus Klotzbuecher wrote:
> Currently, the request to create a static ubi volume is ignored unless
> the partition size changes. This patch changes the logic to always
> recreate the volume if either the size or the type change.
> 
> Signed-off-by: Markus Klotzbuecher <markus.klotzbuecher@kistler.com>
> Acked-by: Stefano Babic <sbabic@denx.de>
> ---
> Changes in v2:
> - Improved documentation for ubi partition keyword
> 
>  doc/source/sw-description.rst | 19 ++++++++++++-------
>  handlers/ubivol_handler.c     | 27 ++++++++++++++++++---------
>  2 files changed, 30 insertions(+), 16 deletions(-)
> 
> diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst
> index a019af4..23f6d34 100644
> --- a/doc/source/sw-description.rst
> +++ b/doc/source/sw-description.rst
> @@ -583,13 +583,18 @@ in kernel.
>  		},
>  	);
>  
> -All fields are mandatory. SWUpdate searches for a volume of the
> -selected name and adjusts the size, or creates a new volume if
> -no volume with the given name exists. In the latter case, it is
> -created on the UBI device attached to the MTD device given by
> -"device". "device" can be given by number (e.g. "mtd4") or by name
> -(the name of the MTD device, e.g. "ubi_partition"). The UBI device
> -is attached automatically.
> +All fields are mandatory. SWUpdate searches for a volume of the given
> +name and if necessary adjusts size or type (see below). If no volume
> +with the given name is found, a new volume is created on the UBI
> +device attached to the MTD device given by ``device``. ``device`` can
> +be specified by number (e.g. "mtd4") or by name (the name of the MTD
> +device, e.g. "ubi_partition"). The UBI device is attached
> +automatically.
> +
> +The default behavior of swupdate is to create a dynamic UBI volume. To
> +create a static volume, add a line ``data = "static";`` to the
> +respective partition entry.
> +
>  
>  images
>  ------
> diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c
> index 62d9aea..51d9e65 100644
> --- a/handlers/ubivol_handler.c
> +++ b/handlers/ubivol_handler.c
> @@ -158,11 +158,17 @@ static int adjust_volume(struct img_type *cfg,
>  	struct ubi_part *ubivol;
>  	struct ubi_mkvol_request req;
>  	struct mtd_ubi_info *mtd_info;
> -	int mtdnum;
> +	int mtdnum, req_vol_type;
>  	char node[64];
>  	int err;
>  	struct flash_description *flash = get_flash_info();
>  
> +	/* determine the requested volume type */
> +	if (!strcmp(cfg->type_data, "static"))
> +		req_vol_type = UBI_STATIC_VOLUME;
> +	else
> +		req_vol_type = UBI_DYNAMIC_VOLUME;
> +
>  	/*
>  	 * Partition are adjusted only in one MTD device
>  	 * Other MTD are not touched
> @@ -205,8 +211,12 @@ static int adjust_volume(struct img_type *cfg,
>  			((cfg->partsize % mtd_info->dev_info.leb_size) ? 1 : 0);
>  		allocated_lebs = ubivol->vol_info.rsvd_bytes / mtd_info->dev_info.leb_size;
>  
> -		if (requested_lebs == allocated_lebs)
> +		if (requested_lebs == allocated_lebs &&
> +		    req_vol_type == ubivol->vol_info.type) {
> +			TRACE("skipping volume %s (same size and type)",
> +			      ubivol->vol_info.name);
>  			return 0;
> +		}
>  
>  		snprintf(node, sizeof(node), "/dev/ubi%d", ubivol->vol_info.dev_num);
>  		err = ubi_rmvol(nandubi->libubi, node, ubivol->vol_info.vol_id);
> @@ -228,17 +238,15 @@ static int adjust_volume(struct img_type *cfg,
>  	 * Volumes are empty, and they are filled later by the update procedure
>  	 */
>  	memset(&req, 0, sizeof(req));
> -	if (!strcmp(cfg->type_data, "static"))
> -		req.vol_type = UBI_STATIC_VOLUME;
> -	else
> -		req.vol_type = UBI_DYNAMIC_VOLUME;
> +	req.vol_type = req_vol_type;
>  	req.vol_id = UBI_VOL_NUM_AUTO;
>  	req.alignment = 1;
>  	req.bytes = cfg->partsize;
>  	req.name = cfg->volname;
>  	err = ubi_mkvol(nandubi->libubi, node, &req);
>  	if (err < 0) {
> -		ERROR("cannot create UBIvolume %s of %lld bytes",
> +		ERROR("cannot create %s UBI volume %s of %lld bytes",
> +		      (req_vol_type == UBI_DYNAMIC_VOLUME) ? "dynamic" : "static",
>  			req.name, req.bytes);
>  		return err;
>  	}
> @@ -257,8 +265,9 @@ static int adjust_volume(struct img_type *cfg,
>  		return err;
>  	}
>  	LIST_INSERT_HEAD(&mtd_info->ubi_partitions, ubivol, next);
> -	TRACE("Created UBI Volume %s of %lld bytes (requested %lld)",
> -		req.name, ubivol->vol_info.rsvd_bytes, req.bytes);
> +	TRACE("Created %s UBI volume %s of %lld bytes (old size %lld)",
> +	      (req_vol_type == UBI_DYNAMIC_VOLUME) ? "dynamic" : "static",
> +	      req.name, req.bytes, ubivol->vol_info.rsvd_bytes);
>  
>  	return 0;
>  }
> 

Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst
index a019af4..23f6d34 100644
--- a/doc/source/sw-description.rst
+++ b/doc/source/sw-description.rst
@@ -583,13 +583,18 @@  in kernel.
 		},
 	);
 
-All fields are mandatory. SWUpdate searches for a volume of the
-selected name and adjusts the size, or creates a new volume if
-no volume with the given name exists. In the latter case, it is
-created on the UBI device attached to the MTD device given by
-"device". "device" can be given by number (e.g. "mtd4") or by name
-(the name of the MTD device, e.g. "ubi_partition"). The UBI device
-is attached automatically.
+All fields are mandatory. SWUpdate searches for a volume of the given
+name and if necessary adjusts size or type (see below). If no volume
+with the given name is found, a new volume is created on the UBI
+device attached to the MTD device given by ``device``. ``device`` can
+be specified by number (e.g. "mtd4") or by name (the name of the MTD
+device, e.g. "ubi_partition"). The UBI device is attached
+automatically.
+
+The default behavior of swupdate is to create a dynamic UBI volume. To
+create a static volume, add a line ``data = "static";`` to the
+respective partition entry.
+
 
 images
 ------
diff --git a/handlers/ubivol_handler.c b/handlers/ubivol_handler.c
index 62d9aea..51d9e65 100644
--- a/handlers/ubivol_handler.c
+++ b/handlers/ubivol_handler.c
@@ -158,11 +158,17 @@  static int adjust_volume(struct img_type *cfg,
 	struct ubi_part *ubivol;
 	struct ubi_mkvol_request req;
 	struct mtd_ubi_info *mtd_info;
-	int mtdnum;
+	int mtdnum, req_vol_type;
 	char node[64];
 	int err;
 	struct flash_description *flash = get_flash_info();
 
+	/* determine the requested volume type */
+	if (!strcmp(cfg->type_data, "static"))
+		req_vol_type = UBI_STATIC_VOLUME;
+	else
+		req_vol_type = UBI_DYNAMIC_VOLUME;
+
 	/*
 	 * Partition are adjusted only in one MTD device
 	 * Other MTD are not touched
@@ -205,8 +211,12 @@  static int adjust_volume(struct img_type *cfg,
 			((cfg->partsize % mtd_info->dev_info.leb_size) ? 1 : 0);
 		allocated_lebs = ubivol->vol_info.rsvd_bytes / mtd_info->dev_info.leb_size;
 
-		if (requested_lebs == allocated_lebs)
+		if (requested_lebs == allocated_lebs &&
+		    req_vol_type == ubivol->vol_info.type) {
+			TRACE("skipping volume %s (same size and type)",
+			      ubivol->vol_info.name);
 			return 0;
+		}
 
 		snprintf(node, sizeof(node), "/dev/ubi%d", ubivol->vol_info.dev_num);
 		err = ubi_rmvol(nandubi->libubi, node, ubivol->vol_info.vol_id);
@@ -228,17 +238,15 @@  static int adjust_volume(struct img_type *cfg,
 	 * Volumes are empty, and they are filled later by the update procedure
 	 */
 	memset(&req, 0, sizeof(req));
-	if (!strcmp(cfg->type_data, "static"))
-		req.vol_type = UBI_STATIC_VOLUME;
-	else
-		req.vol_type = UBI_DYNAMIC_VOLUME;
+	req.vol_type = req_vol_type;
 	req.vol_id = UBI_VOL_NUM_AUTO;
 	req.alignment = 1;
 	req.bytes = cfg->partsize;
 	req.name = cfg->volname;
 	err = ubi_mkvol(nandubi->libubi, node, &req);
 	if (err < 0) {
-		ERROR("cannot create UBIvolume %s of %lld bytes",
+		ERROR("cannot create %s UBI volume %s of %lld bytes",
+		      (req_vol_type == UBI_DYNAMIC_VOLUME) ? "dynamic" : "static",
 			req.name, req.bytes);
 		return err;
 	}
@@ -257,8 +265,9 @@  static int adjust_volume(struct img_type *cfg,
 		return err;
 	}
 	LIST_INSERT_HEAD(&mtd_info->ubi_partitions, ubivol, next);
-	TRACE("Created UBI Volume %s of %lld bytes (requested %lld)",
-		req.name, ubivol->vol_info.rsvd_bytes, req.bytes);
+	TRACE("Created %s UBI volume %s of %lld bytes (old size %lld)",
+	      (req_vol_type == UBI_DYNAMIC_VOLUME) ? "dynamic" : "static",
+	      req.name, req.bytes, ubivol->vol_info.rsvd_bytes);
 
 	return 0;
 }