2015-11-20 17:09:21 +01:00
|
|
|
#!/bin/sh
|
2015-11-21 12:25:32 +01:00
|
|
|
#
|
|
|
|
# .---. . .
|
|
|
|
# | | |
|
|
|
|
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
|
|
|
|
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
|
|
|
|
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
|
|
|
|
#
|
|
|
|
# Freedom in the Cloud
|
|
|
|
#
|
|
|
|
# Hardware setup based on bin/freedombox-hardware-setup from freedom-maker
|
|
|
|
#
|
|
|
|
# License
|
|
|
|
# =======
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2016-02-13 23:09:27 +01:00
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
2015-11-21 12:25:32 +01:00
|
|
|
# the Free Software Foundation, either version 3 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
|
2016-02-13 23:09:27 +01:00
|
|
|
# GNU Affero General Public License for more details.
|
2015-11-21 12:25:32 +01:00
|
|
|
#
|
2016-02-13 23:09:27 +01:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2015-11-21 12:25:32 +01:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2015-11-20 17:09:21 +01:00
|
|
|
|
2015-11-27 12:42:16 +01:00
|
|
|
PROJECT_NAME='freedombone'
|
|
|
|
|
2015-11-27 17:52:23 +01:00
|
|
|
export TEXTDOMAIN=${PROJECT_NAME}-image-hardware-setup
|
2015-11-27 12:42:16 +01:00
|
|
|
export TEXTDOMAINDIR="/usr/share/locale"
|
|
|
|
|
2015-11-20 17:09:21 +01:00
|
|
|
enable_serial_console() {
|
2016-06-28 18:32:54 +02:00
|
|
|
# By default, spawn a console on the serial port
|
|
|
|
device="$1"
|
|
|
|
echo $"Adding a getty on the serial port"
|
|
|
|
echo "T0:12345:respawn:/sbin/getty -L $device 115200 vt100" >> /etc/inittab
|
2015-11-20 17:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
beaglebone_setup_boot() {
|
2016-06-28 18:32:54 +02:00
|
|
|
# Setup uEnv.txt
|
|
|
|
if grep -q btrfs /etc/fstab ; then
|
|
|
|
fstype=btrfs
|
|
|
|
else
|
|
|
|
fstype=ext4
|
|
|
|
fi
|
|
|
|
kernelVersion=$(ls /usr/lib/*/am335x-boneblack.dtb | head -1 | cut -d/ -f4)
|
|
|
|
version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
|
|
|
|
initRd=initrd.img-$version
|
|
|
|
vmlinuz=vmlinuz-$version
|
|
|
|
|
|
|
|
# uEnv.txt for Beaglebone
|
|
|
|
# based on https://github.com/beagleboard/image-builder/blob/master/target/boot/beagleboard.org.txt
|
|
|
|
cat >> /boot/uEnv.txt <<EOF
|
2015-11-20 17:09:21 +01:00
|
|
|
mmcroot=/dev/mmcblk0p2 ro
|
|
|
|
mmcrootfstype=$fstype rootwait fixrtc
|
|
|
|
mmcrootflags=subvol=@
|
|
|
|
|
|
|
|
console=ttyO0,115200n8
|
|
|
|
|
|
|
|
kernel_file=$vmlinuz
|
|
|
|
initrd_file=$initRd
|
|
|
|
|
|
|
|
loadaddr=0x80200000
|
|
|
|
initrd_addr=0x81000000
|
|
|
|
fdtaddr=0x80F80000
|
|
|
|
|
|
|
|
initrd_high=0xffffffff
|
|
|
|
fdt_high=0xffffffff
|
|
|
|
|
|
|
|
loadkernel=load mmc \${mmcdev}:\${mmcpart} \${loadaddr} \${kernel_file}
|
|
|
|
loadinitrd=load mmc \${mmcdev}:\${mmcpart} \${initrd_addr} \${initrd_file}; setenv initrd_size \${filesize}
|
|
|
|
loadfdt=load mmc \${mmcdev}:\${mmcpart} \${fdtaddr} /dtbs/\${fdtfile}
|
|
|
|
|
|
|
|
loadfiles=run loadkernel; run loadinitrd; run loadfdt
|
|
|
|
mmcargs=setenv bootargs console=tty0 console=\${console} root=\${mmcroot} rootfstype=\${mmcrootfstype} rootflags=\${mmcrootflags}
|
|
|
|
|
|
|
|
uenvcmd=run loadfiles; run mmcargs; bootz \${loadaddr} \${initrd_addr}:\${initrd_size} \${fdtaddr}
|
|
|
|
EOF
|
|
|
|
|
2016-06-28 18:32:54 +02:00
|
|
|
mkdir -p /boot/dtbs
|
|
|
|
cp /usr/lib/linux-image-*-armmp/* /boot/dtbs
|
2015-11-20 17:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
beaglebone_flash() {
|
2016-06-28 18:32:54 +02:00
|
|
|
# allow flash-kernel to work without valid /proc contents
|
|
|
|
# ** this doesn't *really* work, since there are too many checks
|
|
|
|
# that fail in an emulated environment! We'll have to do it by
|
|
|
|
# hand below anyway...
|
|
|
|
export FK_MACHINE="TI AM335x BeagleBone"
|
|
|
|
apt-get install -y flash-kernel
|
2015-11-20 17:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
beaglebone_repack_kernel() {
|
2016-06-28 18:32:54 +02:00
|
|
|
# process installed kernel to create uImage, uInitrd, dtb
|
|
|
|
# using flash-kernel would be a good approach, except it fails in the
|
|
|
|
# cross build environment due to too many environment checks...
|
|
|
|
#FK_MACHINE="TI AM335x BeagleBone" flash-kernel
|
|
|
|
# so, let's do it manually...
|
|
|
|
|
|
|
|
# flash-kernel's hook-functions provided to mkinitramfs have the
|
|
|
|
# unfortunate side-effect of creating /conf/param.conf in the initrd
|
|
|
|
# when run from our emulated chroot environment, which means our root=
|
|
|
|
# on the kernel command line is completely ignored! repack the initrd
|
|
|
|
# to remove this evil...
|
|
|
|
|
|
|
|
echo "info: repacking beaglebone kernel and initrd"
|
|
|
|
|
|
|
|
kernelVersion=$(ls /usr/lib/*/am335x-boneblack.dtb | head -1 | cut -d/ -f4)
|
|
|
|
version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
|
|
|
|
initRd=initrd.img-$version
|
|
|
|
vmlinuz=vmlinuz-$version
|
|
|
|
|
|
|
|
mkdir /tmp/initrd-repack
|
|
|
|
|
|
|
|
(cd /tmp/initrd-repack ; \
|
|
|
|
zcat /boot/$initRd | cpio -i ; \
|
|
|
|
rm -f conf/param.conf ; \
|
|
|
|
find . | cpio --quiet -o -H newc | \
|
|
|
|
gzip -9 > /boot/$initRd )
|
|
|
|
|
|
|
|
rm -rf /tmp/initrd-repack
|
|
|
|
|
|
|
|
(cd /boot ; \
|
|
|
|
cp /usr/lib/$kernelVersion/am335x-boneblack.dtb dtb ; \
|
|
|
|
cat $vmlinuz dtb >> temp-kernel ; \
|
|
|
|
mkimage -A arm -O linux -T kernel -n "Debian kernel ${version}" \
|
|
|
|
-C none -a 0x80200000 -e 0x80200000 -d temp-kernel uImage ; \
|
|
|
|
rm -f temp-kernel ; \
|
|
|
|
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x81000000 -e 0x81000000 \
|
|
|
|
-n "Debian ramdisk ${version}" \
|
|
|
|
-d $initRd uInitrd )
|
2016-06-28 18:18:15 +02:00
|
|
|
}
|
|
|
|
|
2015-12-01 17:59:50 +01:00
|
|
|
a20_setup_boot() {
|
2016-06-28 18:32:54 +02:00
|
|
|
dtb="$1"
|
|
|
|
|
|
|
|
# Setup boot.cmd
|
|
|
|
if grep -q btrfs /etc/fstab ; then
|
|
|
|
fstype=btrfs
|
|
|
|
else
|
|
|
|
fstype=ext4
|
|
|
|
fi
|
|
|
|
kernelVersion=$(ls /usr/lib/*/$dtb | head -1 | cut -d/ -f4)
|
|
|
|
version=$(echo $kernelVersion | sed 's/linux-image-\(.*\)/\1/')
|
|
|
|
initRd=initrd.img-$version
|
|
|
|
vmlinuz=vmlinuz-$version
|
|
|
|
|
|
|
|
# Create boot.cmd
|
|
|
|
cat >> /boot/boot.cmd <<EOF
|
2015-11-20 17:09:21 +01:00
|
|
|
setenv mmcdev 0
|
|
|
|
setenv mmcpart 1
|
|
|
|
|
|
|
|
setenv mmcroot /dev/mmcblk0p2 ro
|
|
|
|
setenv mmcrootfstype $fstype rootwait fixrtc
|
|
|
|
setenv mmcrootflags subvol=@
|
|
|
|
|
|
|
|
setenv console ttyS0,115200n8
|
|
|
|
|
|
|
|
setenv kernel_file $vmlinuz
|
|
|
|
setenv initrd_file $initRd
|
2015-12-01 17:59:50 +01:00
|
|
|
setenv fdtfile $dtb
|
2015-11-20 17:09:21 +01:00
|
|
|
|
2015-12-01 17:59:50 +01:00
|
|
|
setenv loadaddr 0x46000000
|
|
|
|
setenv initrd_addr 0x48000000
|
|
|
|
setenv fdtaddr 0x47000000
|
2015-11-20 17:09:21 +01:00
|
|
|
|
|
|
|
setenv initrd_high 0xffffffff
|
|
|
|
setenv fdt_high 0xffffffff
|
|
|
|
|
|
|
|
setenv loadkernel load mmc \${mmcdev}:\${mmcpart} \${loadaddr} \${kernel_file}
|
|
|
|
setenv loadinitrd load mmc \${mmcdev}:\${mmcpart} \${initrd_addr} \${initrd_file}\\; setenv initrd_size \\\${filesize}
|
|
|
|
setenv loadfdt load mmc \${mmcdev}:\${mmcpart} \${fdtaddr} /dtbs/\${fdtfile}
|
|
|
|
|
|
|
|
setenv loadfiles run loadkernel\\; run loadinitrd\\; run loadfdt
|
|
|
|
setenv mmcargs setenv bootargs console=\${console} root=\${mmcroot} rootfstype=\${mmcrootfstype} rootflags=\${mmcrootflags}
|
|
|
|
|
|
|
|
run loadfiles; run mmcargs; bootz \${loadaddr} \${initrd_addr}:\${initrd_size} \${fdtaddr}
|
|
|
|
EOF
|
|
|
|
|
2016-06-28 18:32:54 +02:00
|
|
|
# boot.scr for Allwinner A20 based device
|
|
|
|
mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
|
2015-11-20 17:09:21 +01:00
|
|
|
|
2016-06-28 18:32:54 +02:00
|
|
|
# Copy all DTBs
|
|
|
|
mkdir -p /boot/dtbs
|
|
|
|
cp /usr/lib/$kernelVersion/* /boot/dtbs
|
2015-11-20 17:09:21 +01:00
|
|
|
|
2016-06-28 18:32:54 +02:00
|
|
|
# extra boot modules
|
|
|
|
echo "rtc_sunxi" >> /etc/initramfs-tools/modules
|
2015-11-20 17:09:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
case "$MACHINE" in
|
2016-06-28 18:32:54 +02:00
|
|
|
beaglebone)
|
|
|
|
beaglebone_setup_boot
|
|
|
|
beaglebone_flash
|
|
|
|
beaglebone_repack_kernel
|
|
|
|
enable_serial_console ttyO0
|
|
|
|
;;
|
|
|
|
cubietruck)
|
|
|
|
a20_setup_boot sun7i-a20-cubietruck.dtb
|
|
|
|
enable_serial_console ttyS0
|
|
|
|
;;
|
|
|
|
a20-olinuxino-lime)
|
|
|
|
a20_setup_boot sun7i-a20-olinuxino-lime.dtb
|
|
|
|
enable_serial_console ttyS0
|
|
|
|
;;
|
|
|
|
a20-olinuxino-lime2)
|
|
|
|
a20_setup_boot sun7i-a20-olinuxino-lime2.dtb
|
|
|
|
enable_serial_console ttyS0
|
|
|
|
;;
|
|
|
|
a20-olinuxino-micro)
|
|
|
|
a20_setup_boot sun7i-a20-olinuxino-micro.dtb
|
|
|
|
enable_serial_console ttyS0
|
|
|
|
;;
|
|
|
|
cubieboard2)
|
|
|
|
a20_setup_boot sun7i-a20-cubieboard2.dtb
|
|
|
|
enable_serial_console ttyS0
|
|
|
|
;;
|
2015-11-20 17:09:21 +01:00
|
|
|
esac
|