[OpenWrt-Devel] [PATCH] brcm2708: add script for creating SD partitions and one more missing symbol

Álvaro Fernández Rojas noltari at gmail.com
Tue Feb 17 11:12:05 EST 2015


Signed-off-by: Álvaro Fernández Rojas <noltari at gmail.com>
---
 target/linux/brcm2708/config-3.18            |   1 +
 target/linux/brcm2708/image/Config.in        |  13 +-
 target/linux/brcm2708/image/Makefile         |  32 ++++-
 target/linux/brcm2708/image/create_sdcard.sh | 191 +++++++++++++++++++++++++++
 4 files changed, 235 insertions(+), 2 deletions(-)
 create mode 100755 target/linux/brcm2708/image/create_sdcard.sh

diff --git a/target/linux/brcm2708/config-3.18 b/target/linux/brcm2708/config-3.18
index 873a0f6..d700210 100644
--- a/target/linux/brcm2708/config-3.18
+++ b/target/linux/brcm2708/config-3.18
@@ -258,6 +258,7 @@ CONFIG_USB_UAS=y
 CONFIG_USB_USBNET=y
 CONFIG_VECTORS_BASE=0xffff0000
 CONFIG_VFP=y
+# CONFIG_VIDEO_BCM2835 is not set
 # CONFIG_VMSPLIT_2G is not set
 # CONFIG_VMSPLIT_3G is not set
 CONFIG_VT=y
diff --git a/target/linux/brcm2708/image/Config.in b/target/linux/brcm2708/image/Config.in
index f7abd9d..b6aea19 100644
--- a/target/linux/brcm2708/image/Config.in
+++ b/target/linux/brcm2708/image/Config.in
@@ -1,5 +1,16 @@
+config BRCM2708_BOOTFS_TGZ
+	bool "Build a compressed tar archive of the boot filesystem."
+	depends on TARGET_brcm2708
+	default y
+
+config BRCM2708_SD_SCRIPT
+	bool "Include SD creation script"
+	depends on TARGET_brcm2708
+	select BRCM2708_BOOTFS_TGZ
+	select TARGET_ROOTFS_TARGZ
+	default y
+
 config BRCM2708_SD_BOOT_PARTSIZE
 	int "Boot (SD Card) filesystem partition size (in MB)"
 	depends on TARGET_brcm2708
 	default 20
-
diff --git a/target/linux/brcm2708/image/Makefile b/target/linux/brcm2708/image/Makefile
index ae977a6..56e6f48 100644
--- a/target/linux/brcm2708/image/Makefile
+++ b/target/linux/brcm2708/image/Makefile
@@ -1,5 +1,5 @@
 # 
-# Copyright (C) 2012 OpenWrt.org
+# Copyright (C) 2012-2015 OpenWrt.org
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -28,6 +28,36 @@ define Image/Build/RaspberryPi
 	mcopy -i $(KDIR)/boot.img $(KDIR)/Image ::kernel.img  # Copy OpenWrt built kernel
 	./gen_rpi_sdcard_img.sh $(BIN_DIR)/$(IMG_PREFIX)-sdcard-vfat-$(1).img $(KDIR)/boot.img $(KDIR)/root.$(1) \
 		$(CONFIG_BRCM2708_SD_BOOT_PARTSIZE) $(CONFIG_TARGET_ROOTFS_PARTSIZE)
