public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Henning Schild <henning.schild@siemens.com>
To: isar-users@googlegroups.com
Cc: Henning Schild <henning.schild@siemens.com>
Subject: [PATCH 1/9] classes: image: introduce size measuring function, for before do_*_image
Date: Wed, 31 Jan 2018 10:41:52 +0100	[thread overview]
Message-ID: <a2acd8e35f07f2bf1869463ea368cd1a6b1a164b.1517390790.git.henning.schild@siemens.com> (raw)
In-Reply-To: <cover.1517390790.git.henning.schild@siemens.com>
In-Reply-To: <cover.1517390790.git.henning.schild@siemens.com>

Measure the size and export it to the variable ROOTFS_SIZE just before
the imaging step. The concept is inspired by OE.

Issue:
The size of the rootfs is required for all sort of images, at the moment
Isar only supports one "real" image. Later patches will introduce
another image. And this patch prepares for that by moving the size
measurement into our image base class.

Impact:
 - Issue is solved
 - nothing changes for users

Signed-off-by: Henning Schild <henning.schild@siemens.com>
---
 meta/classes/ext4-img.bbclass |  7 ++-----
 meta/classes/image.bbclass    | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/meta/classes/ext4-img.bbclass b/meta/classes/ext4-img.bbclass
index 83cb137..78036a2 100644
--- a/meta/classes/ext4-img.bbclass
+++ b/meta/classes/ext4-img.bbclass
@@ -1,9 +1,6 @@
 # This software is a part of ISAR.
 # Copyright (C) 2015-2017 ilbers GmbH
 
-# Extra space for rootfs in MB
-ROOTFS_EXTRA ?= "64"
-
 EXT4_IMAGE_FILE = "${DEPLOY_DIR_IMAGE}/${PN}-${DISTRO}-${MACHINE}.ext4.img"
 
 do_ext4_image[stamp-extra-info] = "${DISTRO}-${MACHINE}"
