arm-sdk

os build toolkit for various embedded devices
git clone https://git.parazyd.org/arm-sdk
Log | Files | Refs | Submodules | README | LICENSE

pinephone.sh (4865B)


      1 #!/usr/bin/env zsh
      2 # Copyright (c) 2016-2021 Ivan J. <parazyd@dyne.org>
      3 # arm-sdk is written and maintained by Ivan J. <parazyd@dyne.org>
      4 #
      5 # This file is part of arm-sdk
      6 #
      7 # This source code is free software: you can redistribute it and/or modify
      8 # it under the terms of the GNU General Public License as published by
      9 # the Free Software Foundation, either version 3 of the License, or
     10 # (at your option) any later version.
     11 #
     12 # This software is distributed in the hope that it will be useful,
     13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 # GNU General Public License for more details.
     16 #
     17 # You should have received a copy of the GNU General Public License
     18 # along with this source code. If not, see <http://www.gnu.org/licenses/>.
     19 
     20 
     21 ## settings & config
     22 vars+=(device_name arch size parted_type parted_boot parted_root bootfs inittab)
     23 vars+=(gitkernel gitbranch atfgit crustgit crustbranch ubootgit ubootbranch)
     24 arrs+=(custmodules)
     25 
     26 device_name="pinephone"
     27 arch="arm64"
     28 size=1891
     29 inittab=("T1:12345:respawn:/sbin/agetty -L ttyS0 115200 vt100")
     30 
     31 parted_type="dos"
     32 bootfs="ext2"
     33 rootfs="ext4"
     34 dos_boot="$bootfs 2048s 264191s"
     35 dos_root="$rootfs 264192s 100%"
     36 
     37 extra_packages+=()
     38 custmodules=()
     39 
     40 gitkernel="https://github.com/maemo-leste/pine64-kernel"
     41 gitbranch="pine64-kernel-5.4.0"
     42 
     43 atfgit="https://github.com/ARM-software/arm-trusted-firmware.git"
     44 
     45 crustgit="https://github.com/crust-firmware/crust.git"
     46 crustbranch="master"
     47 
     48 ubootgit="https://gitlab.com/pine64-org/u-boot"
     49 ubootbranch="master"
     50 
     51 prebuild() {
     52 	fn prebuild
     53 	req=(device_name)
     54 	ckreq || return 1
     55 
     56 	notice "executing $device_name prebuild"
     57 
     58 	mkdir -p $R/tmp/kernels/$device_name
     59 }
     60 
     61 postbuild() {
     62 	fn postbuild
     63 	req=(device_name compiler loopdevice or1ktc)
     64 	ckreq || return 1
     65 
     66 	notice "executing $device_name postbuild"
     67 
     68 	copy-root-overlay
     69 
     70 	notice "building arm-trusted-firmware"
     71 	git clone --depth 1 "$atfgit" "$R/tmp/kernels/arm-trusted-firmware" || zerr
     72 	pushd "$R/tmp/kernels/arm-trusted-firmware"
     73 		make $MAKEOPTS CROSS_COMPILE=$compiler PLAT=sun50i_a64 DEBUG=1 bl31 || zerr
     74 	popd
     75 
     76 	notice "building crust"
     77 	git clone --depth 1 "$crustgit" -b "$crustbranch" "$R/tmp/kernels/crust" || zerr
     78 	pushd "$R/tmp/kernels/crust"
     79 		or1ktc="or1k-linux-musl-"
     80 		wget -c "http://musl.cc/${or1ktc}cross.tgz"
     81 		tar xf "${or1ktc}cross.tgz"
     82 		export PATH="$PATH:$(pwd)/or1k-linux-musl/bin"
     83 		make $MAKEOPTS CROSS_COMPILE="$or1ktc" pinephone_defconfig || zerr
     84 		make $MAKEOPTS CROSS_COMPILE="$or1ktc" scp || zerr
     85 	popd
     86 
     87 	notice "building u-boot"
     88 	git clone --depth 1 "$ubootgit" -b "$ubootbranch" "$R/tmp/kernels/u-boot-pinephone" || zerr
     89 	pushd "$R/tmp/kernels/u-boot-pinephone"
     90 		make $MAKEOPTS \
     91 			BL31="$R/tmp/kernels/arm-trusted-firmware/build/sun50i_a64/debug/bl31.bin" \
     92 			SCP="$R/tmp/kernels/crust/build/scp/scp.bin" \
     93 			pinephone_defconfig || zerr
     94 		make $MAKEOPTS \
     95 			BL31="$R/tmp/kernels/arm-trusted-firmware/build/sun50i_a64/debug/bl31.bin" \
     96 			SCP="$R/tmp/kernels/crust/build/scp/scp.bin" \
     97 			ARCH=arm CROSS_COMPILE=$compiler || zerr
     98 		mkdir -p "$R/dist"
     99 		cp u-boot-sunxi-with-spl.bin "$R/dist/u-boot-sunxi-with-spl-pinephone.bin"
    100 	popd
    101 
    102 	cat <<EOF | sudo tee "${strapdir}/boot/boot.txt"
    103 setenv bootargs console=tty0 console=\${console} root=/dev/mmcblk0p2 rw rootwait rootfstype=ext4 fbcon=rotate:1
    104 setenv kernel_addr_z 0x44080000
    105 
    106 if load \${devtype} \${devnum}:\${distro_bootpart} \${kernel_addr_z} Image.gz; then
    107   unzip \${kernel_addr_z} \${kernel_addr_r}
    108   if load \${devtype} \${devnum}:\${distro_bootpart} \${fdt_addr_r} \${fdtfile}; then
    109     booti \${kernel_addr_r} - \${fdt_addr_r};
    110   fi;
    111 fi
    112 EOF
    113 	pushd "${strapdir}/boot"
    114 		sudo mkimage -C none -A arm -T script -d boot.txt boot.scr
    115 	popd
    116 
    117 	sudo dd if="$R/dist/u-boot-sunxi-with-spl-pinephone.bin" of="${loopdevice}" seek=8 \
    118 		bs=1024 conv=notrunc,nocreat
    119 
    120 	postbuild-clean
    121 }
    122 
    123 build_kernel_arm64() {
    124 	fn build_kernel_arm64
    125 	req=(R arch device_name gitkernel gitbranch MAKEOPTS)
    126 	req+=(strapdir)
    127 	ckreq || return 1
    128 
    129 	notice "building $arch kernel"
    130 
    131 	prebuild || zerr
    132 
    133 	get-kernel-sources
    134 	pushd $R/tmp/kernels/$device_name/${device_name}-linux
    135 		wget -O- https://github.com/maemo-leste/pine64-kernel/raw/maemo/ascii-devel/debian/patches/0001-Include-rtl8723cs-staging-driver.patch | patch -p1
    136 
    137 		copy-kernel-config
    138 
    139 		# compile kernel and modules
    140 		make \
    141 			$MAKEOPTS \
    142 			ARCH=arm64 \
    143 			CROSS_COMPILE=$compiler \
    144 			Image.gz modules allwinner/sun50i-a64-pinephone.dtb || zerr
    145 
    146 		# install kernel modules
    147 		sudo -E PATH="$PATH" \
    148 			make \
    149 				$MAKEOPTS \
    150 				ARCH=arm \
    151 				CROSS_COMPILE=$compiler \
    152 				INSTALL_MOD_PATH=$strapdir \
    153 					modules_install || zerr
    154 
    155 		sudo cp -v arch/arm64/boot/Image $strapdir/boot/ || zerr
    156 		sudo cp -v arch/arm64/boot/dts/allwinner/sun50i-a64-pinephone.dtb \
    157 			"$strapdir/boot/" || zerr
    158 	popd
    159 
    160 	postbuild || zerr
    161 }