freedomboneeee/src/freedombone-image-hardware-...

274 lines
8.7 KiB
Plaintext
Raw Normal View History

#!/bin/sh
2018-04-08 14:30:21 +02:00
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
2015-11-21 12:25:32 +01:00
#
2018-04-08 14:30:21 +02:00
# Freedom in the Cloud
2015-11-21 12:25:32 +01:00
#
# 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-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"
2017-05-30 20:17:39 +02:00
enable_serial_console() {
2017-05-30 11:20:12 +02:00
# By default, spawn a console on the serial port
device="$1"
2018-03-02 20:17:02 +01:00
echo "Adding a getty on the serial port"
2017-05-30 11:20:12 +02:00
echo "T0:12345:respawn:/sbin/getty -L $device 115200 vt100" >> /etc/inittab
}
2017-05-31 11:05:49 +02:00
beaglebone_setup_boot() {
2017-01-06 00:21:58 +01:00
2017-05-31 11:05:49 +02:00
# Setup uEnv.txt
if grep -q btrfs /etc/fstab ; then
fstype=btrfs
else
fstype=ext4
2017-01-06 12:33:19 +01:00
fi
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2012
2018-03-03 16:45:45 +01:00
kernelVersion=$(ls /usr/lib/*/am335x-boneblack.dtb | head -1 | cut -d/ -f4)
2018-03-02 20:17:02 +01:00
version=$(echo "$kernelVersion" | sed 's/linux-image-\(.*\)/\1/')
2017-05-31 11:05:49 +02:00
initRd=initrd.img-$version
vmlinuz=vmlinuz-$version
bbb_loadaddr='0x82000000'
bbb_initrd_addr='0x88080000'
bbb_fdtaddr='0x88000000'
2016-06-28 18:32:54 +02:00
2017-05-31 11:05:49 +02:00
# uEnv.txt for Beaglebone
# based on https://github.com/beagleboard/image-builder/blob/master/target/boot/beagleboard.org.txt
cat >> /boot/uEnv.txt <<EOF
mmcroot=/dev/mmcblk0p2 ro
mmcrootfstype=$fstype rootwait fixrtc
mmcrootflags=subvol=@
console=ttyO0,115200n8
kernel_file=$vmlinuz
initrd_file=$initRd
loadaddr=$bbb_loadaddr
initrd_addr=$bbb_initrd_addr
fdtaddr=$bbb_fdtaddr
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
2017-06-20 11:49:08 +02:00
mmcargs=setenv bootargs init=/lib/systemd/systemd console=tty0 console=\${console} root=\${mmcroot} rootfstype=\${mmcrootfstype} rootflags=\${mmcrootflags} ifnames=0 slub_debug=FZP slab_nomerge page_poison=1
2017-05-31 11:05:49 +02:00
uenvcmd=run loadfiles; run mmcargs; bootz \${loadaddr} \${initrd_addr}:\${initrd_size} \${fdtaddr}
EOF
mkdir -p /boot/dtbs
cp /usr/lib/linux-image-*-armmp/* /boot/dtbs
}
beaglebone_flash() {
# 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...
2018-02-18 16:39:16 +01:00
export FK_MACHINE="TI AM335x BeagleBone Black"
apt-get install -y flash-kernel
}
2017-05-31 11:05:49 +02:00
beaglebone_repack_kernel() {
# 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"
bbb_dtb='am335x-boneblack'
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2012
2018-03-03 16:45:45 +01:00
kernelVersion=$(ls /usr/lib/*/${bbb_dtb}.dtb | head -1 | cut -d/ -f4)
2018-03-02 20:17:02 +01:00
version=$(echo "$kernelVersion" | sed 's/linux-image-\(.*\)/\1/')
2017-05-31 11:05:49 +02:00
initRd=initrd.img-$version
vmlinuz=vmlinuz-$version
2017-05-31 18:30:11 +02:00
# optionally use a separately compiled kernel
bbb_dtb_file=/usr/lib/$kernelVersion/${bbb_dtb}.dtb
#if [ -f /boot/bbb.tar.gz ]; then
# cd /boot
# tar -xzvf /boot/bbb.tar.gz
# if [ -f /boot/bbb/dtbs/${bbb_dtb}.dtb ]; then
# if [ -f /boot/bbb/zImage ]; then
# bbb_dtb_file=/boot/bbb/dtbs/${bbb_dtb}.dtb
# vmlinuz=/boot/bbb/zImage
# fi
# fi
#fi
2017-05-31 18:30:11 +02:00
2017-05-31 11:05:49 +02:00
mkdir /tmp/initrd-repack
2018-03-02 20:17:02 +01:00
(cd /tmp/initrd-repack || exit 2468246 ; \
zcat "/boot/$initRd" | cpio -i ; \
2017-05-31 11:05:49 +02:00
rm -f conf/param.conf ; \
find . | cpio --quiet -o -H newc | \
2018-03-02 20:17:02 +01:00
gzip -9 > "/boot/$initRd" )
2017-05-31 11:05:49 +02:00
rm -rf /tmp/initrd-repack
2018-03-02 20:17:02 +01:00
(cd /boot || exit 246824684 ; \
cp "${bbb_dtb_file}" dtb ; \
cat "$vmlinuz" dtb >> temp-kernel ; \
2017-05-31 11:05:49 +02:00
mkimage -A arm -O linux -T kernel -n "Debian kernel ${version}" \
-C none -a 0x82000000 -e 0x82000000 -d temp-kernel uImage ; \
rm -f temp-kernel ; \
mkimage -A arm -O linux -T ramdisk -C gzip -a 0x88080000 -e 0x88080000 \
-n "Debian ramdisk ${version}" \
2018-03-02 20:17:02 +01:00
-d "$initRd" uInitrd )
}
2017-05-31 11:05:49 +02:00
a20_setup_boot() {
2017-05-30 11:20:12 +02:00
dtb="$1"
2018-04-22 13:44:17 +02:00
a20_root_device='mmcblk0p2'
if [ "$2" ]; then
a20_root_device="$2"
fi
2017-05-30 11:20:12 +02:00
# Setup boot.cmd
2017-05-31 11:05:49 +02:00
if grep -q btrfs /etc/fstab ; then
2017-05-30 11:20:12 +02:00
fstype=btrfs
2017-05-31 11:05:49 +02:00
else
fstype=ext4
2017-05-30 11:20:12 +02:00
fi
2018-03-03 16:45:45 +01:00
# shellcheck disable=SC2012,SC2086
kernelVersion=$(ls /usr/lib/*/$dtb | head -1 | cut -d/ -f4)
2018-03-02 20:17:02 +01:00
version=$(echo "$kernelVersion" | sed 's/linux-image-\(.*\)/\1/')
2017-05-30 11:20:12 +02:00
initRd=initrd.img-$version
vmlinuz=vmlinuz-$version
# Create boot.cmd
cat >> /boot/boot.cmd <<EOF
setenv mmcdev 0
setenv mmcpart 1
2018-04-22 13:44:17 +02:00
setenv mmcroot /dev/${a20_root_device} ro
2017-05-30 11:20:12 +02:00
setenv mmcrootfstype $fstype rootwait fixrtc
setenv mmcrootflags subvol=@
setenv console ttyS0,115200n8
setenv kernel_file $vmlinuz
setenv initrd_file $initRd
setenv fdtfile $dtb
setenv loadaddr 0x46000000
setenv initrd_addr 0x48000000
setenv fdtaddr 0x47000000
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
2017-06-20 11:49:08 +02:00
setenv mmcargs setenv bootargs init=/lib/systemd/systemd console=\${console} root=\${mmcroot} rootfstype=\${mmcrootfstype} rootflags=\${mmcrootflags} ifnames=0 slub_debug=FZP slab_nomerge page_poison=1
2017-05-30 11:20:12 +02:00
run loadfiles; run mmcargs; bootz \${loadaddr} \${initrd_addr}:\${initrd_size} \${fdtaddr}
EOF
# boot.scr for Allwinner A20 based device
mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
# Copy all DTBs
mkdir -p /boot/dtbs
2018-03-03 16:45:45 +01:00
# shellcheck disable=SC2086
cp /usr/lib/$kernelVersion/* /boot/dtbs
2017-05-30 11:20:12 +02:00
# extra boot modules
echo "rtc_sunxi" >> /etc/initramfs-tools/modules
}
2017-08-27 20:46:27 +02:00
setup_flash_kernel() {
if [ ! -d /etc/flash-kernel ] ; then
mkdir /etc/flash-kernel
fi
2018-03-03 14:15:52 +01:00
printf "%s" "$1" > /etc/flash-kernel/machine
2017-08-27 20:46:27 +02:00
command_line=""
if [ -n "$2" ] ; then
command_line="console=$2"
fi
if [ -n "$command_line" ] ; then
2018-03-03 14:16:25 +01:00
echo "flash-kernel flash-kernel/linux_cmdline string \"$command_line\"" | debconf-set-selections
2017-08-27 20:46:27 +02:00
fi
apt-get install -y flash-kernel
}
case "$MACHINE" in
2016-06-28 18:32:54 +02:00
beaglebone)
2017-05-31 11:05:49 +02:00
beaglebone_setup_boot
beaglebone_flash
beaglebone_repack_kernel
2017-05-30 11:20:12 +02:00
enable_serial_console ttyO0
;;
2016-06-28 18:32:54 +02:00
cubietruck)
2018-04-22 13:44:17 +02:00
a20_setup_boot sun7i-a20-cubietruck.dtb "$EXTERNAL_DRIVE"
2017-05-31 11:05:49 +02:00
enable_serial_console ttyS0
2016-06-28 18:32:54 +02:00
;;
a20-olinuxino-lime)
2018-04-22 13:44:17 +02:00
a20_setup_boot sun7i-a20-olinuxino-lime.dtb "$EXTERNAL_DRIVE"
2017-05-31 11:05:49 +02:00
enable_serial_console ttyS0
2016-06-28 18:32:54 +02:00
;;
a20-olinuxino-lime2)
2018-04-22 13:44:17 +02:00
a20_setup_boot sun7i-a20-olinuxino-lime2.dtb "$EXTERNAL_DRIVE"
2017-05-31 11:05:49 +02:00
enable_serial_console ttyS0
2016-06-28 18:32:54 +02:00
;;
a20-olinuxino-micro)
2018-04-22 13:44:17 +02:00
a20_setup_boot sun7i-a20-olinuxino-micro.dtb "$EXTERNAL_DRIVE"
2017-05-31 11:05:49 +02:00
enable_serial_console ttyS0
2016-06-28 18:32:54 +02:00
;;
2018-05-17 19:49:56 +02:00
banana-pro)
a20_setup_boot sun7i-a20-bananapro.dtb "$EXTERNAL_DRIVE"
enable_serial_console ttyS0
;;
2016-06-28 18:32:54 +02:00
cubieboard2)
2018-04-22 13:44:17 +02:00
a20_setup_boot sun7i-a20-cubieboard2.dtb "$EXTERNAL_DRIVE"
2017-05-31 11:05:49 +02:00
enable_serial_console ttyS0
2016-06-28 18:32:54 +02:00
;;
2017-08-27 20:46:27 +02:00
pcduino3)
2018-04-22 13:44:17 +02:00
a20_setup_boot sun7i-a20-pcduino3.dtb "$EXTERNAL_DRIVE"
2017-08-27 20:46:27 +02:00
enable_serial_console ttyS0
;;
esac