Advertisement
Guest User

PinePhone uboot/atf/crust/mobian kernel/modem firmware build script

a guest
Feb 2nd, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.89 KB | None | 0 0
  1. #!/bin/bash
  2. set -e
  3. function LOG() { echo -e "\e[32m$@\e[0m"; }
  4.  
  5. # This script is used to compile the
  6. # u-boot+atf+crust, Mobian kernel, and Modem firmware
  7. # for the pinephone.
  8. # Use on Debian 11, preferably in a container or VM!
  9.  
  10. MAKE_PARALLEL="$(nproc)"
  11. OR1K_TOOLCHAIN_URL="https://musl.cc/or1k-linux-musl-cross.tgz"
  12. AARCH64_TOOLCHAIN_URL="https://musl.cc/aarch64-linux-musl-cross.tgz"
  13. CRUST_META_GIT="https://github.com/crust-firmware/meta"
  14. MOBIAN_KERNEL_GIT="https://gitlab.com/mobian1/devices/sunxi64-linux.git"
  15. MOBIAN_KERNEL_BRANCH="mobian-5.15"
  16. MOBIAN_KERNEL_DEFCONFIG="pine64_defconfig"
  17. PINEPHONE_MODEM_SDK_GIT="https://github.com/Biktorgj/pinephone_modem_sdk"
  18.  
  19. # install common build utils
  20. LOG "installing build tools..."
  21. sudo dpkg --add-architecture arm64
  22. sudo apt update -y
  23. sudo apt-get install -y \
  24. build-essential wget git bzip2 libgmp-dev libmpfr-dev libmpc-dev texinfo \
  25. gawk wget git diffstat unzip texinfo gcc build-essential chrpath socat cpio \
  26. python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping \
  27. python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev pylint3 xterm \
  28. python3-subunit mesa-common-dev zstd liblz4-tool \
  29. device-tree-compiler swig bison flex python3-distutils \
  30. libpython3.9-dev libssl-dev python3-setuptools \
  31. g++-aarch64-linux-gnu crossbuild-essential-arm64 \
  32. debootstrap u-boot-tools libncurses-dev \
  33. libssl-dev rsync kmod bc git-buildpackage
  34.  
  35.  
  36.  
  37.  
  38.  
  39. LOG "downloading toolchains..."
  40.  
  41.  
  42. # download or1k cross compiler
  43. if ! [ -d or1k-linux-musl-cross ]; then
  44.     wget "${OR1K_TOOLCHAIN_URL}" -O or1k-linux-musl-cross.tgz
  45.     tar -xvzf or1k-linux-musl-cross.tgz
  46.     rm or1k-linux-musl-cross.tgz
  47. fi
  48. # make sure toolchain is in PATH
  49. if ! [[ ":${PATH}:" == *":${PWD}:"* ]]; then
  50.     pushd or1k-linux-musl-cross/bin
  51.     export PATH="${PATH}:${PWD}"
  52.     echo -e "\n\n# or1k cross compiler for pinephone modem:\nexport PATH=\"${PATH}:${PWD}\"" >> ~/.bashrc
  53.     popd
  54. fi
  55. LOG "or1k toolchain ok!"
  56.  
  57.  
  58. # download aarch64 cross compiler
  59. # Could also use system aarch64 compiler, but musl is default for crust makefile
  60. if ! [ -d aarch64-linux-musl-cross ]; then
  61.     wget  "${AARCH64_TOOLCHAIN_URL}" -O aarch64-linux-musl-cross.tgz
  62.     tar -xvzf aarch64-linux-musl-cross.tgz
  63.     rm aarch64-linux-musl-cross.tgz
  64. fi
  65. # make sure toolchain is in PATH
  66. if ! [[ ":${PATH}:" == *":${PWD}:"* ]]; then
  67.     pushd aarch64-linux-musl-cross/bin
  68.     export PATH="${PATH}:${PWD}"
  69.     echo -e "\n\n# aarch64 cross compiler for pinephone modem:\nexport PATH=\"${PATH}:${PWD}\"" >> ~/.bashrc
  70.     popd
  71. fi
  72. LOG "aarch64 toolchain ok!"
  73.  
  74.  
  75.  
  76.  
  77.  
  78. # download crust firmware makefile
  79. LOG "crust building..."
  80. if ! [ -d crust ]; then
  81.     git clone "${CRUST_META_GIT}" crust
  82. fi
  83. pushd crust
  84.  
  85. # download required repositories if not downloaded already
  86. export HOME="${PWD}"
  87. if ! [ -d arm-trusted-firmware ]; then
  88.     BOARD="pinephone" make arm-trusted-firmware
  89. fi
  90. if ! [ -d crust ]; then
  91.     BOARD="pinephone" make crust
  92. fi
  93. if ! [ -d u-boot ]; then
  94.     BOARD="pinephone" make u-boot
  95. fi
  96.  
  97.  
  98. # make custom changes here, like copying in a defconfig file
  99. # *TODO*, e.g. edit u-boot/configs/pinephone_defconfig ot enable CONFIG_DRAM_CLK=624
  100.  
  101.  
  102. # compile u-boot, crust, atf
  103. BOARD="pinephone" make -j"${MAKE_PARALLEL}"
  104.  
  105. LOG "crust build toolchain ok!"
  106. popd
  107.  
  108.  
  109.  
  110.  
  111.  
  112. # build mobian kernel
  113. LOG "kernel building..."
  114.  
  115. # download debian kernel source
  116. if ! [ -d kernel ]; then
  117.     git clone -b "${MOBIAN_KERNEL_BRANCH}" "${MOBIAN_KERNEL_GIT}" kernel
  118. fi
  119.  
  120. pushd kernel
  121.  
  122. # needed for gbp to apply patches :/
  123. git config --global user.email "${USER}@${HOSTNAME}"
  124. git config --global user.name "${USER}"
  125.  
  126. # Import (Mobian/debian specific) patches
  127. gbp pq import || true
  128.  
  129. # apply default configuration
  130. ARCH="arm64" CROSS_COMPILE="aarch64-linux-gnu-" make -j"${MAKE_PARALLEL}" "${MOBIAN_KERNEL_DEFCONFIG}"
  131.  
  132. ARCH="arm64" CROSS_COMPILE="aarch64-linux-gnu-" make menuconfig || true
  133. # *TODO*: Here you could apply custom config values, or even run menuconfig
  134.  
  135. # build kernel, create .deb packages
  136. # uses the system aarch64 cross compiler
  137. ARCH="arm64" CROSS_COMPILE="aarch64-linux-gnu-" make -j"${MAKE_PARALLEL}" bindeb-pkg KERNELRELEASE="5.15-sunxi64-custom" KDEB_PKGVERSION="1"
  138. popd
  139.  
  140. LOG "kernel build ok!"
  141.  
  142.  
  143.  
  144.  
  145.  
  146. # build pinephone modem firmware
  147. if ! [ -d crust ]; then
  148.     git clone "${PINEPHONE_MODEM_SDK_GIT}" pinephone_modem_sdk
  149. fi
  150. pushd pinephone_modem_sdk
  151. ./init.sh
  152. make everything
  153. popd
  154. LOG "modem firmware build ok!"
  155.  
  156.  
  157.  
  158.  
  159.  
  160. # collect build artifacts
  161. mkdir -p artifacts
  162. # TODO: Get all artifacts, add installer script?
  163. cp *.deb artifacts/
  164. cp curst/u-boot/u-boot-sunxi-with-spl.bin artifacts/
  165. cp pinephone_modem_sdk/target/package.tar.gz artifacts/modem_firmware.tar
  166.  
  167.  
  168. ARTIFACTS_TAR="artifacts-$(date --iso-8601=seconds).tar"
  169. tar --force-local -vczf "${ARTIFACTS_TAR}" artifacts/
  170.  
  171.  
  172.  
  173.  
  174.  
  175. LOG
  176. LOG "Setup ok! Artifacts saved as artifacts.tar"
  177. LOG
  178. #LOG "(press enter to return)"
  179. #read
  180.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement