Skip to contentSkip to conversation

sd card image generation for Xplained boards

PATCH Superseded Ludovic Desroches 1 participant 6 messages Apr 4, 2016 – Apr 6, 2016 Arm/Microchip (AT91) SoC support

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover sd card image generation for Xplained boards

Use genimage to generate a SD card image

Changes
- v2:
- add missing host packages to generate the FAT partition
- cleanup post-image.sh
- update documentation

Ludovic Desroches (4):
configs: atmel: add sama5d2 xplained sd card image generation
configs: atmel: add sama5d4 xplained sd card image generation
configs: atmel: add sama5d3 xplained sd card image generation board/atmel: update documentation for SD card generation

 board/atmel/readme.txt                         | 66 +++++++++++---------------
 board/atmel/sama5d2_xplained_mmc/genimage.cfg  | 33 +++++++++++++
 board/atmel/sama5d2_xplained_mmc/post-image.sh | 14 ++++++
 board/atmel/sama5d3_xplained_mmc/genimage.cfg  | 33 +++++++++++++
 board/atmel/sama5d3_xplained_mmc/post-image.sh | 14 ++++++
 board/atmel/sama5d4_xplained_mmc/genimage.cfg  | 34 +++++++++++++
 board/atmel/sama5d4_xplained_mmc/post-image.sh | 14 ++++++
 configs/atmel_sama5d2_xplained_mmc_defconfig   |  6 +++
 configs/atmel_sama5d3_xplained_mmc_defconfig   |  6 +++
 configs/atmel_sama5d4_xplained_mmc_defconfig   |  7 ++-
 10 files changed, 188 insertions(+), 39 deletions(-)
 create mode 100644 board/atmel/sama5d2_xplained_mmc/genimage.cfg
 create mode 100755 board/atmel/sama5d2_xplained_mmc/post-image.sh
 create mode 100644 board/atmel/sama5d3_xplained_mmc/genimage.cfg
 create mode 100755 board/atmel/sama5d3_xplained_mmc/post-image.sh
 create mode 100644 board/atmel/sama5d4_xplained_mmc/genimage.cfg
 create mode 100755 board/atmel/sama5d4_xplained_mmc/post-image.sh
Signature · 1 line
2.5.0
#1 lore raw

PATCH v2 1/4 configs: atmel: add sama5d2 xplained sd card image generation

Use genimage to generate a sd card with a fat partition (at91bootstrap, u-boot, kernel, dtbs) and an ext4 partition (rootfs).

---
 board/atmel/sama5d2_xplained_mmc/genimage.cfg  | 33 ++++++++++++++++++++++++++
 board/atmel/sama5d2_xplained_mmc/post-image.sh | 14 +++++++++++
 configs/atmel_sama5d2_xplained_mmc_defconfig   |  6 +++++
 3 files changed, 53 insertions(+)
 create mode 100644 board/atmel/sama5d2_xplained_mmc/genimage.cfg
 create mode 100755 board/atmel/sama5d2_xplained_mmc/post-image.sh
board/atmel/sama5d2_xplained_mmc/genimage.cfg new file +33 -0
new file mode 100644
index 0000000..b0ba22d
@@ -0,0 +1,33 @@
+# Image for SD card boot on Atmel SAMA5D2 Xplained boards
+#
+image boot.vfat {
+	vfat {
+		files = {
+			"zImage",
+			"at91-sama5d2_xplained.dtb",
+			"at91-sama5d2_xplained_pda4.dtb",
+			"at91-sama5d2_xplained_pda7.dtb",
+			"at91-sama5d2_xplained_pda7b.dtb",
+			"boot.bin",
+			"u-boot.bin"
+		}
+	}
+	size = 16M
+}
+
+image sdcard.img {
+	hdimage {
+	}
+
+	partition boot {
+		partition-type = 0xC
+		bootable = "true"
+		image = "boot.vfat"
+	}
+
+	partition rootfs {
+		partition-type = 0x83
+		image = "rootfs.ext4"
+		size = 512M
+	}
+}
board/atmel/sama5d2_xplained_mmc/post-image.sh new file +14 -0
new file mode 100755
index 0000000..359b4c9
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+BOARD_DIR="$(dirname $0)"
+GENIMAGE_CFG="${BOARD_DIR}/genimage.cfg"
+GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
+
+rm -rf "${GENIMAGE_TMP}"
+
+genimage                               \
+	--rootpath "${TARGET_DIR}"     \
+	--tmppath "${GENIMAGE_TMP}"    \
+	--inputpath "${BINARIES_DIR}"  \
+	--outputpath "${BINARIES_DIR}" \
+	--config "${GENIMAGE_CFG}"
configs/atmel_sama5d2_xplained_mmc_defconfig +6 -0
index 74fa2b5..ecf4898 100644
@@ -5,6 +5,7 @@ BR2_ARM_ENABLE_VFP=y
 BR2_ARM_FPU_VFPV4=y
 BR2_ARM_INSTRUCTIONS_THUMB2=y
 BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_1=y
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/atmel/sama5d2_xplained_mmc/post-image.sh"
 BR2_LINUX_KERNEL=y
 BR2_LINUX_KERNEL_CUSTOM_GIT=y
 BR2_LINUX_KERNEL_CUSTOM_REPO_URL="https://github.com/linux4sam/linux-at91.git"
