From nobody Sun Sep 28 16:34:15 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=jan.kiszka@siemens.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=siemens.com ARC-Seal: i=1; a=rsa-sha256; t=1756706944; cv=none; d=zohomail.com; s=zohoarc; b=SO6uYg1ZumohDT5yHNSMmy0jAIqN55mMTQEZy3jdgIFAvCv3KSJJwHJ0D0f1NIaUfcN5OrWT+j2QQ6bfEW7kVGnUuOzegGDNcLKNteQmk990XaWxiN37ELHDWQ7cE6jf0SKparsAFQVXDohDm7Ib5XbC6V5FXQgELAMYeb52D2M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756706944; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JTU3BFmS3GSE4uH8eM/o4TaOK5XUVgQEjgYT59J0ET0=; b=hwxPANk1JPUHuPBekOt4irEswtMiM1dvKGukC12De5ivdWKuTvAT6aUNn6NgM96oYcgTcmmTpV+GjnrXSt1Djo9E1F+68tf1fYr1hiBf+N6hdMsZt6JgAUZ2IbnWnpz9qUdumEUHoUyg0IV8eLYLzp3T/94Vr6hiywm26KUViCw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=jan.kiszka@siemens.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1756706944876837.6859668687305; Sun, 31 Aug 2025 23:09:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1usxgq-0003BF-K2; Mon, 01 Sep 2025 02:06:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1usxgi-00039j-15 for qemu-devel@nongnu.org; Mon, 01 Sep 2025 02:06:44 -0400 Received: from mta-64-227.siemens.flowmailer.net ([185.136.64.227]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1usxgc-0001xB-3K for qemu-devel@nongnu.org; Mon, 01 Sep 2025 02:06:43 -0400 Received: by mta-64-227.siemens.flowmailer.net with ESMTPSA id 20250901055632efa9c6209000020776 for ; Mon, 01 Sep 2025 07:56:32 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=jan.kiszka@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=JTU3BFmS3GSE4uH8eM/o4TaOK5XUVgQEjgYT59J0ET0=; b=Ls7GIhFFS2eXamz10t7Am6Lw5O6/i+FyGyISmYYbiFXrv5m2j+tsX3rGvuwvHckid7fx/u dFPceJKpGEi5wRDyCFKqEcefzVYciH88Yb5bTSZk7ovD+0p9H6R/eXdAS1Dj1I8mIpxoJTqd nDVlk3RXKgcG2TMSTPG5gx/8Bw5coFVCwK2YlXEvq4JxF1Eyl1kHTYa/17j6K8ZJXzhoj7Pg 8ZqUrphx7gC9sjmKa4UwRTFBJ1TBAc0djRf9kR157bdIV9uRI/hXSAVyyFDvfwdTBWTp7V+b Vu3b4AOvzx7vUFl4EG01v+5pQkI+go1jfXl+pXpk/GuCkM4fdGlH3ZWg==; From: Jan Kiszka To: qemu-devel Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Bin Meng , qemu-block@nongnu.org, Ilias Apalodimas Subject: [PATCH v2 8/8] scripts: Add helper script to generate eMMC block device images Date: Mon, 1 Sep 2025 07:56:28 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-294854:519-21489:flowmailer Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=185.136.64.227; envelope-from=fm-294854-20250901055632efa9c6209000020776-D6TkCx@rts-flowmailer.siemens.com; helo=mta-64-227.siemens.flowmailer.net X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity jan.kiszka@siemens.com) X-ZM-MESSAGEID: 1756706947060116600 Content-Type: text/plain; charset="utf-8" From: Jan Kiszka As an eMMC block device image may consist of more than just the user data partition, provide a helper script that can compose the image from boot partitions, an RPMB partition and the user data image. The script also does the required size validation and/or rounding. Signed-off-by: Jan Kiszka --- scripts/mkemmc.sh | 186 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100755 scripts/mkemmc.sh diff --git a/scripts/mkemmc.sh b/scripts/mkemmc.sh new file mode 100755 index 0000000000..9e52cd5f32 --- /dev/null +++ b/scripts/mkemmc.sh @@ -0,0 +1,186 @@ +#!/bin/sh -e +# SPDX-License-Identifier: GPL-2.0-only +# +# Create eMMC block device image from boot, RPMB and user data images +# +# Copyright (c) Siemens, 2025 +# +# Authors: +# Jan Kiszka +# +# This work is licensed under the terms of the GNU GPL version 2. +# See the COPYING file in the top-level directory. +# + +usage() { + echo "$0 [OPTIONS] USER_IMG[:SIZE] OUTPUT_IMG" + echo "" + echo "SIZE must be a power of 2. If no SIZE is specified, the size of = USER_ING will" + echo "be used (rounded up)." + echo "" + echo "Supported options:" + echo " -b BOOT1_IMG[:SIZE] Add boot partitions. SIZE must be multip= les of 128K. If" + echo " no SIZE is specified, the size of BOOT= _IMG will be" + echo " used (rounded up). BOOT1_IMG will be s= tored in boot" + echo " partition 1, and a boot partition 2 of= the same size" + echo " will be created as empty (all zeros) u= nless -B is" + echo " specified as well." + echo " -B BOOT2_IMG Fill boot partition 2 with BOOT2_IMG. Mu= st be combined" + echo " with -b which is also defining the par= tition size." + echo " -r RPMB_IMG[:SIZE] Add RPMB partition. SIZE must be multipl= es of 128K. If" + echo " no SIZE is specified, the size of RPMB= _IMG will be" + echo " used (rounded up)." + echo " -h, --help This help" + echo "" + echo "All SIZE parameters support the units K, M, G. If SIZE is smalle= r than the" + echo "associated image, it will be truncated in the output image." + exit "$1" +} + +process_size() { + if [ "${4#*:}" =3D "$4" ]; then + if ! size=3D$(stat -L -c %s "$2" 2>/dev/null); then + echo "Missing $1 image '$2'." >&2 + exit 1 + fi + if [ "$3" =3D 128 ]; then + size=3D$(( (size + 128 * 1024 - 1) & ~(128 * 1024 - 1) )) + elif [ $(( size & (size - 1) )) -gt 0 ]; then + n=3D0 + while [ "$size" -gt 0 ]; do + size=3D$((size >> 1)) + n=3D$((n + 1)) + done + size=3D$((1 << n)) + fi + else + value=3D"${4#*:}" + if [ "${value%K}" !=3D "$value" ]; then + size=3D${value%K} + multiplier=3D1024 + elif [ "${value%M}" !=3D "$value" ]; then + size=3D${value%M} + multiplier=3D$((1024 * 1024)) + elif [ "${value%G}" !=3D "$value" ]; then + size=3D${value%G} + multiplier=3D$((1024 * 1024 * 1024)) + else + size=3D$value + multiplier=3D1 + fi + if [ "$size" -eq "$size" ] 2>/dev/null; then + size=3D$((size * multiplier)) + else + echo "Invalid value '$value' specified for $2 image size." >&2 + exit 1 + fi + if [ "$3" =3D 128 ]; then + if [ $(( size & (128 * 1024 - 1) )) -ne 0 ]; then + echo "The $2 image size must be multiples of 128K." >&2 + exit 1 + fi + elif [ $(( size & (size - 1) )) -gt 0 ]; then + echo "The %2 image size must be power of 2." >&2 + exit 1 + fi + fi + echo $size +} + +userimg=3D +outimg=3D +bootimg1=3D +bootimg2=3D/dev/zero +bootsz=3D0 +rpmbimg=3D +rpmbsz=3D0 + +while [ $# -gt 0 ]; do + case "$1" in + -b) + shift + [ $# -ge 1 ] || usage 1 + bootimg1=3D${1%%:*} + bootsz=3D$(process_size boot "$bootimg1" 128 "$1") + shift + ;; + -B) + shift + [ $# -ge 1 ] || usage 1 + bootimg2=3D$1 + shift + ;; + -r) + shift + [ $# -ge 1 ] || usage 1 + rpmbimg=3D${1%%:*} + rpmbsz=3D$(process_size RPMB "$rpmbimg" 128 "$1") + shift + ;; + -h|--help) + usage 0 + ;; + *) + if [ -z "$userimg" ]; then + userimg=3D${1%%:*} + usersz=3D$(process_size user "$userimg" 2 "$1") + elif [ -z "$outimg" ]; then + outimg=3D$1 + else + usage 1 + fi + shift + ;; + esac +done + +[ -n "$outimg" ] || usage 1 + +if [ "$bootsz" -gt $((32640 * 1024)) ]; then + echo "Boot image size is larger than 32640K." >&2 + exit 1 +fi +if [ "$rpmbsz" -gt $((16384 * 1024)) ]; then + echo "RPMB image size is larger than 16384K." >&2 + exit 1 +fi + +echo "Creating eMMC image" + +truncate "$outimg" -s 0 +pos=3D0 + +if [ "$bootsz" -gt 0 ]; then + echo " Boot partition 1 and 2: $((bootsz / 1024))K each" + blocks=3D$(( bootsz / (128 * 1024) )) + dd if=3D"$bootimg1" of=3D"$outimg" conv=3Dsparse bs=3D128K count=3D$bl= ocks \ + status=3Dnone + dd if=3D"$bootimg2" of=3D"$outimg" conv=3Dsparse bs=3D128K count=3D$bl= ocks \ + seek=3D$blocks status=3Dnone + pos=3D$((2 * bootsz)) +fi + +if [ "$rpmbsz" -gt 0 ]; then + echo " RPMB partition: $((rpmbsz / 1024))K" + blocks=3D$(( rpmbsz / (128 * 1024) )) + dd if=3D"$rpmbimg" of=3D"$outimg" conv=3Dsparse bs=3D128K count=3D$blo= cks \ + seek=3D$(( pos / (128 * 1024) )) status=3Dnone + pos=3D$((pos + rpmbsz)) +fi + +if [ "$usersz" -lt 1024 ]; then + echo " User data: $usersz bytes" +elif [ "$usersz" -lt $((1024 * 1024)) ]; then + echo " User data: $(( (usersz + 1023) / 1024 ))K ($use= rsz)" +elif [ "$usersz" -lt $((1024 * 1024 * 1024)) ]; then + echo " User data: $(( (usersz + 1048575) / 1048576))M = ($usersz)" +else + echo " User data: $(( (usersz + 1073741823) / 10737418= 24))G ($usersz)" +fi +dd if=3D"$userimg" of=3D"$outimg" conv=3Dsparse bs=3D128K seek=3D$(( pos /= (128 * 1024) )) \ + count=3D$(( (usersz + 128 * 1024 - 1) / (128 * 1024) )) status=3Dnone +pos=3D$((pos + usersz)) +truncate "$outimg" -s $pos + +echo "" +echo "Instantiate via '-device emmc,boot-partition-size=3D$bootsz,rpmb-par= tition-size=3D$rpmbsz,drive=3D$outimg'" --=20 2.43.0