public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: Anton Mikanovich <amikan@ilbers.de>
Subject: [PATCH 2/3] rpi: Migrate to WIC
Date: Mon, 21 Mar 2022 16:42:45 +0300	[thread overview]
Message-ID: <20220321134246.17405-3-amikan@ilbers.de> (raw)
In-Reply-To: <20220321134246.17405-1-amikan@ilbers.de>

Migrate all Raspberry Pi targets from custom rpi-sdimg image type to
more generic WIC image type. Create rpi-sdimg.wks instead.
Make rpi-sdimg.bbclass not used in any targets deprecated.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 RECIPE-API-CHANGELOG.md                       |  8 +-
 meta-isar/classes/rpi-sdimg.bbclass           | 88 +++----------------
 meta-isar/conf/machine/rpi-common.conf        | 13 ++-
 meta-isar/conf/machine/rpi.conf               |  3 +-
 meta-isar/conf/multiconfig/rpi-stretch.conf   | 10 +++
 .../scripts/lib/wic/canned-wks/rpi-sdimg.wks  |  5 ++
 6 files changed, 49 insertions(+), 78 deletions(-)
 create mode 100644 meta-isar/scripts/lib/wic/canned-wks/rpi-sdimg.wks

diff --git a/RECIPE-API-CHANGELOG.md b/RECIPE-API-CHANGELOG.md
index cad15a8..5913dd2 100644
--- a/RECIPE-API-CHANGELOG.md
+++ b/RECIPE-API-CHANGELOG.md
@@ -342,4 +342,10 @@ The bitbake variable defines the respective environment variable which is availa
 When cross compiling, `cross` is added to the `DEB_BUILD_PROFILES` environment variable.
 Please note, that manually exported versions of the variables are overwritten.
 
-For a list of well-known Debian build profiles and common practices, we refer to Debian's BuildProfileSpec.
\ No newline at end of file
+For a list of well-known Debian build profiles and common practices, we refer to Debian's BuildProfileSpec.
+
+### `rpi-sdimg.bbclass` class is now deprecated and will be removed soon
+
+It was replaced by WIC and no more needed.
+Machines that use `rpi-sdimg` image type should be modified to use `wic` type
+with `rpi-sdimg` wks file instead.
diff --git a/meta-isar/classes/rpi-sdimg.bbclass b/meta-isar/classes/rpi-sdimg.bbclass
index e36970c..010c573 100644
--- a/meta-isar/classes/rpi-sdimg.bbclass
+++ b/meta-isar/classes/rpi-sdimg.bbclass
@@ -3,84 +3,22 @@
 #
 # Based on SD class from meta-raspberrypi
 
-inherit ext4-img
+inherit wic-img
 
-# Boot partition volume id
-BOOTDD_VOLUME_ID ?= "${MACHINE}"
+WKS_FILE ?= "rpi-sdimg"
 
-# Boot partition size [in KiB]
-BOOT_SPACE ?= "40960"
+WIC_IMAGER_INSTALL = "parted \
+                      dosfstools \
+                      mtools \
+                      e2fsprogs \
+                      python3-distutils \
+                      bmap-tools"
 
-# Set alignment to 4MB [in KiB]
-IMAGE_ROOTFS_ALIGNMENT = "4096"
+IMAGE_BOOT_FILES ?= "${IMAGE_ROOTFS}/boot/*.*;./ \
+                     ${IMAGE_ROOTFS}/boot/overlays/*;overlays/"
 
-SDIMG = "${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.sdimg"
-SDIMG_ROOTFS = "${DEPLOY_DIR_IMAGE}/${EXT4_IMAGE_FILE}"
+IMAGE_INSTALL += "bootconfig-${MACHINE}"
 
