Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Benoît Thébaudeau" <benoit@wsystem.com>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 3/4] board/raspberrypi: generate a medium image
Date: Sat, 22 Aug 2015 22:01:27 +0200	[thread overview]
Message-ID: <1440273688-92868-3-git-send-email-benoit@wsystem.com> (raw)
In-Reply-To: <1440273688-92868-1-git-send-email-benoit@wsystem.com>

Automate the generation of an sdcard.img medium image, ready to be
written to the SD card, while leaving the manual procedure available for
custom needs.

genimage is used, so no commands need to be run as root by Buildroot.

The layout of the generated image is adjusted automatically if an
initramfs is selected in the configuration.

The instructions in readme.txt are updated accordingly. The layout of
the generated image is described in this file.

Signed-off-by: Beno?t Th?baudeau <benoit@wsystem.com>
---
 board/raspberrypi/genimage-persistent-rootfs.cfg | 22 +++++++
 board/raspberrypi/genimage-volatile-rootfs.cfg   | 17 +++++
 board/raspberrypi/genimage.sh                    | 15 +++++
 board/raspberrypi/readme.txt                     | 79 +++++++++++++++++-------
 configs/raspberrypi2_defconfig                   |  6 +-
 configs/raspberrypi_defconfig                    |  6 +-
 6 files changed, 121 insertions(+), 24 deletions(-)
 create mode 100644 board/raspberrypi/genimage-persistent-rootfs.cfg
 create mode 100644 board/raspberrypi/genimage-volatile-rootfs.cfg
 create mode 100755 board/raspberrypi/genimage.sh

diff --git a/board/raspberrypi/genimage-persistent-rootfs.cfg b/board/raspberrypi/genimage-persistent-rootfs.cfg
new file mode 100644
index 0000000..e519ca6
--- /dev/null
+++ b/board/raspberrypi/genimage-persistent-rootfs.cfg
@@ -0,0 +1,22 @@
+image boot.vfat {
+	vfat {
+		extraargs = "-F 16 -n BOOT"
+	}
+	size = 10M
+	mountpoint = "/"
+}
+
+image sdcard.img {
+	hdimage {}
+
+	partition boot {
+		partition-type = 0x0e
+		bootable = true
+		image = "boot.vfat"
+	}
+
+	partition rootfs {
+		partition-type = 0x83
+		image = "rootfs.ext4"
+	}
+}
diff --git a/board/raspberrypi/genimage-volatile-rootfs.cfg b/board/raspberrypi/genimage-volatile-rootfs.cfg
new file mode 100644
index 0000000..488bd81
--- /dev/null
+++ b/board/raspberrypi/genimage-volatile-rootfs.cfg
@@ -0,0 +1,17 @@
+image boot.vfat {
+	vfat {
+		extraargs = "-F 32 -n BOOT"
+	}
+	size = 50M
+	mountpoint = "/"
+}
+
+image sdcard.img {
+	hdimage {}
+
+	partition boot {
+		partition-type = 0x0c
+		bootable = true
+		image = "boot.vfat"
+	}
+}
diff --git a/board/raspberrypi/genimage.sh b/board/raspberrypi/genimage.sh
new file mode 100755
index 0000000..663335c
--- /dev/null
+++ b/board/raspberrypi/genimage.sh
@@ -0,0 +1,15 @@
+#!/bin/bash -e
+
+BOARD_DIR="board/raspberrypi"
+RPI_FW_BIN_DIR="${BINARIES_DIR}/rpi-firmware"
+if grep "^BR2_TARGET_ROOTFS_INITRAMFS=y$" "${BR2_CONFIG}" &>/dev/null; then
+	GENIMAGE_CFG="${BOARD_DIR}/genimage-volatile-rootfs.cfg"
+else
+	GENIMAGE_CFG="${BOARD_DIR}/genimage-persistent-rootfs.cfg"
+fi
+GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
+
+rm -Rf "${GENIMAGE_TMP}"
+genimage --rootpath "${RPI_FW_BIN_DIR}" --tmppath "${GENIMAGE_TMP}" \
+	--inputpath "${BINARIES_DIR}" --outputpath "${BINARIES_DIR}" \
+	--config "${GENIMAGE_CFG}"
diff --git a/board/raspberrypi/readme.txt b/board/raspberrypi/readme.txt
index 168fab5..d63e71e 100644
--- a/board/raspberrypi/readme.txt
+++ b/board/raspberrypi/readme.txt
@@ -33,7 +33,11 @@ And for model 2 B:
 
   $ make raspberrypi2_defconfig
 
-If you want to use a persistent rootfs, skip to "Build the rootfs", below.
+If you want to use a persistent rootfs, the generated ext4 rootfs image fits its
+contents with only a small (but sensible) margin of free space by default, so
+you might want to adjust "Filesystem images"/"ext2/3/4 root filesystem"/
+"size in blocks (leave at 0 for auto calculation)" depending on your needs, then
+skip to "Build the rootfs", below.
 
 For a volatile rootfs, you have to slightly adjust the configuration:
 
@@ -41,7 +45,7 @@ For a volatile rootfs, you have to slightly adjust the configuration:
     * Select "Filesystem images"
     * Select "initial RAM filesystem linked into linux kernel"
 
-You may also deselect "tar the root filesystem".
+You may also deselect "ext2/3/4 root filesystem" and "tar the root filesystem".
 
 Build the rootfs
 ----------------
@@ -61,38 +65,66 @@ Result of the build
 After building, you should obtain this tree:
 
     output/images/
-    +-- rootfs.cpio                 [0]
-    +-- rootfs.tar                  [1]
+    +-- boot.vfat                   [0]
+    +-- sdcard.img                  [1]
+    +-- rootfs.cpio                 [2]
+    +-- rootfs.ext2                 [3]
+    +-- rootfs.ext4 -> rootfs.ext2  [3]
+    +-- rootfs.tar                  [4]
     +-- rpi-firmware/
-    |   +-- bcm2708-rpi-b.dtb       [2]
-    |   +-- bcm2708-rpi-b-plus.dtb  [3]
-    |   +-- bcm2709-rpi-2-b.dtb     [4]
+    |   +-- bcm2708-rpi-b.dtb       [5]
+    |   +-- bcm2708-rpi-b-plus.dtb  [6]
+    |   +-- bcm2709-rpi-2-b.dtb     [7]
     |   +-- bootcode.bin
-    |   +-- cmdline.txt             [5]
+    |   +-- cmdline.txt             [8]
     |   +-- config.txt
     |   +-- fixup.dat
     |   +-- start.elf
-    |   `-- zImage                  [6]
-    `-- zImage                      [7]
+    |   `-- zImage                  [9]
+    `-- zImage                      [10]
 
-[0] rootfs.cpio will only be there if you selected a volatile rootfs.
-[1] Note for volatile: rootfs.tar will only be there if you kept
+[0] Image of the VFAT boot filesystem containing the files from
+    output/images/rpi-firmware.
+
+[1] Medium image ready to be written to your SD card.
+    For the volatile rootfs, it contains a single partition, filled with
+    boot.vfat.
+    For the persistent rootfs, it contains two partitions:
+    one filled with boot.vfat and one filled with rootfs.ext4.
+
+[2] rootfs.cpio will only be there if you selected a volatile rootfs.
+[3] Note for volatile: rootfs.ext* will only be there if you kept
+    "ext2/3/4 root filesystem" option selected in "Filesystem images".
+[4] Note for volatile: rootfs.tar will only be there if you kept
     "tar the root filesystem" option selected in "Filesystem images".
 
-[2] Required for models A and B, generated by raspberrypi_defconfig.
-[3] Required for models A+ and B+, generated by raspberrypi_defconfig.
-[4] Required for model 2, generated by raspberrypi2_defconfig.
+[5] Required for models A and B, generated by raspberrypi_defconfig.
+[6] Required for models A+ and B+, generated by raspberrypi_defconfig.
+[7] Required for model 2, generated by raspberrypi2_defconfig.
 
-[5] Generated by Buildroot, but optional for the firmware.
+[8] Generated by Buildroot, but optional for the firmware.
 
-[6] Kernel image marked for the firmware as supporting Device Tree.
+[9] Kernel image marked for the firmware as supporting Device Tree.
     Note: The kernel image file name is defined in config.txt like this:
     kernel=zImage
-[7] Original kernel image.
+[10] Original kernel image.
 
 Prepare your SD card
 ====================
 
+If you want to follow a manual procedure, then skip to "Manual procedure",
+below.
+
+Write (as root!) the generated medium image to your SD card (adjust 'sdX' to
+match your device):
+
+  $ sudo dd if=output/images/sdcard.img of=/dev/sdX bs=1M
+
+Skip to "Finish", below.
+
+Manual procedure
+----------------
+
 For more information, visit
 http://elinux.org/RPi_Advanced_Setup#Advanced_SD_card_setup
 