@@ -13,6 +14,8 @@ BR2_LINUX_KERNEL_DEFCONFIG="sama5"
 BR2_LINUX_KERNEL_ZIMAGE=y
 BR2_LINUX_KERNEL_DTS_SUPPORT=y
 BR2_LINUX_KERNEL_INTREE_DTS_NAME="at91-sama5d2_xplained at91-sama5d2_xplained_pda4 at91-sama5d2_xplained_pda7 at91-sama5d2_xplained_pda7b"
+BR2_TARGET_ROOTFS_EXT2=y
+BR2_TARGET_ROOTFS_EXT2_4=y
 BR2_TARGET_AT91BOOTSTRAP3=y
 BR2_TARGET_AT91BOOTSTRAP3_CUSTOM_GIT=y
 BR2_TARGET_AT91BOOTSTRAP3_CUSTOM_REPO_URL="https://github.com/linux4sam/at91bootstrap.git"
@@ -24,3 +27,6 @@ BR2_TARGET_UBOOT_CUSTOM_GIT=y
 BR2_TARGET_UBOOT_CUSTOM_REPO_URL="https://github.com/linux4sam/u-boot-at91.git"
 BR2_TARGET_UBOOT_CUSTOM_REPO_VERSION="linux4sam_5.2"
 BR2_TARGET_UBOOT_BOARD_DEFCONFIG="sama5d2_xplained_mmc"
+BR2_PACKAGE_HOST_DOSFSTOOLS=y
+BR2_PACKAGE_HOST_GENIMAGE=y
+BR2_PACKAGE_HOST_MTOOLS=y
Signature · 1 line
2.5.0
#2 lore raw

PATCH v2 2/4 configs: atmel: add sama5d4 xplained sd card image generation

In reply to Ludovic Desroches

Use genimage to generate a sd card with a fat partition (at91bootstrap, u-boot, kernel, dtbs) and an ext4 partition (rootfs).

---
 board/atmel/sama5d4_xplained_mmc/genimage.cfg  | 34 ++++++++++++++++++++++++++
 board/atmel/sama5d4_xplained_mmc/post-image.sh | 14 +++++++++++
 configs/atmel_sama5d4_xplained_mmc_defconfig   |  7 +++++-
 3 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 board/atmel/sama5d4_xplained_mmc/genimage.cfg
 create mode 100755 board/atmel/sama5d4_xplained_mmc/post-image.sh
board/atmel/sama5d4_xplained_mmc/genimage.cfg new file +34 -0
new file mode 100644
index 0000000..b23ebe4
@@ -0,0 +1,34 @@
+# Image for SD card boot on Atmel SAMA5D4 Xplained boards
+#
+image boot.vfat {
+	vfat {
+		files = {
+			"zImage",
+			"at91-sama5d4_xplained.dtb",
+			"at91-sama5d4_xplained_hdmi.dtb",
+			"at91-sama5d4_xplained_pda4.dtb",
+			"at91-sama5d4_xplained_pda7.dtb",
+			"at91-sama5d4_xplained_pda7b.dtb",
+			"boot.bin",
+			"u-boot.bin"
+		}
+	}
+	size = 16M
+}
+
+image sdcard.img {
+	hdimage {
+	}
+
+	partition boot {
+		partition-type = 0xC
+		bootable = "true"
+		image = "boot.vfat"
+	}
+
+	partition rootfs {
+		partition-type = 0x83
+		image = "rootfs.ext4"
+		size = 512M
+	}
+}
board/atmel/sama5d4_xplained_mmc/post-image.sh new file +14 -0
new file mode 100755
index 0000000..359b4c9
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+BOARD_DIR="$(dirname $0)"
+GENIMAGE_CFG="${BOARD_DIR}/genimage.cfg"
+GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
+
+rm -rf "${GENIMAGE_TMP}"
+
+genimage                               \
+	--rootpath "${TARGET_DIR}"     \
+	--tmppath "${GENIMAGE_TMP}"    \
+	--inputpath "${BINARIES_DIR}"  \
+	--outputpath "${BINARIES_DIR}" \
+	--config "${GENIMAGE_CFG}"
configs/atmel_sama5d4_xplained_mmc_defconfig +6 -1
index e0374d7..a3eb7cd 100644
@@ -4,6 +4,7 @@ BR2_ARM_ENABLE_NEON=y
 BR2_ARM_ENABLE_VFP=y
 BR2_ARM_INSTRUCTIONS_THUMB2=y
 BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_1=y
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/atmel/sama5d4_xplained_mmc/post-image.sh"
 BR2_LINUX_KERNEL=y
 BR2_LINUX_KERNEL_CUSTOM_GIT=y
 BR2_LINUX_KERNEL_CUSTOM_REPO_URL="https://github.com/linux4sam/linux-at91.git"
