dinstall-rpi.sh: add a script for preparing a SD card for Raspberry PI with openmamba-rootfs-light

This commit is contained in:
Silvan Calarco 2012-09-20 11:03:39 +02:00
parent a4ef3dc7b0
commit 006df4c5be

123
src/sdinstall-rpi.sh Executable file
View File

@ -0,0 +1,123 @@
### SD-Card: create partitions and fileysytems
#
# Created by: Davide Madrisan
# Modified by: Silvan Calarco <silvan.calarco@mambasoft.it>
#
DRIVE=$1
ROOTFSARCHIVE=$2
[ "$DRIVE" -a "$ROOTFSARCHIVE" ] || {
echo "Usage: $0 device rootfs-archive"
echo
echo "Example: $0 /dev/sdb /tmp/openmamba-rootfs-light.arm.tar.xz"
exit 1
}
[ $UID -eq 0 ] || {
echo "ERROR: this script must be called as root; aborting."
exit 1
}
if [ "${DRIVE:0:11}" = "/dev/mmcblk" ]; then
PARTITION1=${DRIVE}p1
PARTITION2=${DRIVE}p2
else
PARTITION1=${DRIVE}1
PARTITION2=${DRIVE}2
fi
dd if=/dev/zero of=$DRIVE bs=1024 count=1024
set -- $(LC_ALL=C fdisk -l "$DRIVE" | grep "^Disk.*bytes$")
SIZE="$5"
echo Disk Size: $SIZE bytes
CYLINDERS=`echo $SIZE/255/63/512 | bc`
echo Cylinders: $CYLINDERS
{
echo ,9,0x0C,*
echo ,,,-
} | sfdisk -D -H 255 -S 63 -C $CYLINDERS $DRIVE
mkfs.vfat -F 32 -n "boot" $PARTITION1
mke2fs -t ext4 -j -L "openmamba" $PARTITION2
### SD-Card: install software
SWHOME=`mktemp -d`
cd $SWHOME
git clone git://github.com/raspberrypi/firmware.git --depth=1
BOOTMP=/media/boot
ROOTMP=/media/openmamba
[ -e /media/boot -o -e /media/openmamba ] && {
echo "ERROR: /media/boot or /media/openmamba already exist."
exit 1
}
udisks --mount $PARTITION1
udisks --mount $PARTITION2
# 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
# kernel.img : The OS kernel to load on the ARM processor.
for f in bootcode.bin loader.bin arm*_start.elf kernel*.img; do
cp $SWHOME/firmware/boot/$f $BOOTMP/
done
# use arm224_start.elf (224M system, 32MB GPU split) firmware by default
cp $BOOTMP/arm224_start.elf $BOOTMP/start.elf
# cmdline.txt : parameters passed to the kernel on boot
echo "\
dwc_otg.lpm_enable=0 \
console=ttyAMA0,115200 \
kgdboc=ttyAMA0,115200 \
console=tty1 \
root=/dev/mmcblk0p2 \
rootfstype=ext4 \
elevator=deadline \
rootwait" > $BOOTMP/cmdline.txt
#debug=1 \
# optional files:
# config.txt : A configuration file read by the GPU.
# Use this to override set the video mode, alter system clock
# speeds, voltages, etc.
# vlls directory: Additional GPU code, e.g. extra codecs.
# Not present in the initial release.
pushd $ROOTMP >/dev/null
tar xvf $ROOTFSARCHIVE
popd >/dev/null
# copy kernel modules
mkdir -p $ROOTMP/lib/modules
cp -a $SWHOME/firmware/modules/* $ROOTMP/lib/modules/
## swhitch to runlevel 1
#sed -i "s@^id:[0-9]:\(.*\)@id:1:\1@" \
# $ROOTMP/etc/inittab
## remove root password
## default: root:$1$7QJBkeh1$Dd.G4kEYQT2c6x4kLMrAS.:15418:0:99999:7:::0
#sed -i "s@^root:[^:]*\(.*\)@root:\1@" \
# $ROOTMP/etc/shadow
#
## /proc/bus/usb/ does not exist
#sed -i "s@^usbfs.*@#&@" $ROOTMP/etc/fstab
#
#sed -i "\
#s@^multithread=1@multithread=0@
#s@#no_auto_depmod.*@no_auto_depmod=1@" \
# $ROOTMP/etc/sysconfig/rc
udisks --unmount $PARTITION1
udisks --unmount $PARTITION2
[ "$SWHOME" -a "${SWHOME:0:4}" = "/tmp" ] && rm -rf $SWHOME
exit 0