On 04.11.25 17:27, Philippe Mathieu-Daudé wrote: > On 4/11/25 15:45, Jan Kiszka wrote: >> From: Jan Kiszka <[email protected]> >> >> 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 <[email protected]> >> --- >> >> Changes in v6.1: >> - address BSD shell portability issue of stat -c >> >> scripts/mkemmc.sh | 219 ++++++++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 219 insertions(+) >> create mode 100755 scripts/mkemmc.sh > > >> +echo "Creating eMMC image" >> + >> +truncate -s 0 "$outimg" >> +pos=0 >> + >> +if [ "$bootsz" -gt 0 ]; then >> + echo " Boot partition 1 and 2: $((bootsz / 1024))K each" >> + blocks=$(( bootsz / (128 * 1024) )) >> + check_truncation "$bootimg1" "$bootsz" >> + dd if="$bootimg1" of="$outimg" conv=sparse bs=128K count=$blocks \ >> + status=none >> + check_truncation "$bootimg2" "$bootsz" >> + dd if="$bootimg2" of="$outimg" conv=sparse bs=128K count=$blocks \ >> + seek=$blocks status=none >> + pos=$((2 * bootsz)) >> +fi >> + >> +if [ "$rpmbsz" -gt 0 ]; then >> + echo " RPMB partition: $((rpmbsz / 1024))K" >> + blocks=$(( rpmbsz / (128 * 1024) )) >> + check_truncation "$rpmbimg" "$rpmbsz" >> + dd if="$rpmbimg" of="$outimg" conv=sparse bs=128K count=$blocks \ >> + seek=$(( pos / (128 * 1024) )) status=none >> + pos=$((pos + rpmbsz)) >> +fi > > Still: > > $ dash scripts/mkemmc.sh -b firmware.img -r /dev/zero:2MB os.img emmc.img ^^ User error ;-). This must be just "...:2M".
> Invalid value '2MB' specified for /dev/zero image size. > scripts/mkemmc.sh: 170: [: Illegal number: > Creating eMMC image > Boot partition 1 and 2: 128K each > scripts/mkemmc.sh: 192: [: Illegal number: > User data: 4 bytes > > $ bash scripts/mkemmc.sh -b firmware.img -r /dev/zero:2MB os.img emmc.img > Invalid value '2MB' specified for /dev/zero image size. > scripts/mkemmc.sh: line 170: [: : integer expression expected > Creating eMMC image > Boot partition 1 and 2: 128K each > scripts/mkemmc.sh: line 192: [: : integer expression expected > User data: 4 bytes > > But now the file is generated :) ...which is actually a bug as well: We are not terminating the script inside the process_size function when calling "exit" there. Deviates from the behavior under Linux. Sigh. Jan > > We'll fix on top. > > Reviewed-by: Philippe Mathieu-Daudé <[email protected]> > Tested-by: Philippe Mathieu-Daudé <[email protected]> > >> + >> +if [ "$usersz" -lt 1024 ]; then >> + echo " User data: $usersz bytes" >> +elif [ "$usersz" -lt $((1024 * 1024)) ]; then >> + echo " User data: $(( (usersz + 1023) / 1024 ))K >> ($usersz)" >> +elif [ "$usersz" -lt $((1024 * 1024 * 1024)) ]; then >> + echo " User data: $(( (usersz + 1048575) / >> 1048576))M ($usersz)" >> +else >> + echo " User data: $(( (usersz + 1073741823) / >> 1073741824))G ($usersz)" >> +fi >> +check_truncation "$userimg" "$usersz" >> +dd if="$userimg" of="$outimg" conv=sparse bs=128K seek=$(( pos / (128 >> * 1024) )) \ >> + count=$(( (usersz + 128 * 1024 - 1) / (128 * 1024) )) status=none >> +pos=$((pos + usersz)) >> +truncate -s $pos "$outimg" >> + >> +echo "" >> +echo "Instantiate by appending to the qemu command line:" >> +echo " -drive file=$outimg,if=none,format=raw,id=emmc-img" >> +echo " -device emmc,boot-partition-size=$bootsz,rpmb-partition- >> size=$rpmbsz,drive=emmc-img" > -- Siemens AG, Foundational Technologies Linux Expert Center