@@ -12,6 +13,8 @@ BR2_LINUX_KERNEL_DEFCONFIG="sama5"
 BR2_LINUX_KERNEL_ZIMAGE=y
 BR2_LINUX_KERNEL_DTS_SUPPORT=y
 BR2_LINUX_KERNEL_INTREE_DTS_NAME="at91-sama5d4_xplained at91-sama5d4_xplained_hdmi at91-sama5d4_xplained_pda4 at91-sama5d4_xplained_pda7 at91-sama5d4_xplained_pda7b"
+BR2_TARGET_ROOTFS_EXT2=y
+BR2_TARGET_ROOTFS_EXT2_4=y
 BR2_TARGET_AT91BOOTSTRAP3=y
 BR2_TARGET_AT91BOOTSTRAP3_CUSTOM_GIT=y
 BR2_TARGET_AT91BOOTSTRAP3_CUSTOM_REPO_URL="https://github.com/linux4sam/at91bootstrap.git"
@@ -23,4 +26,6 @@ BR2_TARGET_UBOOT_CUSTOM_GIT=y
 BR2_TARGET_UBOOT_CUSTOM_REPO_URL="git://github.com/linux4sam/u-boot-at91.git"
 BR2_TARGET_UBOOT_CUSTOM_REPO_VERSION="linux4sam_5.2"
 BR2_TARGET_UBOOT_BOARD_DEFCONFIG="sama5d4_xplained_mmc"
-BR2_PACKAGE_HOST_SAM_BA=y
+BR2_PACKAGE_HOST_DOSFSTOOLS=y
+BR2_PACKAGE_HOST_GENIMAGE=y
+BR2_PACKAGE_HOST_MTOOLS=y
Signature · 1 line
2.5.0
#3 lore raw

PATCH v2 3/4 configs: atmel: add sama5d3 xplained sd card image generation

In reply to Ludovic Desroches

Use genimage to generate a sd card with a fat partition (at91bootstrap, u-boot, kernel, dtbs) and an ext4 partition (rootfs).

---
 board/atmel/sama5d3_xplained_mmc/genimage.cfg  | 33 ++++++++++++++++++++++++++
 board/atmel/sama5d3_xplained_mmc/post-image.sh | 14 +++++++++++
 configs/atmel_sama5d3_xplained_mmc_defconfig   |  6 +++++
 3 files changed, 53 insertions(+)
 create mode 100644 board/atmel/sama5d3_xplained_mmc/genimage.cfg
 create mode 100755 board/atmel/sama5d3_xplained_mmc/post-image.sh
board/atmel/sama5d3_xplained_mmc/genimage.cfg new file +33 -0
new file mode 100644
index 0000000..32df453
@@ -0,0 +1,33 @@
+# Image for SD card boot on Atmel SAMA5D3 Xplained boards
+#
+image boot.vfat {
+	vfat {
+		files = {
+			"zImage",
+			"at91-sama5d3_xplained.dtb",
+			"at91-sama5d3_xplained_pda4.dtb",
+			"at91-sama5d3_xplained_pda7.dtb",
+			"at91-sama5d3_xplained_pda7b.dtb",
+			"boot.bin",
+			"u-boot.bin"
+		}
+	}
+	size = 16M
+}
+
+image sdcard.img {
+	hdimage {
+	}
+
+	partition boot {
+		partition-type = 0xC
+		bootable = "true"
+		image = "boot.vfat"
+	}
+
+	partition rootfs {
+		partition-type = 0x83
+		image = "rootfs.ext4"
+		size = 512M
+	}
+}
board/atmel/sama5d3_xplained_mmc/post-image.sh new file +14 -0
new file mode 100755
index 0000000..359b4c9
@@ -0,0 +1,14 @@
+#!/bin/sh
+
+BOARD_DIR="$(dirname $0)"
+GENIMAGE_CFG="${BOARD_DIR}/genimage.cfg"
+GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
+
+rm -rf "${GENIMAGE_TMP}"
+
+genimage                               \
+	--rootpath "${TARGET_DIR}"     \
+	--tmppath "${GENIMAGE_TMP}"    \
+	--inputpath "${BINARIES_DIR}"  \
+	--outputpath "${BINARIES_DIR}" \
+	--config "${GENIMAGE_CFG}"
configs/atmel_sama5d3_xplained_mmc_defconfig +6 -0
index 2fb1fa4..c8d92bd 100644
@@ -3,6 +3,7 @@ BR2_cortex_a5=y
 BR2_ARM_ENABLE_VFP=y
 BR2_ARM_INSTRUCTIONS_THUMB2=y
 BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_1=y
+BR2_ROOTFS_POST_IMAGE_SCRIPT="board/atmel/sama5d3_xplained_mmc/post-image.sh"
 BR2_LINUX_KERNEL=y
 BR2_LINUX_KERNEL_CUSTOM_GIT=y
 BR2_LINUX_KERNEL_CUSTOM_REPO_URL="https://github.com/linux4sam/linux-at91.git"
@@ -11,6 +12,8 @@ BR2_LINUX_KERNEL_DEFCONFIG="sama5"
 BR2_LINUX_KERNEL_ZIMAGE=y
 BR2_LINUX_KERNEL_DTS_SUPPORT=y
 BR2_LINUX_KERNEL_INTREE_DTS_NAME="at91-sama5d3_xplained at91-sama5d3_xplained_pda4 at91-sama5d3_xplained_pda7 at91-sama5d3_xplained_pda7b"
+BR2_TARGET_ROOTFS_EXT2=y
+BR2_TARGET_ROOTFS_EXT2_4=y
 BR2_TARGET_AT91BOOTSTRAP3=y
 BR2_TARGET_AT91BOOTSTRAP3_CUSTOM_GIT=y
 BR2_TARGET_AT91BOOTSTRAP3_CUSTOM_REPO_URL="https://github.com/linux4sam/at91bootstrap.git"
@@ -22,3 +25,6 @@ BR2_TARGET_UBOOT_CUSTOM_GIT=y
 BR2_TARGET_UBOOT_CUSTOM_REPO_URL="https://github.com/linux4sam/u-boot-at91.git"
 BR2_TARGET_UBOOT_CUSTOM_REPO_VERSION="linux4sam_5.2"
 BR2_TARGET_UBOOT_BOARD_DEFCONFIG="sama5d3_xplained_mmc"
+BR2_PACKAGE_HOST_DOSFSTOOLS=y
+BR2_PACKAGE_HOST_GENIMAGE=y
+BR2_PACKAGE_HOST_MTOOLS=y
Signature · 1 line
2.5.0
#4 lore raw

PATCH v2 4/4 board/atmel: update documentation for SD card generation

In reply to Ludovic Desroches

Henceforth, a sdcard.img file is automatically generated. It simplifies the procedure to generate a bootable SD card for Atmel Xplained boards.

---
 board/atmel/readme.txt | 66 +++++++++++++++++++++-----------------------------
 1 file changed, 28 insertions(+), 38 deletions(-)
board/atmel/readme.txt +28 -38
index 1e86a11..f874d44 100644
@@ -43,54 +43,44 @@ goto to 'Preparing the SD card' section
 Preparing the SD card
 =====================
 
-The SD card must be partitioned with at least two partitions: one
-FAT16 partition for the bootloaders, kernel image and Device Tree
-blob, and one ext4 partition for the root filesystem. To partition the
-SD card:
+An image named sdcard.img is automatically generated. With this image, you no
+longer have to care about the creation of the partition and copying files to
+the SD card.
 
-sudo sfdisk /dev/mmcblk0 <<EOF
-,64MiB,6
-;
-EOF
+You need@least a 1GB SD card. All the data on the SD card will be lost. To
+copy the image on the SD card:
 
-This creates a 64 MB partition for the FAT16 filesystem (type 6) and
-uses the rest for the ext4 filesystem used for the root filesystem.
+/!\ Caution be sure to do it on the right mmcblk device /!\
 
-Then, format both partitions:
+dd if=output/images/sdcard.img of=/dev/mmcblk0
 
-sudo mkfs.msdos -n boot /dev/mmcblk0p1
-sudo mkfs.ext4 -L rootfs -O ^huge_file /dev/mmcblk0p2
-
- Note: the -O ^huge_file option is needed to avoid enabling the huge
- files features of ext4 (to support files larges than 2 TB), which
- needs the kernel option CONFIG_LBDAF to be enabled.
-
-Mount both partitions (if not done automatically by your system):
-
-sudo mount /dev/mmcblk0p1 /media/boot
-sudo mount /dev/mmcblk0p2 /media/rootfs
-
-Copy the bootloaders, kernel image and Device Tree blob to the first
-partition:
+Insert your SD card in your Xplained board, and enjoy. The default
+U-Boot environment will load properly the kernel and Device Tree blob
+from the first partition of the SD card, so everything works
+automatically.
 
-cp output/images/boot.bin /media/boot/
-cp output/images/u-boot.bin /media/boot/
-cp output/images/zImage /media/boot/
-cp output/images/at91-sama5d2_xplained.dtb /media/boot/
+By default a 16MB FAT partition is created. It contains at91bootstrap, u-boot,
+the kernel image and all dtb variants for your board. The dtb used is the basic
+one:
 
-Extract the root filesystem to the second partition:
+U-Boot> print
+[...]
+bootcmd=fatload mmc 1:1 0x21000000 at91-sama5d2_xplained.dtb; fatload mmc 1:1 0x22000000 zImage; bootz 0x22000000 - 0x21000000
+[...]
 
-sudo tar -C /media/rootfs -xf output/images/rootfs.tar
+If you want to use a variant such as the _pda7 one, you will have to update
+your u-boot environment:
 
-Unmount both partitions:
+U-Boot> setenv bootcmd 'fatload mmc 1:1 0x21000000 at91-sama5d2_xplained_pda7.dtb; fatload mmc 1:1 0x22000000 zImage; bootz 0x22000000 - 0x21000000'
+U-Boot> save
+Saving Environment to FAT...
+writing uboot.env
+done
 
-sudo umount /media/boot
-sudo umount /media/rootfs
+A 512MB ext4 partition is also created to store the rootfs generated.
 
-Insert your SD card in your Xplained board, and enjoy. The default
-U-Boot environment will properly load the kernel and Device Tree blob
-from the first partition of the SD card, so everything works
-automatically.
+If you want to customize the size of the partitions and their content, take a
+look at the the genimage.cfg file in the board repository.
 
 
 Flashing the NAND using SAM-BA
Signature · 1 line
2.5.0
#5 lore raw

v2 cover sd card image generation for Xplained boards

In reply to Ludovic Desroches
Quoted 8 lines · Ludovic Desroches

Use genimage to generate a SD card image

Changes
- v2:
- add missing host packages to generate the FAT partition
- cleanup post-image.sh
- update documentation

If it is ok, I'll send a v3, I have noticed some conflicts when applying my patches.

Quoted 27 lines

Ludovic Desroches (4):
configs: atmel: add sama5d2 xplained sd card image generation
configs: atmel: add sama5d4 xplained sd card image generation
configs: atmel: add sama5d3 xplained sd card image generation board/atmel: update documentation for SD card generation

 board/atmel/readme.txt                         | 66 +++++++++++---------------
 board/atmel/sama5d2_xplained_mmc/genimage.cfg  | 33 +++++++++++++
 board/atmel/sama5d2_xplained_mmc/post-image.sh | 14 ++++++
 board/atmel/sama5d3_xplained_mmc/genimage.cfg  | 33 +++++++++++++
 board/atmel/sama5d3_xplained_mmc/post-image.sh | 14 ++++++
 board/atmel/sama5d4_xplained_mmc/genimage.cfg  | 34 +++++++++++++
 board/atmel/sama5d4_xplained_mmc/post-image.sh | 14 ++++++
 configs/atmel_sama5d2_xplained_mmc_defconfig   |  6 +++
 configs/atmel_sama5d3_xplained_mmc_defconfig   |  6 +++
 configs/atmel_sama5d4_xplained_mmc_defconfig   |  7 ++-
 10 files changed, 188 insertions(+), 39 deletions(-)
 create mode 100644 board/atmel/sama5d2_xplained_mmc/genimage.cfg
 create mode 100755 board/atmel/sama5d2_xplained_mmc/post-image.sh
 create mode 100644 board/atmel/sama5d3_xplained_mmc/genimage.cfg
 create mode 100755 board/atmel/sama5d3_xplained_mmc/post-image.sh
 create mode 100644 board/atmel/sama5d4_xplained_mmc/genimage.cfg
 create mode 100755 board/atmel/sama5d4_xplained_mmc/post-image.sh
Signature · 1 line
2.5.0