All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 2/4] support/testing/infra: add img_round_power2() function
Date: Mon, 21 Jun 2021 22:25:44 +0200	[thread overview]
Message-ID: <20210621202547.360391-2-thomas.petazzoni@bootlin.com> (raw)
In-Reply-To: <20210621202547.360391-1-thomas.petazzoni@bootlin.com>

Since Qemu 5.1, SD card images must have a size that are a power of
two. While some filesystem (such as ext2/3/4) allow to specify the
expected size of the filesystem, others such as SquashFS do not have
this capability.

We were already extending the size of such images to the next 1 MB
boundary using "truncate -s %1M", but that is no longer sufficient. So
instead, we introduce a helper function that extends the size of an
image to the next power of two.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
---
 support/testing/infra/__init__.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/support/testing/infra/__init__.py b/support/testing/infra/__init__.py
index 6522a265f3..c540fd1940 100644
--- a/support/testing/infra/__init__.py
+++ b/support/testing/infra/__init__.py
@@ -112,3 +112,14 @@ def get_elf_prog_interpreter(builddir, prefix, fpath):
             continue
         return m.group(1)
     return None
+
+
+def img_round_power2(img):
+    """
+    Rounds up the size of an image file to the next power of 2
+    """
+    sz = os.stat(img).st_size
+    pow2 = 1
+    while pow2 < sz:
+        pow2 = pow2 << 1
+    subprocess.call(["truncate", "-s", str(pow2), img])
-- 
2.31.1

  reply	other threads:[~2021-06-21 20:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21 20:25 [Buildroot] [PATCH 1/4] support/testing/tests/fs/test_ext: specify 16 MB as ext filesystem size Thomas Petazzoni
2021-06-21 20:25 ` Thomas Petazzoni [this message]
2021-06-26 20:25   ` [Buildroot] [PATCH 2/4] support/testing/infra: add img_round_power2() function Yann E. MORIN
2021-06-21 20:25 ` [Buildroot] [PATCH 3/4] support/testing/tests: fix tests to use infra.img_round_power2() Thomas Petazzoni
2021-06-26 20:27   ` Yann E. MORIN
2021-06-21 20:25 ` [Buildroot] [PATCH 4/4] support/testing/tests/fs/test_ext: add missing "format" option for Qemu Thomas Petazzoni
2021-06-26 20:27   ` Yann E. MORIN
2021-06-26 20:23 ` [Buildroot] [PATCH 1/4] support/testing/tests/fs/test_ext: specify 16 MB as ext filesystem size Yann E. MORIN

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=20210621202547.360391-2-thomas.petazzoni@bootlin.com \
    --to=thomas.petazzoni@bootlin.com \
    --cc=buildroot@busybox.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.