+
+ ifeq ($(CONFIG_BRCM2708_BOOTFS_TGZ),y)
+	rm -rf $(BUILD_DIR)/brcm2708-bootfs
+	mkdir -p $(BUILD_DIR)/brcm2708-bootfs
+
+	$(CP) $(BUILD_DIR)/brcm2708-gpu-fw-boot/bootcode.bin $(BUILD_DIR)/brcm2708-bootfs/
+	$(CP) $(BUILD_DIR)/brcm2708-gpu-fw-boot/COPYING.linux $(BUILD_DIR)/brcm2708-bootfs/
+	$(CP) $(BUILD_DIR)/brcm2708-gpu-fw-boot/LICENCE.broadcom $(BUILD_DIR)/brcm2708-bootfs/
+	$(CP) $(BUILD_DIR)/brcm2708-gpu-fw-boot/start.elf $(BUILD_DIR)/brcm2708-bootfs/
+	$(CP) $(BUILD_DIR)/brcm2708-gpu-fw-boot/start_cd.elf $(BUILD_DIR)/brcm2708-bootfs/
+	$(CP) $(BUILD_DIR)/brcm2708-gpu-fw-boot/fixup.dat $(BUILD_DIR)/brcm2708-bootfs/
+	$(CP) $(BUILD_DIR)/brcm2708-gpu-fw-boot/fixup_cd.dat $(BUILD_DIR)/brcm2708-bootfs/
+	$(CP) cmdline.txt $(BUILD_DIR)/brcm2708-bootfs/
+	$(CP) config.txt $(BUILD_DIR)/brcm2708-bootfs/
+	$(CP) $(KDIR)/Image $(BUILD_DIR)/brcm2708-bootfs/kernel.img
+
+	$(TAR) -czpf $(BIN_DIR)/$(IMG_PREFIX)-$(PROFILE)-bootfs.tar.gz --numeric-owner --owner=0 --group=0 -C $(BUILD_DIR)/brcm2708-bootfs/ .
+ endif
+
+ ifeq ($(CONFIG_BRCM2708_SD_SCRIPT),y)
+	$(CP) create_sdcard.sh $(BIN_DIR)
+
+	rm -f $(BIN_DIR)/config_sdcard
+	touch $(BIN_DIR)/config_sdcard
+	echo -e "BOOT_SIZE=$(CONFIG_BRCM2708_SD_BOOT_PARTSIZE)" >> $(BIN_DIR)/config_sdcard
+	echo -e "BOOTFS_FILE=$(IMG_PREFIX)-$(PROFILE)-bootfs.tar.gz" >> $(BIN_DIR)/config_sdcard
+	echo -e "ROOTFS_FILE=$(IMG_PREFIX)-$(PROFILE)-rootfs.tar.gz" >> $(BIN_DIR)/config_sdcard
+
+	$(TAR) -zcvf $(BIN_DIR)/$(IMG_PREFIX)-createsd.tar.gz -C $(BIN_DIR)/ $(IMG_PREFIX)-$(PROFILE)-bootfs.tar.gz $(IMG_PREFIX)-$(PROFILE)-rootfs.tar.gz config_sdcard create_sdcard.sh
+ endif
 endef
 
 define Image/Build
diff --git a/target/linux/brcm2708/image/create_sdcard.sh b/target/linux/brcm2708/image/create_sdcard.sh
new file mode 100755
index 0000000..93eb5fa
--- /dev/null
+++ b/target/linux/brcm2708/image/create_sdcard.sh
@@ -0,0 +1,191 @@
+#!/bin/sh
+
+. ./config_sdcard
+
+################################################################################
+#      Based on OpenELEC create_sdcard - http://www.openelec.tv
+#      Copyright (C) 2009-2014 Stephan Raue (stephan at openelec.tv)
+#      Copyright (C) 2015 Álvaro Fernández Rojas (noltari at gmail.com)
+################################################################################
+
+# usage:   sudo ./create_sdcard <drive>
+# example: sudo ./create_sdcard /dev/sdb
+
+if [ "$(id -u)" != "0" ]; then
+  clear
+  echo "#########################################################"
+  echo "# please execute with 'sudo' or -DANGEROUS!!!- as root  #"
+  echo "# example: sudo ./create_sdcard <drive>                 #"
+  echo "#########################################################"
+  exit 1
+fi
+
+if [ -z "$1" ]; then
+  clear
+  echo "#########################################################"
+  echo "# please execute with your drive as option              #"
+  echo "# example: sudo ./create_sdcard /dev/sdb                #"
+  echo "# or:      sudo ./create_sdcard /dev/mmcblk0            #"
+  echo "#########################################################"
+  exit 1
+fi
+
+DISK="$1"
+case $DISK in
+  "/dev/mmcblk"*)
+    PART1="${DISK}p1"
+    PART2="${DISK}p2"
+    ;;
+  *)
+    PART1="${DISK}1"
+    PART2="${DISK}2"
+    ;;
+esac
+
+clear
+echo "#########################################################"
+echo "#                                                       #"
+echo "#                OpenWRT SD Installer                   #"
+echo "#                                                       #"
+echo "#########################################################"
+echo "#                                                       #"
+echo "#     This will wipe any data off your chosen drive     #"
+echo "# Please read the instructions and use very carefully.. #"
+echo "#                                                       #"
+echo "#########################################################"
+
+# check for some required tools
+
+  # this is needed to partion the drive
+  which parted > /dev/null
+  if [ "$?" = "1" ]; then
+    clear
+    echo "#########################################################"
+    echo "#                                                       #"
+    echo "# OpenWRT missing tool - Installation will quit         #"
+    echo "#                                                       #"
+    echo "#      We can't find the required tool \"parted\"         #"
+    echo "#      on your system.                                  #"
+    echo "#      Please install it via your package manager.      #"
+    echo "#                                                       #"
+    echo "#########################################################"
+    exit 1
+  fi
+
+  # this is needed to format the drive
+  which mkfs.vfat > /dev/null
+  if [ "$?" = "1" ]; then
+    clear
+    echo "#########################################################"
+    echo "#                                                       #"
+    echo "# OpenWRT missing tool - Installation will quit         #"
+    echo "#                                                       #"
+    echo "#      We can't find the required tool \"mkfs.vfat\"      #"
+    echo "#      on your system.                                  #"
+    echo "#      Please install it via your package manager.      #"
+    echo "#                                                       #"
+    echo "#########################################################"
+    exit 1
+  fi
+
+  # this is needed to format the drive
+  which mkfs.ext4 > /dev/null
+  if [ "$?" = "1" ]; then
+    clear
+    echo "#########################################################"
+    echo "#                                                       #"
+    echo "# OpenWRT missing tool - Installation will quit         #"
+    echo "#                                                       #"
+    echo "#      We can't find the required tool \"mkfs.ext4\"      #"
+    echo "#      on your system.                                  #"
+    echo "#      Please install it via your package manager.      #"
+    echo "#                                                       #"
+    echo "#########################################################"
+    exit 1
+  fi
+
+  # this is needed to tell the kernel for partition changes
+  which partprobe > /dev/null
+  if [ "$?" = "1" ]; then
+    clear
+    echo "#########################################################"
+    echo "#                                                       #"
+    echo "# OpenWRT missing tool - Installation will quit         #"
+    echo "#                                                       #"
+    echo "#      We can't find the required tool \"partprobe\"      #"
+    echo "#      on your system.                                  #"
+    echo "#      Please install it via your package manager.      #"
+    echo "#                                                       #"
+    echo "#########################################################"
+    exit 1
+  fi
+
+# (TODO) umount everything (if more than one partition)
+  umount ${DISK}*
+
+# remove all partitions from the drive
+  echo "writing new disklabel on $DISK (removing all partitions)..."
+  parted -s "$DISK" mklabel msdos
+
+# create a single partition
+  echo "creating partitions on $DISK..."
+  parted -s "$DISK" mkpart primary fat32 -- 0 ${BOOT_SIZE}MiB 
+# align the partition on 4mb boundary
+  parted -s "$DISK" mkpart primary ext2 -- $(($BOOT_SIZE + 4))MiB -2cyl
+
+# make partition active (bootable)
+  echo "marking partition active..."
+  parted -s "$DISK" set 1 boot on
+
+# tell kernel we have a new partition table
+  echo "telling kernel we have a new partition table..."
+  partprobe "$DISK"
+
+# create filesystem
+  echo "creating filesystem on $PART1..."
+  mkfs.vfat "$PART1" -I -n boot
+
+# create ext4 partition with optimized settings for running on flash/sd
+# See http://blogofterje.wordpress.com/2012/01/14/optimizing-fs-on-sd-card/ for reference.
+  echo "creating filesystem on $PART2..."
+  mkfs.ext4 -O ^has_journal -E stride=2,stripe-width=1024 -b 4096 "$PART2" -L rootfs
+
+# mount partitions
+  MNT_BOOT=/tmp/openwrt_boot
+  MNT_ROOTFS=/tmp/openwrt_rootfs
+
+  echo "mounting partition $PART1 on $MNT_BOOT..."
+  rm -rf $MNT_BOOT
+  mkdir -p $MNT_BOOT
+  mount -t vfat "$PART1" $MNT_BOOT
+
+  echo "mounting partition $PART2 on $MNT_ROOTFS..."
+  rm -rf $MNT_ROOTFS
+  mkdir -p $MNT_ROOTFS
+  mount -t ext4 "$PART2" $MNT_ROOTFS
+
+# copy boot files
+  echo "copying bootloader files to $MNT_BOOT..."
+  tar -zxvf $BOOTFS_FILE -C $MNT_BOOT
+
+# copy rootfs files
+  echo "copying rootfs files to $MNT_ROOTFS..."
+  tar -zxvf $ROOTFS_FILE -C $MNT_ROOTFS
+
+# sync disk
+  echo "syncing disk..."
+  sync
+
+# unmount partitions
+  echo "unmounting partition $MNT_BOOT..."
+  umount $MNT_BOOT
+
+  echo "unmounting partition $MNT_ROOTFS..."
+  umount $MNT_ROOTFS
+
+# cleaning
+  echo "cleaning tempdirs..."
+  rmdir $MNT_BOOT
+  rmdir $MNT_ROOTFS
+
+echo "...installation finished"
-- 
1.9.1
_______________________________________________
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