-do_rpi_sdimg[cleandirs] = "${WORKDIR}/rpi_sdimg/"
-do_rpi_sdimg () {
-    # Align partitions
-    ROOTFS_SIZE=$(du -b ${SDIMG_ROOTFS} | cut -f 1)
-    ROOTFS_SIZE=$(expr ${ROOTFS_SIZE} + 1)
-    ROOTFS_SIZE=$(expr ${ROOTFS_SIZE} - ${ROOTFS_SIZE} % 1024)
-    ROOTFS_SIZE=$(expr ${ROOTFS_SIZE} / 1024)
-    ROOTFS_SIZE=$(expr ${ROOTFS_SIZE} - ${ROOTFS_SIZE} % ${IMAGE_ROOTFS_ALIGNMENT} + ${IMAGE_ROOTFS_ALIGNMENT})
-
-    BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE} + ${IMAGE_ROOTFS_ALIGNMENT} - 1)
-    BOOT_SPACE_ALIGNED=$(expr ${BOOT_SPACE_ALIGNED} - ${BOOT_SPACE_ALIGNED} % ${IMAGE_ROOTFS_ALIGNMENT})
-    SDIMG_SIZE=$(expr ${IMAGE_ROOTFS_ALIGNMENT} + ${BOOT_SPACE_ALIGNED} + ${ROOTFS_SIZE})
-
-    echo "Creating filesystem with Boot partition ${BOOT_SPACE_ALIGNED} KiB and RootFS $ROOTFS_SIZE KiB"
-
-    #Initialize sdcard image file
-    dd if=/dev/zero of=${SDIMG} bs=1024 count=0 seek=${SDIMG_SIZE}
-
-    # Create partition table
-    parted -s ${SDIMG} mklabel msdos
-    # Create boot partition and mark it as bootable
-    parted -s ${SDIMG} unit KiB mkpart primary fat32 ${IMAGE_ROOTFS_ALIGNMENT} $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT})
-    parted -s ${SDIMG} set 1 boot on
-    # Create rootfs partition to the end of disk
-    parted -s ${SDIMG} -- unit KiB mkpart primary ext2 $(expr ${BOOT_SPACE_ALIGNED} \+ ${IMAGE_ROOTFS_ALIGNMENT}) -1s
-    parted ${SDIMG} print
-
-    # Create a vfat image with boot files
-    BOOT_BLOCKS=$(LC_ALL=C parted -s ${SDIMG} unit b print | awk '/ 1 / { print substr($4, 1, length($4 -1)) / 512 /2 }')
-    rm -f ${WORKDIR}/boot.img
-    mkfs.vfat -n "${BOOTDD_VOLUME_ID}" -S 512 -C ${WORKDIR}/boot.img $BOOT_BLOCKS
-    cp -a ${IMAGE_ROOTFS}/boot ${WORKDIR}/rpi_sdimg/
-
-    mcopy -i ${WORKDIR}/boot.img -s ${WORKDIR}/rpi_sdimg/boot/* ::/
-
-    # Burn Partitions
-    dd if=${WORKDIR}/boot.img of=${SDIMG} conv=notrunc seek=1 bs=$(expr ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
-    dd if=${SDIMG_ROOTFS} of=${SDIMG} conv=notrunc seek=1 bs=$(expr 1024 \* ${BOOT_SPACE_ALIGNED} + ${IMAGE_ROOTFS_ALIGNMENT} \* 1024) && sync && sync
-}
-
-addtask rpi_sdimg before do_build after do_ext4_image
-
-do_ext4_image[prefuncs] += " append_boot_fstab"
-do_ext4_image[postfuncs] += " restore_fstab"
-
-append_boot_fstab() {
-    grep boot ${IMAGE_ROOTFS} && return 0
-    cp -f ${IMAGE_ROOTFS}/etc/fstab ${WORKDIR}/fstab.orig
-    echo "/dev/mmcblk0p1  /boot           vfat    defaults          0       2" | sudo tee -a ${IMAGE_ROOTFS}/etc/fstab
-}
-
-restore_fstab() {
-    sudo cp -f ${WORKDIR}/fstab.orig ${IMAGE_ROOTFS}/etc/fstab
-}
-
-do_ext4_image[prefuncs] += " empty_boot_folder"
-do_ext4_image[postfuncs] += " restore_boot_folder"
-
-empty_boot_folder() {
-    sudo mv ${IMAGE_ROOTFS}/boot ${WORKDIR}/boot.orig
-    sudo mkdir -p ${IMAGE_ROOTFS}/boot
-}
-
-restore_boot_folder() {
-    sudo rm -rf ${IMAGE_ROOTFS}/boot
-    sudo mv ${WORKDIR}/boot.orig ${IMAGE_ROOTFS}/boot
+python do_wic_image_prepend() {
+    bb.warn("rpi-sdimg image type is deprecated, please change to wic.")
 }
diff --git a/meta-isar/conf/machine/rpi-common.conf b/meta-isar/conf/machine/rpi-common.conf
index b508d2a..8d6dff9 100644
--- a/meta-isar/conf/machine/rpi-common.conf
+++ b/meta-isar/conf/machine/rpi-common.conf
@@ -5,7 +5,8 @@ BOOT_SPACE ?= "81920"
 MACHINE_SERIAL ?= "serial0"
 BAUDRATE_TTY ?= "115200"
 
-IMAGE_FSTYPES ?= "rpi-sdimg"
+IMAGE_FSTYPES ?= "wic-img"
+WKS_FILE ?= "rpi-sdimg"
 
 KERNEL_TYPE = "raspios"
 KERNEL_IMAGE_PKG ?= "raspberrypi-kernel"
@@ -23,3 +24,13 @@ IMAGE_PREINSTALL += " \
 
 IMAGE_INSTALL += "expand-on-first-boot \
                   bootconfig-${MACHINE}"
+
+WIC_IMAGER_INSTALL = "parted \
+                      dosfstools \
+                      mtools \
+                      e2fsprogs \
+                      python3-distutils \
+                      bmap-tools"
+
+IMAGE_BOOT_FILES ?= "${IMAGE_ROOTFS}/boot/*.*;./ \
+                     ${IMAGE_ROOTFS}/boot/overlays/*;overlays/"
diff --git a/meta-isar/conf/machine/rpi.conf b/meta-isar/conf/machine/rpi.conf
index 61852a9..0ab701c 100644
--- a/meta-isar/conf/machine/rpi.conf
+++ b/meta-isar/conf/machine/rpi.conf
@@ -4,4 +4,5 @@
 MACHINE_SERIAL ?= "ttyAMA0"
 BAUDRATE_TTY ?= "9600"
 
-IMAGE_FSTYPES ?= "rpi-sdimg"
+IMAGE_FSTYPES ?= "wic-img"
+WKS_FILE ?= "rpi-sdimg"
diff --git a/meta-isar/conf/multiconfig/rpi-stretch.conf b/meta-isar/conf/multiconfig/rpi-stretch.conf
index 63f9adc..3c9470e 100644
--- a/meta-isar/conf/multiconfig/rpi-stretch.conf
+++ b/meta-isar/conf/multiconfig/rpi-stretch.conf
@@ -35,3 +35,13 @@ IMAGE_PREINSTALL += " \
 
 IMAGE_INSTALL += "sshd-regen-keys \
                   bootconfig-${MACHINE}"
+
+WIC_IMAGER_INSTALL = "parted \
+                      dosfstools \
+                      mtools \
+                      e2fsprogs \
+                      python3 \
+                      bmap-tools"
+
+IMAGE_BOOT_FILES ?= "${IMAGE_ROOTFS}/boot/*.*;./ \
+                     ${IMAGE_ROOTFS}/boot/overlays/*;overlays/"
diff --git a/meta-isar/scripts/lib/wic/canned-wks/rpi-sdimg.wks b/meta-isar/scripts/lib/wic/canned-wks/rpi-sdimg.wks
new file mode 100644
index 0000000..c788213
--- /dev/null
+++ b/meta-isar/scripts/lib/wic/canned-wks/rpi-sdimg.wks
@@ -0,0 +1,5 @@
+part /boot --source bootimg-partition --ondisk mmcblk0 --fstype=vfat --label boot --active --align 4096 --size 10
+
+part / --source rootfs --ondisk mmcblk0 --fstype=ext2 --label root --align 4096 --exclude-path=boot
+
+bootloader
-- 
2.17.1


  parent reply	other threads:[~2022-03-21 13:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-21 13:42 [PATCH 0/3] Replace rpi-sdimg by wic Anton Mikanovich
2022-03-21 13:42 ` [PATCH 1/3] rpi: Introduce bootconfig-rpi package Anton Mikanovich
2022-03-21 13:42 ` Anton Mikanovich [this message]
2022-03-21 13:42 ` [PATCH 3/3] doc: Change rpi-sdimg related documentation Anton Mikanovich
2022-03-28 17:50 ` [PATCH 0/3] Replace rpi-sdimg by wic Anton Mikanovich

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=20220321134246.17405-3-amikan@ilbers.de \
    --to=amikan@ilbers.de \
    --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