[OpenWrt-Devel] [PATCH v4 1/4] mvebu: add squashfs image type to MMCProfile
josua.mayer97 at gmail.com
josua.mayer97 at gmail.com
Wed May 4 15:24:25 EDT 2016
From: Josua Mayer <josua.mayer97 at gmail.com>
Added gen_mvebu_sdcard_img.sh to create bootable sdcard images. It takes
the bootloader and partition images to create a bootable sdcard image.
Partition Layout:
p1: fat32: for kernel, dtb and boot config files if any
p2: squashfs: for openwrt
This change is developed for the Clearfog, but should work on all A38x
SoCs that can boot from mmc.
Signed-off-by: Josua Mayer <josua.mayer97 at gmail.com>
---
target/linux/mvebu/image/Makefile | 16 ++++
target/linux/mvebu/image/gen_mvebu_sdcard_img.sh | 100 +++++++++++++++++++++++
tools/Makefile | 1 +
3 files changed, 117 insertions(+)
create mode 100755 target/linux/mvebu/image/gen_mvebu_sdcard_img.sh
diff --git a/target/linux/mvebu/image/Makefile b/target/linux/mvebu/image/Makefile
index cb73c3b..fc5fded 100644
--- a/target/linux/mvebu/image/Makefile
+++ b/target/linux/mvebu/image/Makefile
@@ -107,6 +107,9 @@ define MMCProfile
ifneq ($(CONFIG_TARGET_ROOTFS_INITRAMFS),)
$(call Image/Build/Profile,$(1)/Initramfs)
endif
+ ifneq ($(CONFIG_TARGET_ROOTFS_SQUASHFS),)
+ $(call Image/Build/squashfs)
+ endif
endef
define Image/Build/Profile/$(1)/Initramfs
@@ -114,6 +117,19 @@ define MMCProfile
cp $(KDIR)/uImage-initramfs-$(2) $(BIN_DIR)/$(IMG_PREFIX)-$(2)-initramfs
endef
+ define Image/Build/Profile/$(1)/squashfs
+ $(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
+ cp $(KDIR)/root.squashfs $(BIN_DIR)/$(IMG_PREFIX)-$(2)-root.squashfs
+ rm -f $(BIN_DIR)/$(IMG_PREFIX)-$(2)-boot.fat32
+ mkfs.fat -C $(BIN_DIR)/$(IMG_PREFIX)-$(2)-boot.fat32 $(shell echo $$((4*1024)) # 4MB)
+ mcopy -i $(BIN_DIR)/$(IMG_PREFIX)-$(2)-boot.fat32 $(KDIR)/zImage ::
+ mcopy -i $(BIN_DIR)/$(IMG_PREFIX)-$(2)-boot.fat32 $(DTS_DIR)/$(2).dtb ::
+ ./gen_mvebu_sdcard_img.sh "$(BIN_DIR)/$(IMG_PREFIX)-$(2)-squashfs-sdcard.img" \
+ "$(BIN_DIR)/uboot-mvebu-clearfog/openwrt-mvebu-clearfog-u-boot-spl.kwb" \
+ c "$(BIN_DIR)/$(IMG_PREFIX)-$(2)-boot.fat32" \
+ 83 "$(BIN_DIR)/$(IMG_PREFIX)-$(2)-root.squashfs"
+ endef
+
PROFILES_LIST += $(1)
endef
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..88d017a
--- /dev/null
+++ b/target/linux/mvebu/image/gen_mvebu_sdcard_img.sh
@@ -0,0 +1,100 @@
+#!/bin/bash -x
+#
+# 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 <outfile> <bootloader> [<type_partitionN> <img_partitionN>]?"
+}
+
+# always require first 2 arguments
+# then in pairs up to 8 more for a total of up to 4 partitions
+if [ $# -lt 2 ] || [ $# -gt 10 ] || [ $((($#-2)%2)) -ne 0 ]; then
+ usage
+ exit 1
+fi
+
+# static settings
+SDCARD_HEADS=16
+SDCARD_SECTORS=63
+SDCARD_ALIGNMENT=4096
+
+# parameters
+OUTFILE="$1"
+BOOTLOADER="$2"
+# up to 4 partitions
+# when calculating size of images in Kilobytes, NEVER round down!
+PART1_TYPE=$3
+PART1_IMG="$4"
+PART1_SIZE=$((($(stat --print="%s" "$PART1_IMG")+1023)/1024))K
+PART2_TYPE=$5
+PART2_IMG="$6"
+PART2_SIZE=$((($(stat --print="%s" "$PART2_IMG")+1023)/1024))K
+PART3_TYPE=$7
+PART3_IMG="$8"
+PART3_SIZE=$((($(stat --print="%s" "$PART3_IMG")+1023)/1024))K
+PART4_TYPE=$9
+PART4_IMG="${10}"
+PART4_SIZE=$((($(stat --print="%s" "$PART4_IMG")+1023)/1024))K
+
+# So how many partitions were given?
+numparts=$((($#-2)/2))
+case $numparts in
+ 0)
+ set `ptgen -o "$OUTFILE" \
+ -h $SDCARD_HEADS -s $SDCARD_SECTORS -l $SDCARD_ALIGNMENT`
+ dd of="$OUTFILE" if="$BOOTLOADER" bs=512 seek=1 conv=notrunc
+ ;;
+ 1)
+ set `ptgen -o "$OUTFILE" \
+ -h $SDCARD_HEADS -s $SDCARD_SECTORS -l $SDCARD_ALIGNMENT \
+ -t $PART1_TYPE -p $PART1_SIZE`
+ dd of="$OUTFILE" if="$PART1_IMG" bs=512 seek=$(($1/512)) conv=notrunc
+ ;;
+ 2)
+ set `ptgen -o "$OUTFILE" \
+ -h $SDCARD_HEADS -s $SDCARD_SECTORS -l $SDCARD_ALIGNMENT \
+ -t $PART1_TYPE -p $PART1_SIZE \
+ -t $PART2_TYPE -p $PART2_SIZE`
+ dd of="$OUTFILE" if="$BOOTLOADER" bs=512 seek=1 conv=notrunc
+ dd of="$OUTFILE" if="$PART1_IMG" bs=512 seek=$(($1/512)) conv=notrunc
+ dd of="$OUTFILE" if="$PART2_IMG" bs=512 seek=$(($2/512)) conv=notrunc
+ ;;
+ 3)
+ set `ptgen -o "$OUTFILE" \
+ -h $SDCARD_HEADS -s $SDCARD_SECTORS -l $SDCARD_ALIGNMENT \
+ -t $PART1_TYPE -p $PART1_SIZE \
+ -t $PART2_TYPE -p $PART2_SIZE \
+ -t $PART3_TYPE -p $PART3_SIZE`
+ dd of="$OUTFILE" if="$BOOTLOADER" bs=512 seek=1 conv=notrunc
+ dd of="$OUTFILE" if="$PART1_IMG" bs=512 seek=$(($1/512)) conv=notrunc
+ dd of="$OUTFILE" if="$PART2_IMG" bs=512 seek=$(($2/512)) conv=notrunc
+ dd of="$OUTFILE" if="$PART3_IMG" bs=512 seek=$(($3/512)) conv=notrunc
+ ;;
+ 4)
+ set `ptgen -o "$OUTFILE" \
+ -h $SDCARD_HEADS -s $SDCARD_SECTORS -l $SDCARD_ALIGNMENT \
+ -t $PART1_TYPE -p $PART1_SIZE \
+ -t $PART2_TYPE -p $PART2_SIZE \
+ -t $PART3_TYPE -p $PART3_SIZE \
+ -t $PART4_TYPE -p $PART4_SIZE`
+ dd of="$OUTFILE" if="$BOOTLOADER" bs=512 seek=1 conv=notrunc
+ dd of="$OUTFILE" if="$PART1_IMG" bs=512 seek=$(($1/512)) conv=notrunc
+ dd of="$OUTFILE" if="$PART2_IMG" bs=512 seek=$(($2/512)) conv=notrunc
+ dd of="$OUTFILE" if="$PART3_IMG" bs=512 seek=$(($3/512)) conv=notrunc
+ dd of="$OUTFILE" if="$PART4_IMG" bs=512 seek=$(($4/512)) conv=notrunc
+esac
diff --git a/tools/Makefile b/tools/Makefile
index 187655e..9a08573 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -38,6 +38,7 @@ tools-$(CONFIG_TARGET_x86) += qemu
tools-$(CONFIG_TARGET_mxs) += elftosb sdimage
tools-$(CONFIG_TARGET_brcm2708)$(CONFIG_TARGET_sunxi)$(CONFIG_TARGET_mxs) += mtools dosfstools
tools-$(CONFIG_TARGET_ar71xx) += lzma-old squashfs
+tools-$(CONFIG_TARGET_mvebu) += squashfs dosfstools
tools-y += lzma squashfs4
tools-$(BUILD_B43_TOOLS) += b43-tools
tools-$(BUILD_PPL_CLOOG) += ppl cloog
--
2.6.6
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list