Newer
Older
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
#
# Hardware setup based on bin/freedombox-hardware-setup from freedom-maker
#
# Booting beaglebones from a USB drive does not work at present, due to
# missing kernel config. See:
# http://processors.wiki.ti.com/index.php/MUSB_Linux_Driver_Configuration
#
# Copyright (C) 2015-2019 Bob Mottram <bob@freedombone.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# 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
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
export TEXTDOMAIN=${PROJECT_NAME}-image-hardware-setup
INSTALL_PACKAGES='apt-get -yq install'
# By default, spawn a console on the serial port
device="$1"
echo "T0:12345:respawn:/sbin/getty -L $device 115200 vt100" >> /etc/inittab
}
# 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...
if ! $INSTALL_PACKAGES flash-kernel; then
echo "Unable to flash kernel for $FK_MACHINE"
# 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...
kernelVersion=$(ls /usr/lib/*/${dtb}.dtb | head -1 | cut -d/ -f4)
initRd=initrd.img-$version
vmlinuz=vmlinuz-$version
# optionally use a separately compiled kernel
(cd /tmp/initrd-repack || exit 24 ; \
rm -f conf/param.conf ; \
find . | cpio --quiet -o -H newc | \
mkimage -A "${arm_arch}" -O linux -T kernel -n "Debian kernel ${version}" \
-C none -a "${arm_loadaddr}" -e "${arm_loadaddr}" -d temp-kernel uImage ; \
mkimage -A "${arm_arch}" -O linux -T ramdisk -C gzip -a "${arm_initrd_addr}" -e "${arm_initrd_addr}" \
setup_flash_kernel() {
if [ ! -d /etc/flash-kernel ] ; then
mkdir /etc/flash-kernel
fi
command_line=""
if [ -n "$2" ] ; then
command_line="console=$2"
fi
if [ -n "$command_line" ] ; then
echo "flash-kernel flash-kernel/linux_cmdline string \"$command_line\"" | debconf-set-selections
$INSTALL_PACKAGES flash-kernel
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
arm_setup_boot() {
dtb="$1"
arm_root_device='mmcblk0p2'
if [ "$EXTERNAL_DRIVE" ]; then
arm_root_device="$EXTERNAL_DRIVE"
fi
arm_flash_name=
if [ "$2" ]; then
arm_flash_name="$2"
fi
# Setup boot.cmd
if grep -q btrfs /etc/fstab ; then
fstype=btrfs
else
fstype=ext4
fi
# shellcheck disable=SC2012,SC2086
kernelVersion=$(ls /usr/lib/*/${dtb}.dtb | head -1 | cut -d/ -f4)
version=$(echo "$kernelVersion" | sed 's/linux-image-\(.*\)/\1/')
initRd=initrd.img-$version
vmlinuz=vmlinuz-$version
arm_loadaddr='0x46000000'
arm_initrd_addr='0x48000000'
arm_fdtaddr='0x47000000'
arm_boot_script=/boot/boot.cmd
case "$dtb" in
"am"*) arm_loadaddr='0x82000000'
arm_initrd_addr='0x88080000'
arm_fdtaddr='0x88000000'
arm_boot_script=/boot/uEnv.txt
if [ "$EXTERNAL_DRIVE" ]; then
arm_boot_dev='bootdev=0:1'
arm_loadaddr='0x80300000'
arm_initrd_addr='0x81600000'
arm_fdtaddr='0x815f0000'
arm_boot_start='usb start; '
fi
"sun"*) { echo "rtc_sunxi";
echo "vfat"; } >> /etc/initramfs-tools/modules
;;
"rock"*) arm_arch=arm64
echo "vfat" >> /etc/initramfs-tools/modules
esac
case "$dtb" in
"am"*) cat >> $arm_boot_script <<EOF
mmcroot=/dev/${arm_root_device} ro
mmcrootfstype=$fstype rootwait fixrtc
mmcrootflags=subvol=@
kernel_file=$vmlinuz
initrd_file=$initRd
loadaddr=$arm_loadaddr
initrd_addr=$arm_initrd_addr
fdtaddr=$arm_fdtaddr
initrd_high=0xffffffff
fdt_high=0xffffffff
loadkernel=load ${arm_boot_device} \${loadaddr} \${kernel_file}
loadinitrd=load ${arm_boot_device} \${initrd_addr} \${initrd_file}; setenv initrd_size \${filesize}
loadfdt=load ${arm_boot_device} \${fdtaddr} /dtbs/\${fdtfile}
loadfiles=run loadkernel; run loadinitrd; run loadfdt
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
uenvcmd=${arm_boot_start}run loadfiles; run mmcargs; bootz \${loadaddr} \${initrd_addr}:\${initrd_size} \${fdtaddr}
EOF
;;
*) cat >> $arm_boot_script <<EOF
setenv mmcdev 0
setenv mmcpart 1
setenv mmcroot /dev/${arm_root_device} ro
setenv mmcrootfstype $fstype rootwait fixrtc
setenv mmcrootflags subvol=@
setenv kernel_file $vmlinuz
setenv initrd_file $initRd
setenv loadaddr $arm_loadaddr
setenv initrd_addr $arm_initrd_addr
setenv fdtaddr $arm_fdtaddr
setenv initrd_high 0xffffffff
setenv fdt_high 0xffffffff
setenv loadkernel load ${arm_boot_device} \${loadaddr} \${kernel_file}
setenv loadinitrd load ${arm_boot_device} \${initrd_addr} \${initrd_file}\\; setenv initrd_size \\\${filesize}
setenv loadfdt load ${arm_boot_device} \${fdtaddr} /dtbs/\${fdtfile}
setenv loadfiles run loadkernel\\; run loadinitrd\\; run loadfdt
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
${arm_boot_start}run loadfiles; run mmcargs; bootz \${loadaddr} \${initrd_addr}:\${initrd_size} \${fdtaddr}
if [ "$arm_boot_script" = "/boot/boot.cmd" ]; then
# Create boot.scr
mkimage -C none -A arm -T script -d /boot/boot.cmd /boot/boot.scr
# shellcheck disable=SC2086
cp /usr/lib/$kernelVersion/* /boot/dtbs
else
# Copy all DTBs
cp /usr/lib/linux-image-*-armmp/* /boot/dtbs
if [ "$arm_flash_name" ]; then
case "$arm_flash_name" in
"TI "*)
arm_flash "$arm_flash_name"
arm_repack_kernel "${dtb}" "$arm_loadaddr" "$arm_initrd_addr" "$arm_arch"
enable_serial_console ttyS0
beagleboneblack)
arm_setup_boot am335x-boneblack "TI AM335x BeagleBone Black"
arm_setup_boot am335x-bonegreen "TI AM335x BeagleBone Green"
arm_setup_boot am57xx-beagle-x15 "TI AM5728 BeagleBoard-X15"