rock64.sh (6065B)
1 #!/usr/bin/env zsh 2 # Copyright (c) 2017 Johny Mattsson <johny.mattsson+github@gmail.com> 3 # 4 # This source code is free software: you can redistribute it and/or modify 5 # it under the terms of the GNU General Public License as published by 6 # the Free Software Foundation, either version 3 of the License, or 7 # (at your option) any later version. 8 # 9 # This software is distributed in the hope that it will be useful, 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 # GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License 15 # along with this source code. If not, see <http://www.gnu.org/licenses/>. 16 17 ## kernel build script for Rock64 boards 18 19 vars+=(device_name arch size inittab parted_type gpt_boot gpt_root bootfs) 20 vars+=(gitkernel gitbranch) 21 22 device_name="rock64" 23 arch="arm64" 24 size=1891 25 inittab=("T1:12345:respawn:/sbin/agetty -L ttyS2 1500000 vt100") 26 27 # There's a lot of reserved areas at the start, see: 28 # http://opensource.rock-chips.com/wiki_Partitions 29 parted_type="gpt" 30 gpt_boot=(32768 229376) 31 gpt_root=(262144) 32 bootfs="vfat" 33 34 gitkernel=mainline 35 gitbranch="linux-4.14-rc2" 36 37 # Mainline u-boot does not yet have full Rock64 support, so have to fetch this 38 rock64uboot=https://github.com/ayufan-rock64/linux-u-boot.git 39 rock64ubootbr=mainline-master 40 rock64ubootdir="$R/tmp/u-boot/${device_name}-u-boot" 41 # Likewise, no u-boot SPL support for the 3288 yet, so need binary loader 42 rkbin=https://github.com/rockchip-linux/rkbin 43 rkbindir="$R/tmp/rkbin" 44 45 expr "${qemu_bin}" : ".*aarch.*" >/dev/null || { 46 error "qemu_bin needs to be arm64 variety (a.k.a. aarch, aarch64)" 47 return 1 48 } 49 50 expr "${compiler}" : ".*aarch64.*" >/dev/null || { 51 error "compiler needs to be arm64 variety (a.k.a. aarch64)" 52 return 1 53 } 54 55 get_rock64_uboot_sources() { 56 fn get_rock64_uboot_sources 57 req=(rock64uboot rock64ubootdir rock64ubootbr) 58 ckreq || return 1 59 60 clone-git "${rock64uboot}" "${rock64ubootdir}" "${rock64ubootbr}" 61 } 62 63 get_rkbin() { 64 fn get_rkbin 65 req=(rkbin rkbindir) 66 ckreq || return 1 67 68 clone-git "${rkbin}" "${rkbindir}" 69 } 70 71 build_uboot_rock64() { 72 fn build_uboot_rock64 73 req=(rock64ubootdir rock64ubootbuild compiler MAKEOPTS) 74 ckreq || return 1 75 76 notice "building u-boot for Rock64" 77 pushd "${rock64ubootdir}" 78 make O="${rock64ubootbuild}" distclean 79 make $MAKEOPTS \ 80 ARCH=arm CROSS_COMPILE=$compiler \ 81 O="${rock64ubootbuild}" rock64-rk3328_defconfig || zerr 82 make $MAKEOPTS \ 83 ARCH=arm CROSS_COMPILE=$compiler \ 84 O="${rock64ubootbuild}" all || zerr 85 popd 86 } 87 88 build_loader_rock64() { 89 fn build_loader_rock64 90 req=(rkbindir rock64ubootbuild) 91 ckreq || return 1 92 93 notice "assembling loader images" 94 pushd "${rock64ubootbuild}" 95 act "creating idbloader.img" 96 dd if="${rkbindir}/rk33/rk3328_ddr_786MHz_v1.06.bin" of=ddr.bin bs=4 skip=1 status=none || zerr 97 tools/mkimage -n rk3328 -T rksd -d ddr.bin idbloader.img || zerr 98 rm -f ddr.bin 99 cat "${rkbindir}/rk33/rk3328_miniloader_v2.43.bin" >> idbloader.img 100 101 act "repacking u-boot for idbloader into uboot.img" 102 "${rkbindir}/tools/loaderimage" --pack --uboot u-boot-dtb.bin uboot.img 0x200000 || zerr 103 104 act "generating trust.img" 105 cat > trust.ini <<EOF 106 [VERSION] 107 MAJOR=1 108 MINOR=2 109 [BL30_OPTION] 110 SEC=0 111 [BL31_OPTION] 112 SEC=1 113 PATH=${rkbindir}/rk33/rk3328_bl31_v1.34.bin 114 ADDR=0x10000 115 [BL32_OPTION] 116 SEC=0 117 [BL33_OPTION] 118 SEC=0 119 [OUTPUT] 120 PATH=trust.img 121 EOF 122 "${rkbindir}/tools/trust_merger" trust.ini 123 popd 124 } 125 126 prebuild() { 127 fn prebuild 128 req=(device_name strapdir) 129 ckreq || return 1 130 131 notice "executing $device_name prebuild" 132 133 copy-root-overlay 134 135 cat << EOF | sudo tee -a "${strapdir}/etc/motd" 136 137 To expand the root partition, run: 138 parted /dev/mmcblk0 resizepart 2 100% 139 resize2fs /dev/mmcblk0p2 140 141 EOF 142 143 mkdir -p "$R/tmp/kernels/${device_name}" 144 } 145 146 postbuild() { 147 fn postbuild 148 req=(strapdir loopdevice) 149 ckreq || return 1 150 151 notice "executing $device_name postbuild" 152 153 rock64ubootbuild="${workdir}/${device_name}-build-u-boot" 154 155 get_rock64_uboot_sources || zerr 156 get_rkbin || zerr 157 158 build_uboot_rock64 || zerr 159 build_loader_rock64 || zerr 160 161 notice "dd'ing loaders to the image" 162 pushd "${rock64ubootbuild}" 163 sudo dd if=idbloader.img bs=512 seek=64 of="${loopdevice}" status=none conv=notrunc || zerr 164 sudo dd if=uboot.img bs=512 seek=16384 of="${loopdevice}" status=none conv=notrunc || zerr 165 sudo dd if=trust.img bs=512 seek=24576 of="${loopdevice}" status=none conv=notrunc || zerr 166 popd 167 168 notice "touching up partition names and flags" 169 sudo parted -s "${loopdevice}" name 1 "boot" || zerr 170 sudo parted -s "${loopdevice}" name 2 "root" || zerr 171 sudo parted -s "${loopdevice}" set 1 legacy_boot on || zerr 172 sudo parted -s "${loopdevice}" set 2 msftdata off || zerr 173 174 notice "setting up extlinux.conf" 175 sudo mkdir -p "${strapdir}/boot/extlinux" 176 cat << EOF | sudo tee "${strapdir}/boot/extlinux/extlinux.conf" >/dev/null 177 label main 178 kernel /Image 179 fdt /dtbs/rk3328-rock64.dtb 180 append earlycon=uart8250,mmio32,0xff130000 coherent_pool=1M ethaddr=\${ethaddr} eth1addr=\${eth1addr} serial=\${serial#} rw root=/dev/mmcblk0p2 rootwait 181 EOF 182 183 postbuild-clean 184 } 185 186 build_kernel_arm64() { 187 fn build_kernel_arm64 188 req=(R arch device_name gitkernel gitbranch MAKEOPTS) 189 req+=(strapdir ubootmainline) 190 req+=(loopdevice) 191 ckreq || return 1 192 193 notice "building $arch kernel" 194 195 prebuild || zerr 196 197 get-kernel-sources 198 pushd "$R/tmp/kernels/${device_name}/${device_name}-linux" 199 copy-kernel-config 200 201 make \ 202 $MAKEOPTS \ 203 ARCH=arm64 \ 204 CROSS_COMPILE=$compiler \ 205 Image dtbs modules || zerr 206 sudo -E PATH="$PATH" \ 207 make \ 208 $MAKEOPTS \ 209 ARCH=arm64 \ 210 CROSS_COMPILE=$compiler \ 211 INSTALL_MOD_PATH="$strapdir" \ 212 modules_install || zerr 213 214 sudo cp -v arch/arm64/boot/Image "${strapdir}/boot/" || zerr 215 sudo mkdir -p "${strapdir}/boot/dtbs" 216 dtb="rk3328-rock64.dtb" 217 sudo cp -v arch/arm64/boot/dts/rockchip/${dtb} "${strapdir}/boot/dtbs/" || zerr 218 popd 219 220 postbuild || zerr 221 }