@@ -12,8 +9,7 @@ do_ext4_image[stamp-extra-info] = "${DISTRO}-${MACHINE}"
 do_ext4_image() {
     rm -f ${EXT4_IMAGE_FILE}
 
-    ROOTFS_SIZE=`sudo du -sm ${IMAGE_ROOTFS} |  awk '{print $1 + ${ROOTFS_EXTRA};}'`
-    dd if=/dev/zero of=${EXT4_IMAGE_FILE} bs=1M count=${ROOTFS_SIZE}
+    dd if=/dev/zero of=${EXT4_IMAGE_FILE} bs=1k count=${ROOTFS_SIZE}
 
     sudo mkfs.ext4 -F ${EXT4_IMAGE_FILE}
 
@@ -31,3 +27,4 @@ do_ext4_image() {
 }
 
 addtask ext4_image before do_build after do_copy_boot_files
+do_ext4_image[prefuncs] = 'set_image_size'
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index e2cb01b..47fa553 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -5,6 +5,9 @@ IMAGE_INSTALL ?= ""
 IMAGE_TYPE    ?= "ext4-img"
 IMAGE_ROOTFS   = "${WORKDIR}/rootfs"
 
+# Extra space for rootfs in MB
+ROOTFS_EXTRA ?= "64"
+
 def get_image_name(d, name_link):
     S = d.getVar("IMAGE_ROOTFS", True)
     path_link = os.path.join(S, name_link)
@@ -12,6 +15,22 @@ def get_image_name(d, name_link):
         return os.path.basename(os.path.realpath(path_link))
     return ""
 
+def get_rootfs_size(d):
+    import subprocess
+    rootfs_extra = int(d.getVar("ROOTFS_EXTRA", True))
+
+    output = subprocess.check_output(['sudo', 'du', '-s', '--block-size=1k',
+                                      d.getVar("IMAGE_ROOTFS", True)])
+    base_size = int(output.split()[0])
+
+    return base_size + rootfs_extra * 1024
+
+python set_image_size () {
+    rootfs_size = get_rootfs_size(d)
+    d.setVar('ROOTFS_SIZE', str(rootfs_size))
+    d.setVarFlag('ROOTFS_SIZE', 'export', '1')
+}
+
 # These variables are used by wic and start_vm
 KERNEL_IMAGE ?= "${@get_image_name(d, 'vmlinuz')}"
 INITRD_IMAGE ?= "${@get_image_name(d, 'initrd.img')}"
-- 
2.13.6


  reply	other threads:[~2018-01-31  9:42 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-31  9:41 [PATCH 0/9] first wic integration Henning Schild
2018-01-31  9:41 ` Henning Schild [this message]
2018-01-31  9:41 ` [PATCH 2/9] images: new class wic-img for wic intregration Henning Schild
2018-02-13 14:44   ` Alexander Smirnov
2018-02-13 16:06     ` Henning Schild
2018-01-31  9:41 ` [PATCH 3/9] wic: add a bootimg-efi-isar plugin outside the wic tree Henning Schild
2018-02-12 17:48   ` Jan Kiszka
2018-01-31  9:41 ` [PATCH 4/9] Revert "wic: Make the bootimg-efi plugin generate usable images" Henning Schild
2018-01-31  9:41 ` [PATCH 5/9] Revert "wic: Introduce the `WicExecError` exception class" Henning Schild
2018-01-31  9:41 ` [PATCH 6/9] Revert "wic: Work around mcopy error" Henning Schild
2018-01-31  9:41 ` [PATCH 7/9] Revert "wic: Use sudo instead of pseudo" Henning Schild
2018-01-31  9:41 ` [PATCH 8/9] Revert "wic: Remove sysroot support" Henning Schild
2018-01-31  9:42 ` [PATCH 9/9] wic: now truly go for the wic version we claim to have Henning Schild
2018-01-31 10:11   ` Alexander Smirnov
2018-01-31 10:55     ` Jan Kiszka
2018-01-31 11:11       ` Alexander Smirnov
2018-01-31 11:43         ` Jan Kiszka
2018-01-31 11:53           ` Baurzhan Ismagulov
2018-01-31 12:01             ` Jan Kiszka
2018-01-31 12:28               ` Baurzhan Ismagulov
2018-01-31 13:53                 ` Henning Schild
2018-01-31 14:01                   ` Baurzhan Ismagulov
2018-01-31 14:21                     ` Henning Schild
2018-01-31 10:02 ` [PATCH 0/9] first wic integration Alexander Smirnov
2018-01-31 10:12   ` Henning Schild
2018-01-31 11:24     ` Baurzhan Ismagulov
2018-01-31 11:47       ` Jan Kiszka
2018-01-31 12:02         ` Baurzhan Ismagulov
2018-01-31 12:15           ` Jan Kiszka
2018-01-31 13:30             ` Jan Kiszka
2018-01-31 13:41               ` Baurzhan Ismagulov
2018-01-31 14:01                 ` Jan Kiszka
2018-01-31 15:21                   ` Baurzhan Ismagulov
2018-01-31 15:46                     ` Henning Schild
2018-01-31 16:13                     ` Jan Kiszka
2018-01-31 13:35             ` Baurzhan Ismagulov
2018-01-31 13:47               ` Henning Schild
2018-01-31 14:00                 ` Baurzhan Ismagulov
2018-01-31 13:46             ` Henning Schild
2018-01-31 13:36           ` Henning Schild
2018-01-31 13:40             ` Baurzhan Ismagulov
2018-01-31 13:05       ` Henning Schild
2018-02-01 12:41 ` [PATCH] images: wic: limit use of sudo and enable manual call again Henning Schild
2018-02-01 12:44   ` Henning Schild
2018-02-01 16:09     ` Baurzhan Ismagulov
2018-02-01 18:10       ` Henning Schild
2018-02-01 18:55         ` Henning Schild
2018-02-12 19:07   ` Henning Schild
2018-02-12 17:27 ` [PATCH 0/9] first wic integration Henning Schild
2018-02-12 18:21   ` Alexander Smirnov
2018-02-12 18:30     ` Henning Schild

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a2acd8e35f07f2bf1869463ea368cd1a6b1a164b.1517390790.git.henning.schild@siemens.com \
    --to=henning.schild@siemens.com \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox