From patchwork Sat Aug 22 20:01:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Th=C3=A9baudeau?= X-Patchwork-Id: 509727 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ozlabs.org (Postfix) with ESMTP id A9483140761 for ; Sun, 23 Aug 2015 06:01:49 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id F174795BEC; Sat, 22 Aug 2015 20:01:48 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CvcYGNDbC50P; Sat, 22 Aug 2015 20:01:48 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by hemlock.osuosl.org (Postfix) with ESMTP id 0F4D495BCB; Sat, 22 Aug 2015 20:01:48 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by ash.osuosl.org (Postfix) with ESMTP id D543A1C1619 for ; Sat, 22 Aug 2015 20:01:40 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id CFF76921B5 for ; Sat, 22 Aug 2015 20:01:40 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id iZmxCH-jvsTo for ; Sat, 22 Aug 2015 20:01:39 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from authsmtp.register.it (authsmtp76.register.it [195.110.101.60]) by whitealder.osuosl.org (Postfix) with ESMTP id 9609D921B1 for ; Sat, 22 Aug 2015 20:01:38 +0000 (UTC) Received: from localhost.localdomain ([88.172.188.148]) by paganini34 with id 7w1W1r00y3CYkgw01w1cWF; Sat, 22 Aug 2015 22:01:36 +0200 X-Rid: benoit@wsystem.com@88.172.188.148 From: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= To: buildroot@buildroot.org Date: Sat, 22 Aug 2015 22:01:27 +0200 Message-Id: <1440273688-92868-3-git-send-email-benoit@wsystem.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1440273688-92868-1-git-send-email-benoit@wsystem.com> References: <1440273688-92868-1-git-send-email-benoit@wsystem.com> In-Reply-To: <20150820143005.GA6441@ketchup.mtl.sfl> References: <20150820143005.GA6441@ketchup.mtl.sfl> MIME-Version: 1.0 Cc: =?UTF-8?q?Beno=C3=AEt=20Th=C3=A9baudeau?= Subject: [Buildroot] [PATCH 3/4] board/raspberrypi: generate a medium image X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" 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 --- 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"