2013-11-10 15:35:54 +01:00
|
|
|
#!/bin/bash
|
2013-07-16 21:31:57 +02:00
|
|
|
### rootfsinstall: create partitions and fileysytems
|
|
|
|
#
|
|
|
|
# Based on rpi-install by: Davide Madrisan
|
|
|
|
# Modified by: Silvan Calarco <silvan.calarco@mambasoft.it>
|
|
|
|
#
|
2013-11-10 15:37:27 +01:00
|
|
|
|
2013-07-16 21:31:57 +02:00
|
|
|
SYSTEMFSTYPE=ext4
|
2014-12-08 01:00:08 +01:00
|
|
|
# All targets are arm currently
|
|
|
|
TARGET_ARCH=arm
|
2016-07-19 14:04:15 +02:00
|
|
|
VOLUME_LABEL="openmamba"
|
2013-07-16 21:31:57 +02:00
|
|
|
|
|
|
|
function usage() {
|
2014-12-28 13:44:40 +01:00
|
|
|
echo "Usage: $0 device rootfs-archive [-bpi|-cubox|-rpi] [-a archive] [-c command] [-fs fstype] [-k kernel] [-p password] [-y]"
|
2013-11-10 15:37:27 +01:00
|
|
|
echo
|
|
|
|
echo "Target platform (optional):"
|
2014-10-17 12:12:35 +02:00
|
|
|
echo "-bpi : make a BananaPi SD with boot partition"
|
2013-11-10 15:37:27 +01:00
|
|
|
echo "-cubox : make a Cubox SD with boot partition"
|
2014-12-28 13:44:40 +01:00
|
|
|
echo "-rpi : make a RaspberryPi SD with boot partition"
|
2013-07-16 21:31:57 +02:00
|
|
|
echo
|
|
|
|
echo "Options:"
|
2013-09-24 13:15:21 +02:00
|
|
|
echo "-a archive : additional archive to unpack in rootfs root"
|
2014-10-17 12:12:35 +02:00
|
|
|
echo "-cp command : command to run before chroot (may be specified multiple times)"
|
|
|
|
echo " Use @ROOT@ as reference to rootfs path and @BOOT@ as reference to bootfs path"
|
|
|
|
echo "-c command : command to run through chroot in rootfs (may be specified multiple times)"
|
2013-09-24 13:15:21 +02:00
|
|
|
echo "-fs fstype : filesystem type for system partition (default: ext4)"
|
|
|
|
echo "-h hostname : set given hostname"
|
2013-11-10 15:37:27 +01:00
|
|
|
echo "-k kernel : extract and use specified kernel file from ROOTFS/boot/ for boot"
|
2015-03-01 21:15:18 +01:00
|
|
|
echo "-k2 kernel : extract and use specified second kernel file from ROOTFS/boot/ for boot"
|
2014-12-08 01:00:08 +01:00
|
|
|
echo "-i packages : install packages using package manager in chroot"
|
2015-04-30 13:12:34 +02:00
|
|
|
echo "-l : force local installation only; don't perform installation from network"
|
2016-07-19 14:04:15 +02:00
|
|
|
echo "-L : rootfs volume label (default: 'openmamba')"
|
2013-09-24 13:15:21 +02:00
|
|
|
echo "-p password : set given password for root user"
|
2013-11-22 18:07:41 +01:00
|
|
|
echo "-r mode : set given default video mode where applicable (e.g. -r 1920x1080-32@60)"
|
2013-09-24 13:15:21 +02:00
|
|
|
echo "-y : assume yes to all questions (script mode)"
|
2013-07-16 21:31:57 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
while [ "$1" ]; do
|
|
|
|
case $1 in
|
|
|
|
-y) ASSUMEYES=1 ;;
|
2013-11-10 15:37:27 +01:00
|
|
|
-cubox) TARGETDEVICE=cubox ;;
|
2014-10-17 12:12:35 +02:00
|
|
|
-bpi) TARGETDEVICE=bpi ;;
|
2013-11-10 15:37:27 +01:00
|
|
|
-rpi) TARGETDEVICE=rpi ;;
|
2013-09-24 13:15:21 +02:00
|
|
|
-fs) [ "$2" ] || {
|
2013-07-16 21:31:57 +02:00
|
|
|
echo "Error: -fs option requires an argument; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
SYSTEMFSTYPE=$2
|
|
|
|
shift
|
|
|
|
;;
|
2013-09-24 13:15:21 +02:00
|
|
|
-a) [ "$2" ] || {
|
|
|
|
echo "Error: -a option requires an archive as argument; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
ADDITIONALARCHIVE=`realpath $2`
|
|
|
|
[ -r "$ADDITIONALARCHIVE" ] || {
|
|
|
|
echo "Error: file $ADDITIONALARCHIVE not found; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-c) [ "$2" ] || {
|
|
|
|
echo "Error: -c option requires a command string as argument; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
2014-03-01 17:18:01 +01:00
|
|
|
CHROOTCOMMANDS[${#CHROOTCOMMANDS[*]}]="$2"
|
2013-09-24 13:15:21 +02:00
|
|
|
shift
|
|
|
|
;;
|
2013-11-10 15:35:54 +01:00
|
|
|
-cp) [ "$2" ] || {
|
2014-10-17 12:12:35 +02:00
|
|
|
echo "Error: -cp option requires a command string as argument; aborting."
|
2013-11-10 15:35:54 +01:00
|
|
|
exit 1
|
|
|
|
}
|
2014-10-17 12:12:35 +02:00
|
|
|
PRECHROOTCOMMANDS[${#PRECHROOTCOMMANDS[*]}]="$2"
|
2013-11-10 15:35:54 +01:00
|
|
|
shift
|
|
|
|
;;
|
2013-09-24 13:15:21 +02:00
|
|
|
-k) [ "$2" ] || {
|
|
|
|
echo "Error: -k option requires a kernel file name as argument; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
USEKERNEL=$2
|
|
|
|
shift
|
|
|
|
;;
|
2015-03-01 21:15:18 +01:00
|
|
|
-k2) [ "$2" ] || {
|
|
|
|
echo "Error: -k2 option requires a kernel file name as argument; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
USEKERNEL2=$2
|
|
|
|
shift
|
|
|
|
;;
|
2013-09-24 13:15:21 +02:00
|
|
|
-h) [ "$2" ] || {
|
|
|
|
echo "Error: -h option requires a hostname as argument; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
SETHOSTNAME=$2
|
|
|
|
shift
|
|
|
|
;;
|
2014-12-08 01:00:08 +01:00
|
|
|
-i) [ "$2" ] || {
|
|
|
|
echo "Error: -i option requires a packages list as argument; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
INSTALLPACKAGES="$2"
|
|
|
|
shift
|
|
|
|
;;
|
2015-04-30 13:12:34 +02:00
|
|
|
-l) LOCALONLY=1 ;;
|
2016-07-19 14:04:15 +02:00
|
|
|
-L) [ "$2" ] || {
|
|
|
|
echo "Error: -L option requires a volume label as argument; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
VOLUME_LABEL="$2"
|
|
|
|
shift
|
|
|
|
;;
|
2013-09-24 13:15:21 +02:00
|
|
|
-p) [ "$2" ] || {
|
|
|
|
echo "Error: -p option requires a password as argument; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
ROOTPASSWORD=$2
|
|
|
|
shift
|
|
|
|
;;
|
2013-11-22 18:07:41 +01:00
|
|
|
-r) [ "$2" ] || {
|
|
|
|
echo "Error: -r option requires a video mode as argument; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
VIDEOMODE=$2
|
|
|
|
shift
|
|
|
|
;;
|
2013-07-16 21:31:57 +02:00
|
|
|
-*) echo "Error: invalid option $1; aborting."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
*) if [ ! "$DRIVE" ]; then
|
|
|
|
DRIVE=$1
|
|
|
|
elif [ ! "$ROOTFSARCHIVE" ]; then
|
2013-09-24 13:15:21 +02:00
|
|
|
ROOTFSARCHIVE=`realpath $1`
|
2013-07-16 21:31:57 +02:00
|
|
|
else
|
|
|
|
echo "Error: invalid argument $1; aborting."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
[ "$ROOTFSARCHIVE" ] || { usage; exit 1; }
|
|
|
|
|
2014-12-06 17:04:45 +01:00
|
|
|
if [ "${DRIVE:0:11}" = "/dev/mmcblk" -o "${DRIVE:0:9}" = "/dev/loop" ]; then
|
2013-07-16 21:31:57 +02:00
|
|
|
PARTITION1=${DRIVE}p1
|
|
|
|
PARTITION2=${DRIVE}p2
|
|
|
|
else
|
|
|
|
PARTITION1=${DRIVE}1
|
|
|
|
PARTITION2=${DRIVE}2
|
|
|
|
fi
|
|
|
|
|
2013-11-10 15:37:27 +01:00
|
|
|
case $TARGETDEVICE in
|
2014-12-08 01:00:08 +01:00
|
|
|
bpi) ARCH=arm
|
|
|
|
BOOTFSTYPE=fat32
|
2014-10-17 10:09:27 +02:00
|
|
|
BOOTFSSIZE=22M
|
2014-10-17 12:12:35 +02:00
|
|
|
BOOTFSSTART=1049k
|
|
|
|
[ "$USEKERNEL" ] || USEKERNEL=uImage-sunxi
|
|
|
|
KERNELDEST="@BOOT@/kernel.img"
|
2014-12-08 01:00:08 +01:00
|
|
|
INSTALLPACKAGES="kernel-sunxi kernel-sunxi-modules u-boot-sunxi-Bananapi $INSTALLPACKAGES"
|
2016-12-16 10:49:30 +01:00
|
|
|
REMOVEPACKAGES="kernel-mamba-arm"
|
2016-07-19 10:19:54 +02:00
|
|
|
FSTAB_ROOT_DEVICE="/dev/mmcblk0p2"
|
2014-10-17 12:12:35 +02:00
|
|
|
;;
|
2014-12-08 01:00:08 +01:00
|
|
|
rpi) ARCH=arm
|
|
|
|
BOOTFSTYPE=fat32
|
2014-10-17 12:12:35 +02:00
|
|
|
BOOTFSSIZE=40M
|
|
|
|
BOOTFSSTART=0
|
2015-03-01 21:15:18 +01:00
|
|
|
[ "$USEKERNEL" ] || USEKERNEL="zImage-*-rpi"
|
2016-07-19 10:19:54 +02:00
|
|
|
[ "$USEKERNEL2" ] || USEKERNEL2="zImage-*-rpi-v7"
|
2013-11-10 15:37:27 +01:00
|
|
|
KERNELDEST="@BOOT@/kernel.img"
|
2015-03-01 21:15:18 +01:00
|
|
|
KERNELDEST2="@BOOT@/kernel7.img"
|
2015-01-30 10:25:13 +01:00
|
|
|
INSTALLPACKAGES="kernel-rpi kernel-rpi-modules raspberrypi-firmware \
|
2016-07-19 10:19:54 +02:00
|
|
|
kernel-rpi-v7 kernel-rpi-v7-modules \
|
2015-01-30 10:25:13 +01:00
|
|
|
raspberrypi-utils raspi-config $INSTALLPACKAGES"
|
2016-12-16 10:49:30 +01:00
|
|
|
REMOVEPACKAGES="kernel-mamba-arm"
|
2016-07-19 10:19:54 +02:00
|
|
|
RPI_FIRMWARE_FILES="bootcode.bin fixup_x.dat start_x.elf \
|
2016-07-19 10:21:45 +02:00
|
|
|
bcm2708-rpi-b-plus.dtb bcm2708-rpi-b.dtb bcm2708-rpi-cm.dtb bcm2709-rpi-2-b.dtb bcm2710-rpi-3-b.dtb \
|
|
|
|
cmdline.txt config.txt"
|
2016-07-19 10:19:54 +02:00
|
|
|
FSTAB_ROOT_DEVICE="/dev/mmcblk0p2"
|
2013-11-10 15:37:27 +01:00
|
|
|
;;
|
2014-12-08 01:00:08 +01:00
|
|
|
cubox) ARCH=arm
|
|
|
|
BOOTFSTYPE=ext3
|
2014-10-17 12:12:35 +02:00
|
|
|
BOOTFSSIZE=20M
|
|
|
|
BOOTFSSTART=0
|
2013-12-09 13:29:53 +01:00
|
|
|
[ "$USEKERNEL" ] || USEKERNEL=uImage-3.6.9-cubox
|
2014-12-28 13:44:40 +01:00
|
|
|
KERNELDEST="@BOOT@/uImage"
|
|
|
|
INSTALLPACKAGES="kernel-cubox kernel-cubox-modules xf86-video-dove $INSTALLPACKAGES"
|
2016-12-16 10:49:30 +01:00
|
|
|
REMOVEPACKAGES="kernel-mamba-arm"
|
2013-11-10 15:37:27 +01:00
|
|
|
;;
|
|
|
|
*) 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"
|
2015-03-01 21:15:18 +01:00
|
|
|
[ "$USEKERNEL2" ] && echo "Second kernel : $USEKERNEL2 -> $KERNELDEST2"
|
2013-11-10 15:37:27 +01:00
|
|
|
echo
|
2013-07-16 21:31:57 +02:00
|
|
|
|
|
|
|
[ "$ASSUMEYES" ] || {
|
|
|
|
echo -n "All current data in ${DRIVE} will be lost, do you want to proceed [y/N]?"
|
|
|
|
read ans
|
|
|
|
[ "$ans" = "y" -o "$ans" = "Y" ] || exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
sudo parted -s ${DRIVE} mktable msdos
|
|
|
|
if [ "$?" != "0" ]; then
|
|
|
|
echo "ERROR: parted exited with error $? while creating partition table on ${DRIVE}; aborting."
|
|
|
|
fi
|
2014-12-06 17:04:45 +01:00
|
|
|
sync
|
2013-07-16 21:31:57 +02:00
|
|
|
|
2013-11-10 15:37:27 +01:00
|
|
|
if [ "$BOOTFSTYPE" ]; then
|
2013-07-16 21:31:57 +02:00
|
|
|
# FAT partition
|
2014-10-17 12:12:35 +02:00
|
|
|
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $BOOTFSTYPE $BOOTFSSTART $BOOTFSSIZE
|
2013-07-16 21:31:57 +02:00
|
|
|
if [ "$?" != "0" ]; then
|
|
|
|
echo "ERROR: parted exited with error $? while creating boot partition on ${DRIVE}; aborting."
|
|
|
|
fi
|
2014-10-17 12:12:35 +02:00
|
|
|
sudo parted -s -- ${DRIVE} toggle 1 boot
|
|
|
|
if [ "$?" != "0" ]; then
|
|
|
|
echo "ERROR: parted exited with error $? while setting boot flag on ${DRIVE} boot partition; aborting."
|
|
|
|
fi
|
2013-07-16 21:31:57 +02:00
|
|
|
# rootfs partition
|
2013-11-10 15:37:27 +01:00
|
|
|
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $SYSTEMFSTYPE $BOOTFSSIZE -1
|
2013-07-16 21:31:57 +02:00
|
|
|
if [ "$?" != "0" ]; then
|
|
|
|
echo "ERROR: parted exited with error $? while creating system partition on ${DRIVE}; aborting."
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# rootfs partition
|
2014-10-17 12:12:35 +02:00
|
|
|
sudo parted -s -a cyl -- ${DRIVE} mkpart primary $SYSTEMFSTYPE 0 -1
|
2013-07-16 21:31:57 +02:00
|
|
|
if [ "$?" != "0" ]; then
|
|
|
|
echo "ERROR: parted exited with error $? while creating system partition on ${DRIVE}; aborting."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-11-10 15:37:27 +01:00
|
|
|
if [ "$BOOTFSTYPE" ]; then
|
|
|
|
echo "Formatting $PARTITION1 ($BOOTFSTYPE) ..."
|
|
|
|
case "$BOOTFSTYPE" in
|
2014-12-08 01:00:08 +01:00
|
|
|
vfat|fat32) mkfs.vfat -s 1 -F 32 -n "boot" $PARTITION1 || {
|
2013-11-10 15:37:27 +01:00
|
|
|
echo "ERROR: unable to format $PARTITION1; aborting."
|
|
|
|
exit 1
|
|
|
|
} ;;
|
2014-12-08 01:00:08 +01:00
|
|
|
ext*) mke2fs -q -t $BOOTFSTYPE -j -L "boot" $PARTITION1 || {
|
2013-11-10 15:37:27 +01:00
|
|
|
echo "ERROR: unable to format $PARTITION1; aborting."
|
|
|
|
exit 1
|
|
|
|
} ;;
|
|
|
|
esac
|
2013-07-16 21:31:57 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Formatting $PARTITION2 ($SYSTEMFSTYPE)..."
|
2016-07-19 14:04:15 +02:00
|
|
|
mke2fs -q -F -t $SYSTEMFSTYPE -j -L "$VOLUME_LABEL" $PARTITION2 || {
|
2013-07-16 21:31:57 +02:00
|
|
|
echo "ERROR: unable to format $PARTITION2; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2013-11-23 16:58:43 +01:00
|
|
|
[ "$BOOTFSTYPE" ] && BOOTMP=`mktemp -d -t rootfsinstall.XXXXXXXX`
|
2013-07-16 21:31:57 +02:00
|
|
|
ROOTMP=`mktemp -d -t rootfsinstall.XXXXXXXX`
|
|
|
|
|
2013-11-23 16:58:43 +01:00
|
|
|
[ -d $ROOTMP ] || {
|
2013-07-16 21:31:57 +02:00
|
|
|
echo "Error: unable to create temporary mount points; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
mount $PARTITION2 $ROOTMP || {
|
|
|
|
echo "ERROR: unable to mount partition $PARTITION2; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
2015-04-30 13:12:34 +02:00
|
|
|
trap "[ "$ROOTMP" -a -e $ROOTMP ] && umount $ROOTMP/dev/pts $ROOTMP/dev $ROOTMP/proc $ROOTMP/sys $ROOTMP/run $ROOTMP && rmdir $ROOTMP;[ "$BOOTMP" -a -e $BOOTMP ] && umount $BOOTMP && rmdir $BOOTMP" 0 HUP INT QUIT ABRT KILL TERM
|
2013-07-16 21:31:57 +02:00
|
|
|
|
2013-11-10 15:37:27 +01:00
|
|
|
if [ "$BOOTFSTYPE" ]; then
|
|
|
|
mount $PARTITION1 $BOOTMP || {
|
|
|
|
echo "ERROR: unable to mount partition $PARTITION1; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2014-03-01 17:18:01 +01:00
|
|
|
(
|
|
|
|
cd $ROOTMP >/dev/null || {
|
|
|
|
echo "ERROR: unable to access system partition mount point; aborting."
|
|
|
|
umount $PARTITION2
|
|
|
|
rmdir $ROOTMP
|
|
|
|
exit 1
|
|
|
|
}
|
2013-07-16 21:31:57 +02:00
|
|
|
|
2014-03-01 17:18:01 +01:00
|
|
|
echo "Uncompressing $ROOTFSARCHIVE..."
|
|
|
|
echo -n "This can take a while, please wait..."
|
|
|
|
tar xf $ROOTFSARCHIVE || {
|
|
|
|
echo
|
|
|
|
echo "ERROR: unable to uncompress rootfs archive; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
echo "DONE"
|
2015-04-30 13:12:34 +02:00
|
|
|
for b in dev dev/pts proc sys run; do
|
|
|
|
mount -o bind /$b $ROOTMP/$b
|
|
|
|
done
|
2014-03-01 17:18:01 +01:00
|
|
|
|
|
|
|
if [ "$ADDITIONALARCHIVE" ]; then
|
|
|
|
echo "Uncompressing $ADDITIONALARCHIVE..."
|
|
|
|
echo -n "This can take a while, please wait..."
|
|
|
|
tar xf $ADDITIONALARCHIVE || {
|
|
|
|
echo
|
|
|
|
echo "ERROR: unable to uncompress additional archive; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
echo "DONE"
|
2013-09-24 13:15:21 +02:00
|
|
|
fi
|
2014-03-01 17:18:01 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
[ $? -eq 0 ] || exit $?
|
2013-07-16 21:31:57 +02:00
|
|
|
|
2014-12-08 01:00:08 +01:00
|
|
|
[ -e /usr/bin/qemu-${TARGET_ARCH}.static ] && cp /usr/bin/qemu-${TARGET_ARCH}.static $ROOTMP/usr/bin/qemu-${TARGET_ARCH}
|
|
|
|
|
|
|
|
if [ "$ROOTPASSWORD" ]; then
|
|
|
|
echo "$ROOTPASSWORD" | chroot $ROOTMP passwd root --stdin || {
|
|
|
|
echo "ERROR: unable to set password for root; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$SETHOSTNAME" ]; then
|
|
|
|
echo "$SETHOSTNAME" > $ROOTMP/etc/hostname
|
|
|
|
sed -i "s|HOSTNAME=.*|HOSTNAME=$SETHOSTNAME|" $ROOTMP/etc/sysconfig/network
|
|
|
|
sed -i "s|\(127\.0\.0\.1\W*\)\(.*\)|\1 $SETHOSTNAME.localdomain $SETHOSTNAME localhost.localdomain localhost|" $ROOTMP/etc/hosts
|
|
|
|
fi
|
|
|
|
|
2015-04-30 13:12:34 +02:00
|
|
|
if [ "$INSTALLPACKAGES" -a "$LOCALONLY" != "1" ]; then
|
2014-12-08 01:00:08 +01:00
|
|
|
mv $ROOTMP/etc/resolv.conf $ROOTMP/etc/resolv.conf.rootfsinstall
|
|
|
|
cp /etc/resolv.conf $ROOTMP/etc/resolv.conf
|
2015-03-01 23:40:33 +01:00
|
|
|
chroot $ROOTMP bash -c /etc/profile.d/gpg-key-openmamba.sh
|
|
|
|
#chroot $ROOTMP smart channel --enable devel-kernel
|
2014-12-08 01:00:08 +01:00
|
|
|
chroot $ROOTMP smart update || {
|
|
|
|
echo "ERROR: error running chroot command 'smart update'; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
chroot $ROOTMP smart install -y $INSTALLPACKAGES || {
|
|
|
|
echo "ERROR: error running chroot command 'smart install $INSTALLPACKAGES'; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
2015-03-01 23:40:33 +01:00
|
|
|
#chroot $ROOTMP smart channel --disable devel-kernel
|
2014-12-08 01:00:08 +01:00
|
|
|
mv $ROOTMP/etc/resolv.conf.rootfsinstall $ROOTMP/etc/resolv.conf
|
|
|
|
fi
|
|
|
|
|
2016-12-16 10:49:30 +01:00
|
|
|
if [ "$REMOVEPACKAGES" ]; then
|
|
|
|
chroot $ROOTMP smart remove -y $REMOVEPACKAGES || {
|
|
|
|
echo "ERROR: error running chroot command 'smart remove $REMOVEPACKAGES'; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
2015-03-01 21:15:18 +01:00
|
|
|
KERNELDEST=`echo $KERNELDEST | sed "s|@BOOT@|$BOOTMP|g"`
|
|
|
|
KERNELDEST2=`echo $KERNELDEST2 | sed "s|@BOOT@|$BOOTMP|g"`
|
|
|
|
|
2014-12-08 01:00:08 +01:00
|
|
|
#
|
|
|
|
# Prepare boot partition
|
|
|
|
#
|
2014-10-17 12:12:35 +02:00
|
|
|
if [ "$TARGETDEVICE" = "bpi" ]; then
|
|
|
|
# TODO
|
2014-12-06 17:04:45 +01:00
|
|
|
cp $ROOTMP/boot/Bananapi-script.bin $BOOTMP/
|
|
|
|
IMAGE=`ls $ROOTMP/boot/uImage-*-sunxi | head -n 1`
|
|
|
|
cp $IMAGE $BOOTMP/uImage-sunxi
|
|
|
|
cat > $BOOTMP/uEnv.txt << _EOF
|
|
|
|
bootargs=console=ttyS0,115200 console=tty0 sunxi_g2d_mem_reserve=0 sunxi_ve_mem_reserve=0 disp.screen0_output_mode=EDID:1280x720p50 hdmi.audio=EDID:0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait
|
|
|
|
aload_script=fatload mmc 0 0x43000000 Bananapi-script.bin;
|
|
|
|
aload_kernel=fatload mmc 0 0x48000000 uImage-sunxi; bootm 0x48000000;
|
|
|
|
uenvcmd=run aload_script aload_kernel
|
|
|
|
_EOF
|
|
|
|
dd if=$ROOTMP/boot/Bananapi/u-boot-sunxi-with-spl.bin of=${DRIVE} bs=1024 seek=8
|
2014-10-17 12:12:35 +02:00
|
|
|
:
|
|
|
|
elif [ "$TARGETDEVICE" = "rpi" ]; then
|
2014-03-01 17:18:01 +01:00
|
|
|
# fetch and install firmware files if missing
|
2015-03-01 21:15:18 +01:00
|
|
|
for f in $RPI_FIRMWARE_FILES; do
|
|
|
|
if [ -e $ROOTMP/boot/$f ]; then
|
2014-03-01 17:18:01 +01:00
|
|
|
cp $ROOTMP/boot/$f $BOOTMP/$f
|
2015-04-30 13:12:34 +02:00
|
|
|
elif [ "$f" != "cmdline.txt" -a "$f" != "config.txt" ]; then
|
2015-03-01 21:15:18 +01:00
|
|
|
echo "ERROR: firmware file $f for rpi is missing in /boot directory; aborting."
|
|
|
|
exit 1
|
2013-09-24 13:15:21 +02:00
|
|
|
fi
|
2015-03-01 21:15:18 +01:00
|
|
|
done
|
|
|
|
if [ -e $ROOTMP/boot/overlays ]; then
|
|
|
|
cp -a $ROOTMP/boot/overlays $BOOTMP/
|
2014-03-01 17:18:01 +01:00
|
|
|
fi
|
2015-03-01 21:15:18 +01:00
|
|
|
# IMAGE=`ls $ROOTMP/boot/$USEKERNEL | head -n 1`
|
|
|
|
cp $ROOTMP/boot/$USEKERNEL $KERNELDEST
|
|
|
|
cp $ROOTMP/boot/$USEKERNEL2 $KERNELDEST2
|
2013-07-16 21:31:57 +02:00
|
|
|
|
|
|
|
# cmdline.txt : parameters passed to the kernel on boot
|
2015-04-30 13:12:34 +02:00
|
|
|
[ ! -e $ROOTMP/boot/cmdline.txt ] && \
|
2013-07-16 21:31:57 +02:00
|
|
|
echo "\
|
|
|
|
dwc_otg.lpm_enable=0 \
|
|
|
|
root=/dev/mmcblk0p2 \
|
|
|
|
rootfstype=$SYSTEMFSTYPE \
|
|
|
|
quiet \
|
|
|
|
rootwait \
|
|
|
|
splash" > $BOOTMP/cmdline.txt
|
|
|
|
|
|
|
|
# Create the kernel configuration file
|
2015-04-30 13:12:34 +02:00
|
|
|
[ ! -e $ROOTMP/boot/config.txt ] && \
|
2013-07-16 21:31:57 +02:00
|
|
|
echo "\
|
2015-03-01 21:15:18 +01:00
|
|
|
start_file=start_x.elf
|
|
|
|
fixup_file=fixup_x.dat
|
|
|
|
framebuffer_depth=32
|
|
|
|
framebuffer_ignore_alpha=1
|
|
|
|
[rp1]
|
2013-07-16 21:31:57 +02:00
|
|
|
arm_freq=800
|
|
|
|
force_turbo=1
|
|
|
|
gpu_mem=100
|
|
|
|
disable_overscan=1
|
2015-03-01 21:15:18 +01:00
|
|
|
[rp2]
|
|
|
|
gpu_mem=128
|
|
|
|
" > $BOOTMP/config.txt
|
2013-07-16 21:31:57 +02:00
|
|
|
|
|
|
|
## Enable HDMI mode rather than DVI, if required
|
|
|
|
#echo "\
|
|
|
|
#hdmi_drive=2" >> $BOOTMP/config.txt
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
[ "$SWHOME" -a "${SWHOME:0:4}" = "/tmp" ] && rm -rf $SWHOME
|
|
|
|
|
2013-11-10 15:37:27 +01:00
|
|
|
elif [ "$TARGETDEVICE" = "cubox" ]; then
|
2014-12-28 13:44:40 +01:00
|
|
|
if [ -e $ROOTMP/boot/uImage-*-cubox ]; then
|
|
|
|
IMAGE=`ls $ROOTMP/boot/uImage-*-cubox | head -n 1`
|
|
|
|
cp $IMAGE* $BOOTMP/
|
|
|
|
ln -s ${IMAGE/*\/}-boot.scr $BOOTMP/boot.scr
|
|
|
|
else
|
|
|
|
[ "$VIDEO_MODE" ] || VIDEO_MODE="1920x1080-32@60"
|
|
|
|
mkdir -p $BOOTMP
|
|
|
|
echo "Creating u-boot boot.scr..."
|
|
|
|
cat > $BOOTMP/boot.txt << _EOF
|
2014-03-01 17:18:01 +01:00
|
|
|
setenv bootargs 'console=ttyS0,115200n8 vmalloc=384M root=/dev/mmcblk0p2 video=dovefb:lcd0:$VIDEO_MODE-edid clcd.lcd0_enable=1 clcd.lcd1_enable=0 rootwait'
|
2013-11-10 15:37:27 +01:00
|
|
|
echo ======== Loading kernel ========
|
2014-12-28 13:44:40 +01:00
|
|
|
ext2load mmc 0:1 0x00200000 /uImage
|
2013-11-10 15:37:27 +01:00
|
|
|
echo ======== Booting kernel ========
|
|
|
|
bootm
|
|
|
|
_EOF
|
2014-12-28 13:44:40 +01:00
|
|
|
mkimage -A arm -O linux -T script -C none -n "u-boot commands" -d $BOOTMP/boot.txt $BOOTMP/boot.scr || {
|
|
|
|
echo "ERROR: mkimage: error creating boot.scr; aborting."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
fi
|
2013-11-10 15:37:27 +01:00
|
|
|
fi
|
2013-07-16 21:31:57 +02:00
|
|
|
|
2016-07-19 10:19:54 +02:00
|
|
|
if [ "$FSTAB_ROOT_DEVICE" ]; then
|
|
|
|
cat >> $ROOTMP/etc/fstab << _EOF
|
|
|
|
$FSTAB_ROOT_DEVICE / auto defaults 0 0
|
|
|
|
_EOF
|
|
|
|
fi
|
|
|
|
|
2013-09-24 13:15:21 +02:00
|
|
|
if [ "$USEKERNEL" ]; then
|
2013-11-10 15:35:54 +01:00
|
|
|
if [ -r $ROOTMP/boot/$USEKERNEL ]; then
|
|
|
|
cp $ROOTMP/boot/$USEKERNEL $KERNELDEST || {
|
2013-09-24 13:15:21 +02:00
|
|
|
echo "ERROR: unable to find or copy kernel $USEKERNEL; aborting."
|
|
|
|
exit 1
|
2013-11-10 15:35:54 +01:00
|
|
|
}
|
2013-11-10 15:37:27 +01:00
|
|
|
echo "Kernel image available as $KERNELDEST"
|
2013-11-10 15:35:54 +01:00
|
|
|
else
|
2013-11-10 15:37:27 +01:00
|
|
|
echo "WARNING: can't find kernel file $ROOTMP/boot/$USERKERNEL"
|
2013-09-24 13:15:21 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2014-12-08 01:00:08 +01:00
|
|
|
#
|
|
|
|
# Final custom commands
|
|
|
|
#
|
2014-10-17 12:12:35 +02:00
|
|
|
for c in `seq 1 ${#PRECHROOTCOMMANDS[*]}`; do
|
|
|
|
PRECHROOTCOMMAND=`echo ${PRECHROOTCOMMANDS[c-1]} | sed "s|@ROOT@|$ROOTMP|g;s|@BOOT@|$BOOTMP|g"`
|
2013-11-10 15:35:54 +01:00
|
|
|
$PRECHROOTCOMMAND || {
|
2014-10-17 12:12:35 +02:00
|
|
|
echo "ERROR: error running pre-chroot command '${PRECHROOTCOMMANDS[c-1]}'; aborting."
|
2013-11-10 15:35:54 +01:00
|
|
|
exit 1
|
|
|
|
}
|
2014-10-17 12:12:35 +02:00
|
|
|
done
|
2013-11-10 15:35:54 +01:00
|
|
|
|
2014-03-01 17:18:01 +01:00
|
|
|
for c in `seq 1 ${#CHROOTCOMMANDS[*]}`; do
|
|
|
|
chroot $ROOTMP ${CHROOTCOMMANDS[c-1]} || {
|
|
|
|
echo "ERROR: error running chroot command '${CHROOTCOMMANDS[c-1]}'; aborting."
|
2013-09-24 13:15:21 +02:00
|
|
|
exit 1
|
|
|
|
}
|
2014-03-01 17:18:01 +01:00
|
|
|
done
|
2013-09-24 13:15:21 +02:00
|
|
|
|
2013-07-16 21:31:57 +02:00
|
|
|
sync
|
|
|
|
|
|
|
|
echo "Done."
|
|
|
|
exit 0
|