Newer
Older
# _____ _ _
# | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# | __| _| -_| -_| . | . | | . | . | | -_|
# |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
#
# Hardware setup based on bin/freedombox-hardware-setup from freedom-maker
#
# License
# =======
#
# Copyright (C) 2014-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
convert_dtb() {
dtb="$1"
dts=$(echo "${dtb}" | sed 's|.dtb||g')
dts_filename="/root/${PROJECT_NAME}/image_build/dts/${dts}"
if [ ! -d /boot/dtbs ]; then
mkdir -p /boot/dtbs
fi
if [ -f "${dts_filename}.dtb" ]; then
cp "${dts_filename}.dtb" "/boot/dtbs/${dtb}"
else
if [ -f "${dts_filename}.dts" ]; then
if [ ! -f "/boot/dtbs/${dtb}" ]; then
$INSTALL_PACKAGES device-tree-compiler
dtc -I dts -O dtb "${dts_filename}.dts" > "/boot/dtbs/${dtb}"
fi
fi
fi
# By default, spawn a console on the serial port
device="$1"
echo "T0:12345:respawn:/sbin/getty -L $device 115200 vt100" >> /etc/inittab
}
generic_setup_boot() {
architecture="$1"
console_device="$2"
boot_type="$3"
dtb="$4"
generic_root_device='mmcblk0p2'
extra_module="$5"
root_device_type="mmc"
if [ "$7" ]; then
root_device_type="$6"
generic_root_device="$7"
fi
manufacturer=
# shellcheck disable=SC2012,SC2086
kernelVersion=$(ls /usr/lib/*/$dtb | head -1 | cut -d/ -f4)
if [ ! "$kernelVersion" ]; then
# shellcheck disable=SC2012,SC2086
kernelVersion=$(ls /usr/lib/*/*/$dtb | head -1 | cut -d/ -f3)
# shellcheck disable=SC2012,SC2086
manufacturer=$(ls /usr/lib/linux-*/*/$dtb | head -1 | cut -d/ -f4)
fi
version=$(echo "$kernelVersion" | sed 's/linux-image-\(.*\)/\1/')
initRd=initrd.img-$version
vmlinuz=vmlinuz-$version
if [ "$boot_type" = "uenv" ]; then
cat >> /boot/uEnv.txt <<EOF
mmcroot=/dev/${generic_root_device} ro
kernel_file=$vmlinuz
initrd_file=$initRd
loadaddr=0x82000000
initrd_addr=0x88080000
fdtaddr=0x88000000
initrd_high=0xffffffff
fdt_high=0xffffffff
loadkernel=load ${root_device_type} \${mmcdev}:\${mmcpart} \${loadaddr} \${kernel_file}
loadinitrd=load ${root_device_type} \${mmcdev}:\${mmcpart} \${initrd_addr} \${initrd_file}; setenv initrd_size \${filesize}
loadfdt=load ${root_device_type} \${mmcdev}:\${mmcpart} \${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} ifnames=0 slub_debug=FZP slab_nomerge page_poison=1
uenvcmd=run loadfiles; run mmcargs; bootz \${loadaddr} \${initrd_addr}:\${initrd_size} \${fdtaddr}
EOF
setenv mmcdev 0
setenv mmcpart 1
setenv mmcroot /dev/${generic_root_device} ro
setenv mmcrootfstype ext4 rootwait fixrtc
setenv console ${console_device},${console_speed}
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 ${root_device_type} \${mmcdev}:\${mmcpart} \${loadaddr} \${kernel_file}
setenv loadinitrd load ${root_device_type} \${mmcdev}:\${mmcpart} \${initrd_addr} \${initrd_file}\\; setenv initrd_size \\\${filesize}
setenv loadfdt load ${root_device_type} \${mmcdev}:\${mmcpart} \${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} ifnames=0 slub_debug=FZP slab_nomerge page_poison=1
run loadfiles; run mmcargs; bootz \${loadaddr} \${initrd_addr}:\${initrd_size} \${fdtaddr}
# generate boot.scr
mkimage -C none -A "${architecture}" -T script -d /boot/boot.cmd /boot/boot.scr
echo "vfat" >> /etc/initramfs-tools/modules
if [ "$extra_module" ]; then
echo "$extra_module" >> /etc/initramfs-tools/modules
# Copy all DTBs for the manufacturer
if [ ! -d /boot/dtbs ]; then
mkdir -p /boot/dtbs
ls "/usr/lib/$kernelVersion"
if [ "$manufacturer" ]; then
# shellcheck disable=SC2086
cp -r /usr/lib/$kernelVersion/$manufacturer/* /boot/dtbs
else
# shellcheck disable=SC2086
cp -r /usr/lib/$kernelVersion/* /boot/dtbs
beagleboneblack)
generic_setup_boot arm ttyO0 uenv am335x-boneblack.dtb "" mmc "$EXTERNAL_DRIVE"
generic_setup_boot arm ttyO0 uenv am335x-bonegreen.dtb "" mmc "$EXTERNAL_DRIVE"
generic_setup_boot arm ttyO0 uenv am57xx-beagle-x15.dtb "" mmc "$EXTERNAL_DRIVE"
generic_setup_boot arm ttyS0 boot sun7i-a20-cubietruck.dtb rtc_sunxi mmc "$EXTERNAL_DRIVE"
generic_setup_boot arm ttyS0 boot sun7i-a20-olinuxino-lime.dtb rtc_sunxi mmc "$EXTERNAL_DRIVE"
generic_setup_boot arm ttyS0 boot sun7i-a20-olinuxino-lime2.dtb rtc_sunxi mmc "$EXTERNAL_DRIVE"
generic_setup_boot arm ttyS0 boot sun7i-a20-olinuxino-micro.dtb rtc_sunxi mmc "$EXTERNAL_DRIVE"
generic_setup_boot arm ttyS0 boot sun7i-a20-bananapro.dtb rtc_sunxi mmc "$EXTERNAL_DRIVE"
generic_setup_boot arm ttyS0 boot sun7i-a20-cubieboard2.dtb rtc_sunxi mmc "$EXTERNAL_DRIVE"
generic_setup_boot arm ttyS0 boot sun7i-a20-pcduino3.dtb rtc_sunxi mmc "$EXTERNAL_DRIVE"
console_speed='1500000'
generic_setup_boot arm64 ttyS2 boot rk3328-rock64.dtb "" usb "$EXTERNAL_DRIVE"
;;
renegade)
console_speed='1500000'
generic_setup_boot arm64 ttyS2 boot rk3328-roc-cc.dtb "" usb "$EXTERNAL_DRIVE"