Skip to contentSkip to conversation

image_types.bbclass: Round up ROOTFS_SIZE after base_size check

PATCH Superseded Andrei Gherzan 2 participants 4 messages Sep 12, 2012

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover image_types.bbclass: Round up ROOTFS_SIZE after base_size check

V2:
Replace expr with awk. In this way an error like "expr: non-integer argument" is avoided.

The following changes since commit 0f55a5868457300a3defc7fa7451ef191d19e018:

adt-installer: Allow changing YOCTOADT_REPO (2012-09-05 23:28:10 +0100)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib ag/rootfs_size
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=ag/rootfs_size

Andrei Gherzan (1):
image_types.bbclass: Round up ROOTFS_SIZE after base_size check

 meta/classes/image_types.bbclass |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v2 1/1 image_types.bbclass: Round up ROOTFS_SIZE after base_size check

If we round up ROOTFS_SIZE to IMAGE_ROOTFS_ALIGNMENT before checking if base_size is greater then IMAGE_ROOTFS_SIZE, we can end up adding an unaligned value to IMAGE_ROOTFS_SIZE. Obviously, if IMAGE_ROOTFS_EXTRA_SPACE was overwritten with an unaligned value. So let's add the round up code after the base_size calculus and it's comparison.

---
 meta/classes/image_types.bbclass |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
meta/classes/image_types.bbclass +5 -2
index d286eea..6c01b21 100644
@@ -82,9 +82,12 @@ runimagecmd () {
 	# The base_size gets calculated:
 	#  - initial size determined by `du -ks` of the IMAGE_ROOTFS
 	#  - then multiplied by the IMAGE_OVERHEAD_FACTOR
-	#  - then rounded up to IMAGE_ROOTFS_ALIGNMENT
 	#  - finally tested against IMAGE_ROOTFS_SIZE
-	ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{base_size = $1 * ${IMAGE_OVERHEAD_FACTOR} + ${IMAGE_ROOTFS_ALIGNMENT} - 1; base_size -= base_size % ${IMAGE_ROOTFS_ALIGNMENT}; print ((base_size > ${IMAGE_ROOTFS_SIZE} ? base_size : ${IMAGE_ROOTFS_SIZE}) + ${IMAGE_ROOTFS_EXTRA_SPACE}) }'`
+	ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{base_size = $1 * ${IMAGE_OVERHEAD_FACTOR}; print ((base_size > ${IMAGE_ROOTFS_SIZE} ? base_size : ${IMAGE_ROOTFS_SIZE}) + ${IMAGE_ROOTFS_EXTRA_SPACE}) }'`
+
+	# Round up ROOTFS_SIZE to IMAGE_ROOTFS_ALIGNMENT
+	ROOTFS_SIZE=`awk "BEGIN { rootfs_size = $ROOTFS_SIZE + ${IMAGE_ROOTFS_ALIGNMENT} - 1; rootfs_size -= rootfs_size % ${IMAGE_ROOTFS_ALIGNMENT}; print rootfs_size }"`
+
 	${cmd}
 	# Now create the needed compressed versions
 	cd ${DEPLOY_DIR_IMAGE}/
Signature · 1 line
1.7.9.5
#2 lore raw
Quoted 18 lines · Andrei Gherzan

If we round up ROOTFS_SIZE to IMAGE_ROOTFS_ALIGNMENT before checking if base_size is greater then IMAGE_ROOTFS_SIZE, we can end up adding an unaligned value to IMAGE_ROOTFS_SIZE. Obviously, if IMAGE_ROOTFS_EXTRA_SPACE was overwritten with an unaligned value. So let's add the round up code after the base_size calculus and it's comparison.

---
  meta/classes/image_types.bbclass |    7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
meta/classes/image_types.bbclass +0 -0
index d286eea..6c01b21 100644
@@ -82,9 +82,12 @@ runimagecmd () {
  	# The base_size gets calculated:

meta/classes/image_types.bbclass runimagecmd () { · line 90

Quoted 10 lines
meta/classes/image_types.bbclass +5 -2
  	#  - initial size determined by `du -ks` of the IMAGE_ROOTFS
  	#  - then multiplied by the IMAGE_OVERHEAD_FACTOR
-	#  - then rounded up to IMAGE_ROOTFS_ALIGNMENT
  	#  - finally tested against IMAGE_ROOTFS_SIZE
-	ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{base_size = $1 * ${IMAGE_OVERHEAD_FACTOR} + ${IMAGE_ROOTFS_ALIGNMENT} - 1; base_size -= base_size % ${IMAGE_ROOTFS_ALIGNMENT}; print ((base_size > ${IMAGE_ROOTFS_SIZE} ? base_size : ${IMAGE_ROOTFS_SIZE}) + ${IMAGE_ROOTFS_EXTRA_SPACE}) }'`
+	ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{base_size = $1 * ${IMAGE_OVERHEAD_FACTOR}; print ((base_size > ${IMAGE_ROOTFS_SIZE} ? base_size : ${IMAGE_ROOTFS_SIZE}) + ${IMAGE_ROOTFS_EXTRA_SPACE}) }'`
+
+	# Round up ROOTFS_SIZE to IMAGE_ROOTFS_ALIGNMENT
+	ROOTFS_SIZE=`awk "BEGIN { rootfs_size = $ROOTFS_SIZE + ${IMAGE_ROOTFS_ALIGNMENT} - 1; rootfs_size -= rootfs_size % ${IMAGE_ROOTFS_ALIGNMENT}; print rootfs_size }"`
+

AWK seems a little heavy weight here, now we are forking it twice, since we are already in awk above, can you not just continue the function from there instead, maybe with a END{} or something else?

Also will this guarantee an Integer result?

Quoted 4 lines
meta/classes/image_types.bbclass +0 -0
  	${cmd}
  	# Now create the needed compressed versions
  	cd ${DEPLOY_DIR_IMAGE}/
#3 lore raw
Quoted 46 lines · Saul Wold
Quoted 34 lines · Andrei Gherzan

If we round up ROOTFS_SIZE to IMAGE_ROOTFS_ALIGNMENT before checking if base_size is greater then IMAGE_ROOTFS_SIZE, we can end up adding an unaligned value to IMAGE_ROOTFS_SIZE. Obviously, if IMAGE_ROOTFS_EXTRA_SPACE was overwritten with an unaligned value. So let's add the round up code after the base_size calculus and it's comparison.

---
  meta/classes/image_types.**bbclass |    7 +++++--
  1 file changed, 5 insertions(+), 2 deletions(-)
meta/classes/image_types.**bbclass +0 -2
index d286eea..6c01b21 100644
@@ -82,9 +82,12 @@ runimagecmd () {
        # The base_size gets calculated:
        #  - initial size determined by `du -ks` of the IMAGE_ROOTFS
        #  - then multiplied by the IMAGE_OVERHEAD_FACTOR
-       #  - then rounded up to IMAGE_ROOTFS_ALIGNMENT
        #  - finally tested against IMAGE_ROOTFS_SIZE
-       ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{base_size = $1 *

${IMAGE_OVERHEAD_FACTOR} + ${IMAGE_ROOTFS_ALIGNMENT} - 1; base_size -= base_size % ${IMAGE_ROOTFS_ALIGNMENT}; print ((base_size > ${IMAGE_ROOTFS_SIZE} ? base_size : ${IMAGE_ROOTFS_SIZE}) + ${IMAGE_ROOTFS_EXTRA_SPACE}) }'`
+ ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{base_size = $1 *
${IMAGE_OVERHEAD_FACTOR}; print ((base_size > ${IMAGE_ROOTFS_SIZE} ? base_size : ${IMAGE_ROOTFS_SIZE}) + ${IMAGE_ROOTFS_EXTRA_SPACE}) }'`

meta/classes/image_types.**bbclass +3 -0
+
+       # Round up ROOTFS_SIZE to IMAGE_ROOTFS_ALIGNMENT
+       ROOTFS_SIZE=`awk "BEGIN { rootfs_size = $ROOTFS_SIZE +
Quoted 4 lines

${IMAGE_ROOTFS_ALIGNMENT} - 1; rootfs_size -= rootfs_size % ${IMAGE_ROOTFS_ALIGNMENT}; print rootfs_size }"`
+

AWK seems a little heavy weight here, now we are forking it twice, since we are already in awk above, can you not just continue the function from there instead, maybe with a END{} or something else?

Quoted 1 line

So, to be sure i understood. You want to have the whole routine in the

same awk right? I did it this way to make those steps a little clearer. But indeed, this is a good idea in terms of performance.

Also will this guarantee an Integer result?

Quoted 1 line

Will fix in V3. :)

Branch updated with v3.

ag