rootfsinstall: new target platform option -cubox

This commit is contained in:
Silvan Calarco 2013-11-10 15:37:27 +01:00
parent 36f4b5abeb
commit 2a9f821f6b

View File

@ -4,10 +4,15 @@
# Based on rpi-install by: Davide Madrisan
# Modified by: Silvan Calarco <silvan.calarco@mambasoft.it>
#
SYSTEMFSTYPE=ext4
function usage() {
echo "Usage: $0 device rootfs-archive [-y] [-rpi] [-fs fstype] [-a archive] [-c command] [-k kernel] [-p password]"
echo "Usage: $0 device rootfs-archive [-rpi|-cubox] [-a archive] [-c command] [-fs fstype] [-k kernel] [-p password] [-y]"
echo
echo "Target platform (optional):"
echo "-rpi : make a RaspberryPi SD with boot partition"
echo "-cubox : make a Cubox SD with boot partition"
echo
echo "Options:"
echo "-a archive : additional archive to unpack in rootfs root"
@ -15,9 +20,8 @@ function usage() {
echo "-c command : command to run through chroot in rootfs"
echo "-fs fstype : filesystem type for system partition (default: ext4)"
echo "-h hostname : set given hostname"
echo "-k kernel : extract/use kernel file from ROOTFS/boot/ for boot"
echo "-k kernel : extract and use specified kernel file from ROOTFS/boot/ for boot"
echo "-p password : set given password for root user"
echo "-rpi : make a RaspberryPi SD with boot partition"
echo "-y : assume yes to all questions (script mode)"
echo
echo "Example: $0 /dev/sdb /tmp/openmamba-rootfs-light.arm.tar.xz"
@ -32,7 +36,8 @@ function usage() {
while [ "$1" ]; do
case $1 in
-y) ASSUMEYES=1 ;;
-rpi) RPIMODE=1 ;;
-cubox) TARGETDEVICE=cubox ;;
-rpi) TARGETDEVICE=rpi ;;
-fs) [ "$2" ] || {
echo "Error: -fs option requires an argument; aborting."
exit 1
@ -111,8 +116,36 @@ else
PARTITION2=${DRIVE}2
fi
# FIXME: in non rpi mode we only have system partition
[ "$RPIMODE" ] || PARTITION2=$PARTITION1
case $TARGETDEVICE in
rpi) BOOTFSTYPE=fat32
BOOTFSSIZE=40M
KERNELDEST="@BOOT@/kernel.img"
;;
cubox) BOOTFSTYPE=ext3
BOOTFSSIZE=20M
KERNELDEST="@BOOT@/boot/uImage"
;;
*) BOOTFSTYPE=
if [ "$USEKERNEL" ]; then
KERNELDEST="/tmp/$USEKERNEL"
else
KERNELDEST=
fi
PARTITION2=$PARTITION1 ;;
esac
[ -r "$ROOTFSARCHIVE" ] || {
echo "ERROR: unable to read rootfs archive $ROOTFSARCHIVE; aborting."
exit 1
}
echo "Rootfs archive : $ROOTFSARCHIVE"
echo "Target SD card : ${DRIVE}"
[ "$TARGETDEVICE" ] && echo "Target platform: $TARGETDEVICE"
[ "$BOOTFSTYPE" ] && echo "Boot fs : $BOOTFSTYPE($BOOTFSSIZE)"
[ "$BOOTFSTYPE" ] && echo "System fs : $SYSTEMFSTYPE"
[ "$USEKERNEL" ] && echo "Kernel : $USEKERNEL -> $KERNELDEST"
echo
[ "$ASSUMEYES" ] || {
echo -n "All current data in ${DRIVE} will be lost, do you want to proceed [y/N]?"
@ -125,14 +158,14 @@ if [ "$?" != "0" ]; then
echo "ERROR: parted exited with error $? while creating partition table on ${DRIVE}; aborting."
fi
if [ "$RPIMODE" ]; then
if [ "$BOOTFSTYPE" ]; then
# FAT partition
sudo parted -s -a cyl -- ${DRIVE} mkpart primary fat32 0 40M
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $BOOTFSTYPE 0 $BOOTFSSIZE
if [ "$?" != "0" ]; then
echo "ERROR: parted exited with error $? while creating boot partition on ${DRIVE}; aborting."
fi
# rootfs partition
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $SYSTEMFSTYPE 40M -1
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $SYSTEMFSTYPE $BOOTFSSIZE -1
if [ "$?" != "0" ]; then
echo "ERROR: parted exited with error $? while creating system partition on ${DRIVE}; aborting."
fi
@ -145,12 +178,18 @@ else
fi
sync
if [ "$RPIMODE" ]; then
echo "Formatting $PARTITION1 (vfat) ..."
mkfs.vfat -s 1 -F 32 -n "BOOT" $PARTITION1 || {
echo "ERROR: unable to format $PARTITION1; aborting."
exit 1
}
if [ "$BOOTFSTYPE" ]; then
echo "Formatting $PARTITION1 ($BOOTFSTYPE) ..."
case "$BOOTFSTYPE" in
vfat) mkfs.vfat -s 1 -F 32 -n "BOOT" $PARTITION1 || {
echo "ERROR: unable to format $PARTITION1; aborting."
exit 1
} ;;
ext*) mke2fs -q -t $BOOTFSTYPE -j -L "BOOT" $PARTITION1 || {
echo "ERROR: unable to format $PARTITION1; aborting."
exit 1
} ;;
esac
fi
echo "Formatting $PARTITION2 ($SYSTEMFSTYPE)..."
@ -173,7 +212,14 @@ mount $PARTITION2 $ROOTMP || {
}
trap "[ -e $ROOTMP ] && umount $ROOTMP;[ -e $BOOTMP ] && umount $BOOTMP" 0 HUP INT QUIT ABRT KILL TERM
if [ "$RPIMODE" ]; then
if [ "$BOOTFSTYPE" ]; then
mount $PARTITION1 $BOOTMP || {
echo "ERROR: unable to mount partition $PARTITION1; aborting."
exit 1
}
fi
if [ "$TARGETDEVICE" = "rpi" ]; then
### SD-Card: install software
if [ ! "$USEKERNEL" ]; then
@ -185,11 +231,6 @@ if [ "$RPIMODE" ]; then
echo "Fetching firmware boot files from git..."
fi
mount $PARTITION1 $BOOTMP || {
echo "ERROR: unable to mount partition $PARTITION1; aborting."
exit 1
}
# bootcode.bin: 2nd stage bootloader, starts with SDRAM disabled
# loader.bin : 3rd stage bootloader, starts with SDRAM enabled
# start.elf : The GPU binary firmware image, provided by the foundation
@ -242,7 +283,22 @@ framebuffer_ignore_alpha=1" > $BOOTMP/config.txt
fi
[ "$SWHOME" -a "${SWHOME:0:4}" = "/tmp" ] && rm -rf $SWHOME
fi # rpimode
elif [ "$TARGETDEVICE" = "cubox" ]; then
mkdir -p $BOOTMP/boot
echo "Creating u-boot boot.scr..."
cat > $BOOTMP/boot/boot.txt << _EOF
setenv bootargs 'console=ttyS0,115200n8 vmalloc=384M root=/dev/mmcblk0p2 video=dovefb:lcd0:1920x1080-32@60-edid clcd.lcd0_enable=1 clcd.
lcd1_enable=0'
echo ======== Loading kernel ========
ext2load mmc 0:1 0x00200000 /boot/uImage
echo ======== Booting kernel ========
bootm
_EOF
mkimage -A arm -O linux -T script -C none -n "u-boot commands" -d $BOOTMP/boot/boot.txt $BOOTMP/boot/boot.scr || {
echo "ERROR: mkimage: error creating boot.scr; aborting."
exit 1
}
fi
(
cd $ROOTMP >/dev/null || {
@ -275,23 +331,16 @@ fi # rpimode
[ $? -eq 0 ] || exit $?
KERNELDEST=`echo $KERNELDEST | sed "s|@BOOT@|$BOOTMP|g"`
if [ "$USEKERNEL" ]; then
if [ "$RPIMODE" ]; then
KERNELDEST=$BOOTMP/kernel.img
else
KERNELDEST=/tmp/$USEKERNEL
fi
if [ -r $ROOTMP/boot/$USEKERNEL ]; then
cp $ROOTMP/boot/$USEKERNEL $KERNELDEST || {
echo "ERROR: unable to find or copy kernel $USEKERNEL; aborting."
exit 1
}
if [ -e /tmp/$USEKERNEL ]; then
echo "Extracted kernel is available as $KERNELDEST"
fi
echo "Kernel image available as $KERNELDEST"
else
echo "ERROR: can't find kernel file $ROOTMP/boot/$USERKERNEL; aborting."
exit 1
echo "WARNING: can't find kernel file $ROOTMP/boot/$USERKERNEL"
fi
fi
@ -324,7 +373,7 @@ if [ "$CHROOTCOMMAND" ]; then
fi
sync
if [ "$RPIMODE" ]; then
if [ "$BOOTFSTYPE" ]; then
umount $PARTITION1
rmdir $BOOTMP
fi