@@ -119,7 +151,7 @@ output/images/rpi-firmware:
 
   $ cp output/images/rpi-firmware/* /mnt/mountpointboot
 
-If you use a volatile rootfs, skip to "Finish", below. For a persistent
+If you use a volatile rootfs, skip to "Unmount", below. For a persistent
 rootfs, there are further steps to do.
 
 Extract (as root!) the contents of the rootfs.tar archive into the second
@@ -127,15 +159,18 @@ partition you created above:
 
   $ sudo tar xf ./output/images/rootfs.tar -C /mnt/mountpointroot
 
-Finish
-======
+Unmount
+-------
 
 Unmount all the partitions:
 
   $ sudo umount /mnt/mountpointboot
   $ sudo umount /mnt/mountpointroot     (only for persistent rootfs)
 
-And eject your SD card from your computer SD card reader.
+Finish
+======
+
+Eject your SD card from your computer SD card reader.
 
 Insert the SD card into your Raspberry Pi, and power it up. Your new system
 should come up, now.
diff --git a/configs/raspberrypi2_defconfig b/configs/raspberrypi2_defconfig
index bfbf243..73dc290 100644
--- a/configs/raspberrypi2_defconfig
+++ b/configs/raspberrypi2_defconfig
@@ -27,4 +27,8 @@ BR2_LINUX_KERNEL_INTREE_DTS_NAME="bcm2709-rpi-2-b"
 BR2_PACKAGE_RPI_FIRMWARE=y
 # BR2_PACKAGE_RPI_FIRMWARE_INSTALL_DTB_OVERLAYS is not set
 
-BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi2/post-image.sh"
+BR2_TARGET_ROOTFS_EXT2=y
+BR2_TARGET_ROOTFS_EXT2_4=y
+BR2_TARGET_ROOTFS_EXT2_LABEL="rootfs"
+BR2_PACKAGE_HOST_GENIMAGE=y
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi2/post-image.sh board/raspberrypi2/genimage.sh"
diff --git a/configs/raspberrypi_defconfig b/configs/raspberrypi_defconfig
index 5ded72f..58f4cab 100644
--- a/configs/raspberrypi_defconfig
+++ b/configs/raspberrypi_defconfig
@@ -26,4 +26,8 @@ BR2_LINUX_KERNEL_INTREE_DTS_NAME="bcm2708-rpi-b bcm2708-rpi-b-plus"
 BR2_PACKAGE_RPI_FIRMWARE=y
 # BR2_PACKAGE_RPI_FIRMWARE_INSTALL_DTB_OVERLAYS is not set
 
-BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi/post-image.sh"
+BR2_TARGET_ROOTFS_EXT2=y
+BR2_TARGET_ROOTFS_EXT2_4=y
+BR2_TARGET_ROOTFS_EXT2_LABEL="rootfs"
+BR2_PACKAGE_HOST_GENIMAGE=y
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi/post-image.sh board/raspberrypi/genimage.sh"
-- 
2.1.4

  parent reply	other threads:[~2015-08-22 20:01 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-19 22:23 [Buildroot] rpi: image generation Benoît Thébaudeau
2015-08-20  7:59 ` Thomas Petazzoni
2015-08-20 14:30   ` Vivien Didelot
2015-08-22 20:01     ` [Buildroot] [PATCH 1/4] configs/raspberrypi: use EABIhf Benoît Thébaudeau
2015-08-22 20:01       ` [Buildroot] [PATCH 2/4] board/raspberrypi: prepare the image files for the target Benoît Thébaudeau
2015-10-17 11:45         ` Yann E. MORIN
2015-10-17 13:52           ` Benoît Thébaudeau
2015-08-22 20:01       ` Benoît Thébaudeau [this message]
2015-08-22 20:01       ` [Buildroot] [PATCH 4/4] board/raspberrypi: auto-expand rootfs on first boot Benoît Thébaudeau
2015-08-27  9:02         ` Benoît Thébaudeau
2015-08-27 21:22           ` Jérôme Pouiller
2015-08-28 10:36             ` Benoît Thébaudeau
2015-08-28 11:15               ` Benoît Thébaudeau
     [not found]         ` <4057940.fE2DsQZqLb@sagittea>
2015-08-31  9:11           ` Benoît Thébaudeau
2015-08-31 12:17         ` Floris Bos
2015-08-31 18:53           ` Benoît Thébaudeau
2015-08-31 13:25         ` Floris Bos
2015-08-31 19:05           ` Benoît Thébaudeau
2015-10-12 21:59       ` [Buildroot] [PATCH 1/4] configs/raspberrypi: use EABIhf Thomas Petazzoni
2015-10-12 23:17         ` Benoît Thébaudeau
2015-10-13  7:06           ` Arnout Vandecappelle
2015-10-15 20:11         ` Peter Korsgaard
2015-10-15 21:12           ` Peter Korsgaard
2015-10-25 15:19           ` [Buildroot] [PATCH] arch/arm: use EABIhf by default with VFP Benoît Thébaudeau
2015-10-25 18:53             ` Peter Korsgaard
2015-10-26  0:32               ` Thomas Petazzoni
2015-10-26  7:47                 ` Peter Korsgaard
2015-10-26  8:25                   ` Thomas Petazzoni
2015-10-26  8:51                     ` Peter Korsgaard
2015-10-25 18:55             ` Peter Korsgaard
2015-10-25 20:27               ` Benoît Thébaudeau
2015-10-25 20:40                 ` Peter Korsgaard
2015-10-25 20:52                   ` Benoît Thébaudeau
2015-10-25 21:30                     ` 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=1440273688-92868-3-git-send-email-benoit@wsystem.com \
    --to=benoit@wsystem.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox