[source] mvebu: add sdcard image creation script
LEDE Commits
lede-commits at lists.infradead.org
Fri Sep 2 05:44:13 PDT 2016
nbd pushed a commit to source.git, branch master:
https://git.lede-project.org/3242c076492a46ddf5da92fb4bd3de813cab56f4
commit 3242c076492a46ddf5da92fb4bd3de813cab56f4
Author: Josua Mayer <josua.mayer97 at gmail.com>
AuthorDate: Tue Aug 9 15:23:24 2016 +0200
mvebu: add sdcard image creation script
Added gen_mvebu_sdcard_img.sh to facilitate creating an fixed-size sdcard image,
adding the bootloader and populating it with actual data.
Added the required rules for creating a 4GB sdcard image according to this layout:
p0: boot (fat32)
p1: rootfs (squashfs)
p2: rootfs_data (ext4)
This should be generic to any mvebu boards that can boot from block storage.
Added the new sdcard image to the Clearfog image profile.
Signed-off-by: Josua Mayer <josua.mayer97 at gmail.com>
Signed-off-by: Felix Fietkau <nbd at nbd.name> [cleanup]
---
config/Config-images.in | 2 +-
target/linux/mvebu/image/Makefile | 37 +++++++-
target/linux/mvebu/image/boot.script | 7 ++
target/linux/mvebu/image/gen_mvebu_sdcard_img.sh | 111 +++++++++++++++++++++++
4 files changed, 154 insertions(+), 3 deletions(-)
diff --git a/config/Config-images.in b/config/Config-images.in
index b73442d..4e7f8c5 100644
--- a/config/Config-images.in
+++ b/config/Config-images.in
@@ -259,7 +259,7 @@ menu "Target Images"
config TARGET_ROOTFS_PARTSIZE
int "Root filesystem partition size (in MB)"
- depends on GRUB_IMAGES || TARGET_ROOTFS_EXT4FS || TARGET_rb532
+ depends on GRUB_IMAGES || TARGET_ROOTFS_EXT4FS || TARGET_rb532 || TARGET_mvebu
default 48
help
Select the root filesystem partition size.
diff --git a/target/linux/mvebu/image/Makefile b/target/linux/mvebu/image/Makefile
index a09cf24..05321e1 100644
--- a/target/linux/mvebu/image/Makefile
+++ b/target/linux/mvebu/image/Makefile
@@ -29,6 +29,38 @@ define Build/clearfog-bundle
gzip -9n -c $@.new > $@
endef
+# SD-Card Images:
+# these values are optimized for a 4GB labeled sdcard that actually holds 7744512 sectors of 512 byte
+# MBR: 2048 sectors
+# Partition 1: 32768 sectors
+# Partition 2: 98304 sectors (configurable)
+# Partition 3: 7611392 sectors (configurable, depends on p2 size)
+
+define Build/boot-scr
+ rm -f $@.bootscript
+ mkimage -A arm -O linux -T script -C none -a 0 -e 0 -d boot.script $@.bootscript
+endef
+
+define Build/boot-img
+ rm -f $@.boot
+ mkfs.fat -C $@.boot 16384
+ $(foreach dts,$(DEVICE_DTS), mcopy -i $@.boot $(DTS_DIR)/$(dts).dtb ::$(dts).dtb)
+ mcopy -i $@.boot $(IMAGE_KERNEL) ::zImage
+ mcopy -i $@.boot $@.bootscript ::boot.scr
+endef
+
+define Build/sdcard-img
+ rm -rf $@ $@.rootfsdata $@.tmp
+ mkdir -p $@.tmp
+ ROOTFS_SIZE=$$(( $(CONFIG_TARGET_ROOTFS_PARTSIZE) * 1024 * 2 )); \
+ DATA_SIZE=$$(( 7709696 - ($(CONFIG_TARGET_ROOTFS_PARTSIZE) * 1024 * 2) )); \
+ make_ext4fs -J -l $$DATA_SIZE $@.rootfsdata $@.tmp && \
+ ./gen_mvebu_sdcard_img.sh 7744512 $@ \
+ "$(BIN_DIR)/uboot-mvebu-clearfog/openwrt-mvebu-clearfog-u-boot-spl.kwb" \
+ c 32768 $@.boot \
+ 83 $$ROOTFS_SIZE $(IMAGE_ROOTFS) \
+ 83 $$DATA_SIZE $@.rootfsdata
+endef
define Device/Default
PROFILES := Default
@@ -150,9 +182,10 @@ define Device/armada-388-clearfog
KERNEL_INSTALL := 1
KERNEL := dtb | kernel-bin
DEVICE_TITLE := SolidRun ClearFog
- DEVICE_PACKAGES := uboot-mvebu-clearfog
- IMAGES := bundle.tar.gz
+ DEVICE_PACKAGES := uboot-mvebu-clearfog kmod-fs-ext4
+ IMAGES := bundle.tar.gz sdcard.img.gz
IMAGE/bundle.tar.gz := clearfog-bundle
+ IMAGE/sdcard.img.gz := boot-scr | boot-img | sdcard-img | gzip
IMAGE_NAME = $$(IMAGE_PREFIX)-$$(2)
endef
TARGET_DEVICES += armada-388-clearfog
diff --git a/target/linux/mvebu/image/boot.script b/target/linux/mvebu/image/boot.script
new file mode 100644
index 0000000..1ebc88b
--- /dev/null
+++ b/target/linux/mvebu/image/boot.script
@@ -0,0 +1,7 @@
+setenv bootargs console=ttyS0,115200n8 root=/dev/mmcblk0p2 rootfstype=squashfs rootwait overlay=/dev/mmcblk0p3
+setenv fdt_high 0x07a12000
+
+fatload mmc 0:1 0x02000000 zImage
+fatload mmc 0:1 0x05F00000 armada-388-clearfog.dtb
+
+bootz 0x02000000 - 0x05F00000
diff --git a/target/linux/mvebu/image/gen_mvebu_sdcard_img.sh b/target/linux/mvebu/image/gen_mvebu_sdcard_img.sh
new file mode 100755
index 0000000..8725a37
--- /dev/null
+++ b/target/linux/mvebu/image/gen_mvebu_sdcard_img.sh
@@ -0,0 +1,111 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2016 Josua Mayer
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+usage() {
+ echo "$0 <sectors> <outfile> <bootloader> [<type_partitionN> <sectors_partitionN> <img_partitionN>]?"
+}
+
+# always require first 3 arguments
+# then in pairs up to 8 more for a total of up to 4 partitions
+if [ $# -lt 3 ] || [ $# -gt 15 ] || [ $(($#%3)) -ne 0 ]; then
+ usage
+ exit 1
+fi
+
+set -e
+
+# parameters
+IMGSIZE=$1
+OUTFILE="$2"
+BOOTLOADER="$3"
+
+# calculate number of partitions from argument list
+NUMPARTS=$#
+((NUMPARTS=(NUMPARTS-3)/3))
+
+# find required applications
+FDISK=$(env PATH="/usr/local/sbin:/usr/sbin:/sbin:$PATH" which fdisk)
+
+# generate image file
+printf "Creating $OUTFILE from /dev/zero: "
+dd if=/dev/zero of="$OUTFILE" bs=512 count=1 >/dev/null
+printf "Done\n"
+
+# generate fdisk argument list
+printf "Generating fdisk argument list: "
+ARGSFILE=$(mktemp)
+
+# empty partition table
+printf "o\n" >> $ARGSFILE
+
+# actual partitions
+offset=2048
+for i in $(seq 1 1 $NUMPARTS); do
+ ((n=3+3*i-2)); type=$(eval echo \${$n})
+ ((n=3+3*i-1)); size=$(eval echo \${$n})
+ ((end=offset+size-1))
+
+ printf "n\np\n%i\n\n%i\n" $i $end >> $ARGSFILE
+
+ # special case on first aprtition: fdisk wont ask which one
+ if [ $i -eq 1 ]; then
+ printf "t\n%s\n" $type >> $ARGSFILE
+ else
+ printf "t\n%i\n%s\n" $i $type >> $ARGSFILE
+ fi
+
+ # add this partitions size to offset for next partition
+ ((offset=end+1))
+done
+
+# write and exit
+printf "w\n" >> $ARGSFILE
+
+printf "Done\n"
+
+# create real partition table using fdisk
+printf "Creating partition table: "
+cat $ARGSFILE | $FDISK "$OUTFILE" >/dev/null
+printf "Done\n"
+
+# remove temporary files
+printf "Cleaning up: "
+rm -f $ARGSFILE
+printf "Done\n"
+
+# install bootloader
+printf "Writing bootloader: "
+dd of="$OUTFILE" if="$BOOTLOADER" bs=512 seek=1 conv=notrunc 2>/dev/null
+printf "Done\n"
+
+# write partition data
+
+# offset of first partition is 2048
+offset=2048
+for i in $(seq 1 1 $NUMPARTS); do
+ ((n=3+3*i-1)); size=$(eval echo \${$n})
+ ((n=3+3*i)); img="$(eval echo \${$n})"
+
+ printf "Writing %s to partition %i: " "$img" $i
+ dd if="$img" of="$OUTFILE" bs=512 seek=$offset conv=notrunc 2>/dev/null
+ printf "Done\n"
+
+ # add this partitions size to offset for next partition
+ ((offset=offset+size))
+done
More information about the lede-commits
mailing list