main.sh 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2013-2021 Igor Pecovnik, igor.pecovnik@gma**.com
  4. #
  5. # This file is licensed under the terms of the GNU General Public
  6. # License version 2. This program is licensed "as is" without any
  7. # warranty of any kind, whether express or implied.
  8. #
  9. # Main program
  10. #
  11. cleanup_list() {
  12. local varname="${1}"
  13. local list_to_clean="${!varname}"
  14. list_to_clean="${list_to_clean#"${list_to_clean%%[![:space:]]*}"}"
  15. list_to_clean="${list_to_clean%"${list_to_clean##*[![:space:]]}"}"
  16. echo ${list_to_clean}
  17. }
  18. if [[ $(basename "$0") == main.sh ]]; then
  19. echo "Please use build.sh to start the build process"
  20. exit 255
  21. fi
  22. # default umask for root is 022 so parent directories won't be group writeable without this
  23. # this is used instead of making the chmod in prepare_host() recursive
  24. umask 002
  25. # destination
  26. if [ -d "$CONFIG_PATH/output" ]; then
  27. DEST="${CONFIG_PATH}"/output
  28. else
  29. DEST="${SRC}"/output
  30. fi
  31. [[ -z $REVISION ]] && REVISION="3.0.8"
  32. [[ $DOWNLOAD_MIRROR == "china" ]] && NTP_SERVER="cn.pool.ntp.org"
  33. if [[ $BUILD_ALL != "yes" ]]; then
  34. # override stty size
  35. [[ -n $COLUMNS ]] && stty cols $COLUMNS
  36. [[ -n $LINES ]] && stty rows $LINES
  37. TTY_X=$(($(stty size | awk '{print $2}')-6)) # determine terminal width
  38. TTY_Y=$(($(stty size | awk '{print $1}')-6)) # determine terminal height
  39. fi
  40. # We'll use this title on all menus
  41. backtitle="Orange Pi building script, http://www.orangepi.org"
  42. titlestr="Choose an option"
  43. # Warnings mitigation
  44. [[ -z $LANGUAGE ]] && export LANGUAGE="en_US:en" # set to english if not set
  45. [[ -z $CONSOLE_CHAR ]] && export CONSOLE_CHAR="UTF-8" # set console to UTF-8 if not set
  46. # Libraries include
  47. # shellcheck source=debootstrap.sh
  48. source "${SRC}"/scripts/debootstrap.sh # system specific install
  49. # shellcheck source=image-helpers.sh
  50. source "${SRC}"/scripts/image-helpers.sh # helpers for OS image building
  51. # shellcheck source=distributions.sh
  52. source "${SRC}"/scripts/distributions.sh # system specific install
  53. # shellcheck source=desktop.sh
  54. source "${SRC}"/scripts/desktop.sh # desktop specific install
  55. # shellcheck source=compilation.sh
  56. source "${SRC}"/scripts/compilation.sh # patching and compilation of kernel, uboot, ATF
  57. # shellcheck source=compilation-prepare.sh
  58. #source "${SRC}"/scripts/compilation-prepare.sh # drivers that are not upstreamed
  59. # shellcheck source=makeboarddeb.sh
  60. source "${SRC}"/scripts/makeboarddeb.sh # board support package
  61. # shellcheck source=general.sh
  62. source "${SRC}"/scripts/general.sh # general functions
  63. # shellcheck source=chroot-buildpackages.sh
  64. source "${SRC}"/scripts/chroot-buildpackages.sh # chroot packages building
  65. # shellcheck source=pack.sh
  66. source "${SRC}"/scripts/pack-uboot.sh
  67. # set log path
  68. LOG_SUBPATH=${LOG_SUBPATH:=debug}
  69. # compress and remove old logs
  70. mkdir -p "${DEST}"/${LOG_SUBPATH}
  71. (cd "${DEST}"/${LOG_SUBPATH} && tar -czf logs-"$(<timestamp)".tgz ./*.log) > /dev/null 2>&1
  72. rm -f "${DEST}"/${LOG_SUBPATH}/*.log > /dev/null 2>&1
  73. date +"%d_%m_%Y-%H_%M_%S" > "${DEST}"/${LOG_SUBPATH}/timestamp
  74. # delete compressed logs older than 7 days
  75. (cd "${DEST}"/${LOG_SUBPATH} && find . -name '*.tgz' -mtime +7 -delete) > /dev/null
  76. if [[ $PROGRESS_DISPLAY == none ]]; then
  77. OUTPUT_VERYSILENT=yes
  78. elif [[ $PROGRESS_DISPLAY == dialog ]]; then
  79. OUTPUT_DIALOG=yes
  80. fi
  81. if [[ $PROGRESS_LOG_TO_FILE != yes ]]; then unset PROGRESS_LOG_TO_FILE; fi
  82. SHOW_WARNING=yes
  83. if [[ $USE_CCACHE != no ]]; then
  84. CCACHE=ccache
  85. export PATH="/usr/lib/ccache:$PATH"
  86. # private ccache directory to avoid permission issues when using build script with "sudo"
  87. # see https://ccache.samba.org/manual.html#_sharing_a_cache for alternative solution
  88. [[ $PRIVATE_CCACHE == yes ]] && export CCACHE_DIR=$EXTER/cache/ccache
  89. else
  90. CCACHE=""
  91. fi
  92. if [[ -n $REPOSITORY_UPDATE ]]; then
  93. # select stable/beta configuration
  94. if [[ $BETA == yes ]]; then
  95. DEB_STORAGE=$DEST/debs-beta
  96. REPO_STORAGE=$DEST/repository-beta
  97. REPO_CONFIG="aptly-beta.conf"
  98. else
  99. DEB_STORAGE=$DEST/debs
  100. REPO_STORAGE=$DEST/repository
  101. REPO_CONFIG="aptly.conf"
  102. fi
  103. # For user override
  104. if [[ -f "${USERPATCHES_PATH}"/lib.config ]]; then
  105. display_alert "Using user configuration override" "userpatches/lib.config" "info"
  106. source "${USERPATCHES_PATH}"/lib.config
  107. fi
  108. repo-manipulate "$REPOSITORY_UPDATE"
  109. exit
  110. fi
  111. # if BUILD_OPT, KERNEL_CONFIGURE, BOARD, BRANCH or RELEASE are not set, display selection menu
  112. if [[ -z $BUILD_OPT ]]; then
  113. options+=("u-boot" "U-boot package")
  114. options+=("kernel" "Kernel package")
  115. options+=("rootfs" "Rootfs and all deb packages")
  116. options+=("image" "Full OS image for flashing")
  117. menustr="Compile image | rootfs | kernel | u-boot"
  118. BUILD_OPT=$(whiptail --title "${titlestr}" --backtitle "${backtitle}" --notags \
  119. --menu "${menustr}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
  120. --cancel-button Exit --ok-button Select "${options[@]}" \
  121. 3>&1 1>&2 2>&3)
  122. unset options
  123. [[ -z $BUILD_OPT ]] && exit_with_error "No option selected"
  124. [[ $BUILD_OPT == rootfs ]] && ROOT_FS_CREATE_ONLY="yes"
  125. fi
  126. if [[ ${BUILD_OPT} =~ kernel|image ]]; then
  127. if [[ -z $KERNEL_CONFIGURE ]]; then
  128. options+=("no" "Do not change the kernel configuration")
  129. options+=("yes" "Show a kernel configuration menu before compilation")
  130. menustr="Select the kernel configuration."
  131. KERNEL_CONFIGURE=$(whiptail --title "${titlestr}" --backtitle "$backtitle" --notags \
  132. --menu "${menustr}" $TTY_Y $TTY_X $((TTY_Y - 8)) \
  133. --cancel-button Exit --ok-button Select "${options[@]}" \
  134. 3>&1 1>&2 2>&3)
  135. unset options
  136. [[ -z $KERNEL_CONFIGURE ]] && exit_with_error "No option selected"
  137. fi
  138. fi
  139. if [[ -z $BOARD ]]; then
  140. #options+=("orangepir1" "Allwinner H2+ quad core 256MB RAM WiFi SPI 2xETH")
  141. #options+=("orangepizero" "Allwinner H2+ quad core 256MB/512MB RAM WiFi SPI")
  142. #options+=("orangepipc" "Allwinner H3 quad core 1GB RAM")
  143. #options+=("orangepipcplus" "Allwinner H3 quad core 1GB RAM WiFi eMMC")
  144. #options+=("orangepione" "Allwinner H3 quad core 512MB RAM")
  145. #options+=("orangepilite" "Allwinner H3 quad core 512MB RAM WiFi")
  146. #options+=("orangepiplus" "Allwinner H3 quad core 1GB/2GB RAM WiFi GBE eMMC")
  147. #options+=("orangepiplus2e" "Allwinner H3 quad core 2GB RAM WiFi GBE eMMC")
  148. #options+=("orangepizeroplus2h3" "Allwinner H3 quad core 512MB RAM WiFi/BT eMMC")
  149. #options+=("orangepipch5" "Allwinner H5 quad core 1GB RAM")
  150. #options+=("orangepipc2" "Allwinner H5 quad core 1GB RAM GBE SPI")
  151. #options+=("orangepioneh5" "Allwinner H5 quad core 512MB/1GB RAM")
  152. #options+=("orangepiprime" "Allwinner H5 quad core 2GB RAM GBE WiFi/BT")
  153. #options+=("orangepizeroplus" "Allwinner H5 quad core 512MB RAM GBE WiFi SPI")
  154. #options+=("orangepizeroplus2h5" "Allwinner H5 quad core 512MB RAM WiFi/BT eMMC")
  155. options+=("orangepi3" "Allwinner H6 quad core 1GB/2GB RAM GBE WiFi/BT eMMC USB3")
  156. options+=("orangepi3-lts" "Allwinner H6 quad core 2GB RAM GBE WiFi/BT-AW859A eMMC USB3")
  157. #options+=("orangepilite2" "Allwinner H6 quad core 1GB RAM WiFi/BT USB3")
  158. #options+=("orangepioneplus" "Allwinner H6 quad core 1GB RAM GBE")
  159. options+=("orangepizero2" "Allwinner H616 quad core 512MB/1GB RAM WiFi/BT GBE SPI")
  160. #options+=("orangepizero2-b" "Allwinner H616 quad core 512MB/1GB RAM WiFi/BT GBE SPI")
  161. #options+=("orangepizero2-lts" "Allwinner H616 quad core 1.5GB RAM WiFi/BT GBE SPI")
  162. options+=("orangepizero3" "Allwinner H618 quad core 1GB/1.5GB/2GB/4GB RAM WiFi/BT GBE SPI")
  163. options+=("orangepizero2w" "Allwinner H618 quad core 1GB/1.5GB/2GB/4GB RAM WiFi/BT SPI")
  164. #options+=("orangepir1b" "Allwinner H618 quad core 1.5GB/2GB/4GB RAM WiFi/BT GBE SPI")
  165. #options+=("orangepi400" "Allwinner H616 quad core 4GB RAM WiFi/BT GBE eMMC VGA")
  166. options+=("orangepi4" "Rockchip RK3399 hexa core 4GB RAM GBE eMMC USB3 USB-C WiFi/BT")
  167. options+=("orangepi4a" "Allwinner T527 octa core 2-4GB RAM GBE WiFi/BT NVMe eMMC")
  168. options+=("orangepi4-lts" "Rockchip RK3399 hexa core 4GB RAM GBE eMMC USB3 USB-C WiFi/BT")
  169. options+=("orangepi800" "Rockchip RK3399 hexa core 4GB RAM GBE eMMC USB3 USB-C WiFi/BT VGA")
  170. options+=("orangepi5" "Rockchip RK3588S octa core 4-16GB RAM GBE USB3 USB-C NVMe")
  171. options+=("orangepicm5" "Rockchip RK3588S octa core 4-16GB RAM GBE USB3 USB-C")
  172. options+=("orangepicm5-tablet" "Rockchip RK3588S octa core 4-16GB RAM USB3 USB-C WiFi/BT")
  173. options+=("orangepi5b" "Rockchip RK3588S octa core 4-16GB RAM GBE USB3 USB-C WiFi/BT eMMC")
  174. #options+=("orangepitab" "Rockchip RK3588S octa core 4-16GB RAM USB-C WiFi/BT NVMe")
  175. #options+=("orangepi900" "Rockchip RK3588 octa core 4-16GB RAM 2.5GBE USB3 USB-C WiFi/BT NVMe")
  176. options+=("orangepi5pro" "Rockchip RK3588S octa core 4-16GB RAM GBE USB3 WiFi/BT NVMe eMMC")
  177. options+=("orangepi5max" "Rockchip RK3588 octa core 4-16GB RAM 2.5GBE USB3 WiFi/BT NVMe eMMC")
  178. options+=("orangepi5ultra" "Rockchip RK3588 octa core 4-16GB RAM 2.5GBE USB3 WiFi/BT NVMe eMMC")
  179. options+=("orangepi5plus" "Rockchip RK3588 octa core 4-32GB RAM 2.5GBE USB3 USB-C WiFi/BT NVMe eMMC")
  180. options+=("orangepicm4" "Rockchip RK3566 quad core 2-8GB RAM GBE eMMC USB3 NvMe WiFi/BT")
  181. options+=("orangepi3b" "Rockchip RK3566 quad core 2-8GB RAM GBE eMMC USB3 NvMe WiFi/BT")
  182. options+=("orangepirv" "Starfive JH7110 quad core 2-8GB RAM GBE USB3 NvMe WiFi/BT")
  183. options+=("orangepirv2" "Ky X1 octa core 2-8GB RAM GBE USB3 WiFi/BT NVMe eMMC")
  184. #options+=("orangepir2s" "Ky X1 octa core 2-8GB RAM 2.5GBE USB3 eMMC")
  185. #options+=("orangepir1plus" "Rockchip RK3328 quad core 1GB RAM 2xGBE USB2 SPI")
  186. #options+=("orangepi3plus" "Amlogic S905D3 quad core 2/4GB RAM SoC eMMC GBE USB3 SPI WiFi/BT")
  187. menustr="Please choose a Board."
  188. BOARD=$(whiptail --title "${titlestr}" --backtitle "${backtitle}" \
  189. --menu "${menustr}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
  190. --cancel-button Exit --ok-button Select "${options[@]}" \
  191. 3>&1 1>&2 2>&3)
  192. unset options
  193. [[ -z $BOARD ]] && exit_with_error "No option selected"
  194. fi
  195. BOARD_TYPE="conf"
  196. # shellcheck source=/dev/null
  197. source "${EXTER}/config/boards/${BOARD}.${BOARD_TYPE}"
  198. LINUXFAMILY="${BOARDFAMILY}"
  199. [[ -z $KERNEL_TARGET ]] && exit_with_error "Board configuration does not define valid kernel config"
  200. if [[ -z $BRANCH ]]; then
  201. options=()
  202. [[ $KERNEL_TARGET == *current* ]] && options+=("current" "Recommended. Come with best support")
  203. [[ $KERNEL_TARGET == *legacy* ]] && options+=("legacy" "Old stable / Legacy")
  204. [[ $KERNEL_TARGET == *next* ]] && options+=("next" "Use the latest kernel")
  205. menustr="Select the target kernel branch\nExact kernel versions depend on selected board"
  206. # do not display selection dialog if only one kernel branch is available
  207. if [[ "${#options[@]}" == 2 ]]; then
  208. BRANCH="${options[0]}"
  209. else
  210. BRANCH=$(whiptail --title "${titlestr}" --backtitle "${backtitle}" \
  211. --menu "${menustr}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
  212. --cancel-button Exit --ok-button Select "${options[@]}" \
  213. 3>&1 1>&2 2>&3)
  214. fi
  215. unset options
  216. [[ -z $BRANCH ]] && exit_with_error "No kernel branch selected"
  217. [[ $BRANCH == dev && $SHOW_WARNING == yes ]] && show_developer_warning
  218. fi
  219. if [[ $BUILD_OPT =~ rootfs|image && -z $RELEASE ]]; then
  220. options=()
  221. distros_options
  222. menustr="Select the target OS release package base"
  223. RELEASE=$(whiptail --title "Choose a release package base" --backtitle "${backtitle}" \
  224. --menu "${menustr}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
  225. --cancel-button Exit --ok-button Select "${options[@]}" \
  226. 3>&1 1>&2 2>&3)
  227. #echo "options : ${options}"
  228. [[ -z $RELEASE ]] && exit_with_error "No release selected"
  229. unset options
  230. fi
  231. # don't show desktop option if we choose minimal build
  232. [[ $BUILD_MINIMAL == yes ]] && BUILD_DESKTOP=no
  233. if [[ $BUILD_OPT =~ rootfs|image && -z $BUILD_DESKTOP ]]; then
  234. # read distribution support status which is written to the orangepi-release file
  235. set_distribution_status
  236. options=()
  237. options+=("no" "Image with console interface (server)")
  238. options+=("yes" "Image with desktop environment")
  239. menustr="Select the target image type"
  240. BUILD_DESKTOP=$(whiptail --title "Choose image type" --backtitle "${backtitle}" \
  241. --menu "${menustr}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
  242. --cancel-button Exit --ok-button Select "${options[@]}" \
  243. 3>&1 1>&2 2>&3)
  244. unset options
  245. [[ -z $BUILD_DESKTOP ]] && exit_with_error "No option selected"
  246. if [[ ${BUILD_DESKTOP} == "yes" ]]; then
  247. BUILD_MINIMAL=no
  248. SELECTED_CONFIGURATION="desktop"
  249. fi
  250. fi
  251. if [[ $BUILD_OPT =~ rootfs|image && $BUILD_DESKTOP == no && -z $BUILD_MINIMAL ]]; then
  252. options=()
  253. options+=("no" "Standard image with console interface")
  254. options+=("yes" "Minimal image with console interface")
  255. menustr="Select the target image type"
  256. BUILD_MINIMAL=$(whiptail --title "Choose image type" --backtitle "${backtitle}" \
  257. --menu "${menustr}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
  258. --cancel-button Exit --ok-button Select "${options[@]}" \
  259. 3>&1 1>&2 2>&3)
  260. unset options
  261. [[ -z $BUILD_MINIMAL ]] && exit_with_error "No option selected"
  262. if [[ $BUILD_MINIMAL == "yes" ]]; then
  263. SELECTED_CONFIGURATION="cli_minimal"
  264. else
  265. SELECTED_CONFIGURATION="cli_standard"
  266. fi
  267. fi
  268. #prevent conflicting setup
  269. if [[ $BUILD_DESKTOP == "yes" ]]; then
  270. BUILD_MINIMAL=no
  271. SELECTED_CONFIGURATION="desktop"
  272. elif [[ $BUILD_MINIMAL != "yes" || -z "${BUILD_MINIMAL}" ]]; then
  273. BUILD_MINIMAL=no # Just in case BUILD_MINIMAL is not defined
  274. BUILD_DESKTOP=no
  275. SELECTED_CONFIGURATION="cli_standard"
  276. elif [[ $BUILD_MINIMAL == "yes" ]]; then
  277. BUILD_DESKTOP=no
  278. SELECTED_CONFIGURATION="cli_minimal"
  279. fi
  280. #[[ ${KERNEL_CONFIGURE} == prebuilt ]] && [[ -z ${REPOSITORY_INSTALL} ]] && \
  281. #REPOSITORY_INSTALL="u-boot,kernel,bsp,orangepi-zsh,orangepi-config,orangepi-firmware${BUILD_DESKTOP:+,orangepi-desktop}"
  282. #shellcheck source=configuration.sh
  283. source "${SRC}"/scripts/configuration.sh
  284. # optimize build time with 100% CPU usage
  285. CPUS=$(grep -c 'processor' /proc/cpuinfo)
  286. if [[ $USEALLCORES != no ]]; then
  287. CTHREADS="-j$((CPUS + CPUS/2))"
  288. else
  289. CTHREADS="-j1"
  290. fi
  291. call_extension_method "post_determine_cthreads" "config_post_determine_cthreads" << 'POST_DETERMINE_CTHREADS'
  292. *give config a chance modify CTHREADS programatically. A build server may work better with hyperthreads-1 for example.*
  293. Called early, before any compilation work starts.
  294. POST_DETERMINE_CTHREADS
  295. if [[ $BETA == yes ]]; then
  296. IMAGE_TYPE=nightly
  297. elif [[ $BETA != "yes" && $BUILD_ALL == yes && -n $GPG_PASS ]]; then
  298. IMAGE_TYPE=stable
  299. else
  300. IMAGE_TYPE=user-built
  301. fi
  302. branch2dir() {
  303. [[ "${1}" == "head" ]] && echo "HEAD" || echo "${1##*:}"
  304. }
  305. BOOTSOURCEDIR="${BOOTDIR}/$(branch2dir "${BOOTBRANCH}")"
  306. LINUXSOURCEDIR="${KERNELDIR}/$(branch2dir "${KERNELBRANCH}")"
  307. [[ -n $ATFSOURCE ]] && ATFSOURCEDIR="${ATFDIR}/$(branch2dir "${ATFBRANCH}")"
  308. BSP_CLI_PACKAGE_NAME="orangepi-bsp-cli-${BOARD}"
  309. BSP_CLI_PACKAGE_FULLNAME="${BSP_CLI_PACKAGE_NAME}_${REVISION}_${ARCH}"
  310. BSP_DESKTOP_PACKAGE_NAME="orangepi-bsp-desktop-${BOARD}"
  311. BSP_DESKTOP_PACKAGE_FULLNAME="${BSP_DESKTOP_PACKAGE_NAME}_${REVISION}_${ARCH}"
  312. CHOSEN_UBOOT=linux-u-boot-${BRANCH}-${BOARD}
  313. CHOSEN_KERNEL=linux-image-${BRANCH}-${LINUXFAMILY}
  314. CHOSEN_ROOTFS=${BSP_CLI_PACKAGE_NAME}
  315. CHOSEN_DESKTOP=orangepi-${RELEASE}-desktop-${DESKTOP_ENVIRONMENT}
  316. CHOSEN_KSRC=linux-source-${BRANCH}-${LINUXFAMILY}
  317. do_default() {
  318. start=$(date +%s)
  319. # Check and install dependencies, directory structure and settings
  320. # The OFFLINE_WORK variable inside the function
  321. prepare_host
  322. [[ "${JUST_INIT}" == "yes" ]] && exit 0
  323. [[ $CLEAN_LEVEL == *sources* ]] && cleaning "sources"
  324. # fetch_from_repo <url> <dir> <ref> <subdir_flag>
  325. # ignore updates help on building all images - for internal purposes
  326. if [[ ${IGNORE_UPDATES} != yes ]]; then
  327. display_alert "Downloading sources" "" "info"
  328. [[ $BUILD_OPT =~ u-boot|image ]] && fetch_from_repo "$BOOTSOURCE" "$BOOTDIR" "$BOOTBRANCH" "yes"
  329. [[ $BUILD_OPT =~ kernel|image ]] && fetch_from_repo "$KERNELSOURCE" "$KERNELDIR" "$KERNELBRANCH" "yes"
  330. if [[ -n ${ATFSOURCE} ]]; then
  331. [[ ${BUILD_OPT} =~ u-boot|image ]] && fetch_from_repo "$ATFSOURCE" "${EXTER}/cache/sources/$ATFDIR" "$ATFBRANCH" "yes"
  332. fi
  333. if [[ ${BOARD} =~ orangepi4|orangepi4-lts|orangepi800 && $BRANCH == legacy ]]; then
  334. [[ $BUILD_OPT =~ image ]] && fetch_from_repo "https://github.com/orangepi-xunlong/rk3399_gst_xserver_libs.git" "${EXTER}/cache/sources/rk3399_gst_xserver_libs" "branch:main"
  335. fi
  336. if [[ ${BOARD} =~ orangepiaimax ]]; then
  337. [[ $BUILD_OPT =~ image ]] && fetch_from_repo "https://github.com/orangepi-xunlong/ascend-driver.git" "${EXTER}/cache/sources/ascend-driver" "branch:main"
  338. fi
  339. if [[ "${BOARD}x" =~ orangepi4x|orangepi4-ltsx|orangepi800x && $RELEASE =~ focal|buster|bullseye|bookworm ]]; then
  340. [[ ${BUILD_OPT} == image ]] && fetch_from_repo "https://github.com/orangepi-xunlong/rk-rootfs-build.git" "${EXTER}/cache/sources/rk-rootfs-build-${RELEASE}" "branch:rk-rootfs-build-${RELEASE}"
  341. [[ ${BUILD_OPT} == image ]] && fetch_from_repo "https://github.com/orangepi-xunlong/rk-rootfs-build.git" "${EXTER}/cache/sources/rk35xx_packages" "branch:rk35xx_packages"
  342. fi
  343. if [[ ${BOARDFAMILY} == "rockchip-rk3588" && $RELEASE =~ bullseye|bookworm|focal|jammy|raspi ]]; then
  344. [[ ${BUILD_OPT} == image ]] && fetch_from_repo "https://github.com/orangepi-xunlong/rk-rootfs-build.git" "${EXTER}/cache/sources/rk35xx_packages" "branch:rk35xx_packages"
  345. fi
  346. if [[ ${BOARDFAMILY} == "rockchip-rk356x" && $RELEASE =~ bullseye|focal|jammy|raspi ]]; then
  347. [[ ${BUILD_OPT} == image ]] && fetch_from_repo "https://github.com/orangepi-xunlong/rk-rootfs-build.git" "${EXTER}/cache/sources/rk35xx_packages" "branch:rk35xx_packages"
  348. fi
  349. if [[ ${BOARDFAMILY} == "ky" && $RELEASE =~ noble ]]; then
  350. [[ ${BUILD_OPT} == image ]] && fetch_from_repo "https://github.com/orangepi-xunlong/rk-rootfs-build.git" "${EXTER}/cache/sources/ky_packages" "branch:ky_packages"
  351. fi
  352. if [[ ${BOARDFAMILY} == "sun55iw3" && $RELEASE =~ bookworm|jammy ]]; then
  353. [[ ${BUILD_OPT} == image ]] && fetch_from_repo "https://github.com/orangepi-xunlong/rk-rootfs-build.git" "${EXTER}/cache/sources/t527_packages" "branch:t527_packages"
  354. fi
  355. if [[ ${BOARD} =~ orangepi3|orangepi3-lts && $RELEASE =~ bullseye && $BRANCH == current ]]; then
  356. [[ ${BUILD_OPT} == image ]] && fetch_from_repo "https://github.com/orangepi-xunlong/rk-rootfs-build.git" "${EXTER}/cache/sources/ffmpeg_kodi_${RELEASE}" "branch:ffmpeg_kodi_${RELEASE}"
  357. fi
  358. if [[ "${BOARD}x" =~ orangepi4x|orangepi4-ltsx|orangepi800x && $RELEASE =~ jammy && $BRANCH == next ]]; then
  359. [[ ${BUILD_OPT} == image ]] && fetch_from_repo "https://github.com/orangepi-xunlong/rk-rootfs-build.git" "${EXTER}/cache/sources/ffmpeg_kodi_${RELEASE}" "branch:ffmpeg_kodi_${RELEASE}"
  360. fi
  361. call_extension_method "fetch_sources_tools" <<- 'FETCH_SOURCES_TOOLS'
  362. *fetch host-side sources needed for tools and build*
  363. Run early to fetch_from_repo or otherwise obtain sources for needed tools.
  364. FETCH_SOURCES_TOOLS
  365. call_extension_method "build_host_tools" <<- 'BUILD_HOST_TOOLS'
  366. *build needed tools for the build, host-side*
  367. After sources are fetched, build host-side tools needed for the build.
  368. BUILD_HOST_TOOLS
  369. fi
  370. for option in $(tr ',' ' ' <<< "$CLEAN_LEVEL"); do
  371. [[ $option != sources ]] && cleaning "$option"
  372. done
  373. # Compile u-boot if packed .deb does not exist or use the one from Orange Pi
  374. if [[ $BUILD_OPT == u-boot || $BUILD_OPT == image ]]; then
  375. if [[ ! -f "${DEB_STORAGE}"/u-boot/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb ]]; then
  376. [[ -n "${ATFSOURCE}" && "${REPOSITORY_INSTALL}" != *u-boot* ]] && compile_atf
  377. [[ ${REPOSITORY_INSTALL} != *u-boot* ]] && compile_uboot
  378. fi
  379. if [[ $BUILD_OPT == "u-boot" ]]; then
  380. unset BUILD_MINIMAL BUILD_DESKTOP COMPRESS_OUTPUTIMAGE
  381. display_alert "U-boot build done" "@host" "info"
  382. display_alert "Target directory" "${DEB_STORAGE}/u-boot" "info"
  383. display_alert "File name" "${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb" "info"
  384. fi
  385. fi
  386. # Compile kernel if packed .deb does not exist or use the one from Orange Pi
  387. if [[ $BUILD_OPT == kernel || $BUILD_OPT == image ]]; then
  388. if [[ ! -f ${DEB_STORAGE}/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb ]]; then
  389. KDEB_CHANGELOG_DIST=$RELEASE
  390. [[ "${REPOSITORY_INSTALL}" != *kernel* ]] && compile_kernel
  391. fi
  392. if [[ $BUILD_OPT == "kernel" ]]; then
  393. unset BUILD_MINIMAL BUILD_DESKTOP COMPRESS_OUTPUTIMAGE
  394. display_alert "Kernel build done" "@host" "info"
  395. display_alert "Target directory" "${DEB_STORAGE}/" "info"
  396. display_alert "File name" "${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb" "info"
  397. fi
  398. fi
  399. if [[ $BUILD_OPT == rootfs || $BUILD_OPT == image ]]; then
  400. # Compile orangepi-config if packed .deb does not exist or use the one from Orange Pi
  401. if [[ ! -f ${DEB_STORAGE}/orangepi-config_${REVISION}_all.deb ]]; then
  402. [[ "${REPOSITORY_INSTALL}" != *orangepi-config* ]] && compile_orangepi-config
  403. fi
  404. # Compile orangepi-zsh if packed .deb does not exist or use the one from repository
  405. if [[ ! -f ${DEB_STORAGE}/orangepi-zsh_${REVISION}_all.deb ]]; then
  406. [[ "${REPOSITORY_INSTALL}" != *orangepi-zsh* ]] && compile_orangepi-zsh
  407. fi
  408. # Compile plymouth-theme-orangepi if packed .deb does not exist or use the one from repository
  409. if [[ ! -f ${DEB_STORAGE}/plymouth-theme-orangepi_${REVISION}_all.deb ]]; then
  410. [[ "${REPOSITORY_INSTALL}" != *plymouth-theme-orangepi* ]] && compile_plymouth-theme-orangepi
  411. fi
  412. # Compile orangepi-firmware if packed .deb does not exist or use the one from repository
  413. if [[ "${REPOSITORY_INSTALL}" != *orangepi-firmware* ]]; then
  414. if ! ls "${DEB_STORAGE}/orangepi-firmware_${REVISION}_all.deb" 1> /dev/null 2>&1; then
  415. FULL=""
  416. REPLACE="-full"
  417. compile_firmware
  418. fi
  419. #if ! ls "${DEB_STORAGE}/orangepi-firmware-full_${REVISION}_all.deb" 1> /dev/null 2>&1; then
  420. #FULL="-full"
  421. #REPLACE=""
  422. #compile_firmware
  423. #fi
  424. fi
  425. overlayfs_wrapper "cleanup"
  426. # create board support package
  427. [[ -n $RELEASE && ! -f ${DEB_STORAGE}/$RELEASE/${BSP_CLI_PACKAGE_FULLNAME}.deb ]] && create_board_package
  428. # create desktop package
  429. #[[ -n $RELEASE && $DESKTOP_ENVIRONMENT && ! -f ${DEB_STORAGE}/$RELEASE/${CHOSEN_DESKTOP}_${REVISION}_all.deb ]] && create_desktop_package
  430. #[[ -n $RELEASE && $DESKTOP_ENVIRONMENT && ! -f ${DEB_STORAGE}/${RELEASE}/${BSP_DESKTOP_PACKAGE_FULLNAME}.deb ]] && create_bsp_desktop_package
  431. [[ -n $RELEASE && $DESKTOP_ENVIRONMENT ]] && create_desktop_package
  432. [[ -n $RELEASE && $DESKTOP_ENVIRONMENT ]] && create_bsp_desktop_package
  433. # build additional packages
  434. [[ $EXTERNAL_NEW == compile ]] && chroot_build_packages
  435. [[ $BSP_BUILD != yes ]] && debootstrap_ng
  436. fi
  437. # hook for function to run after build, i.e. to change owner of $SRC
  438. # NOTE: this will run only if there were no errors during build process
  439. [[ $(type -t run_after_build) == function ]] && run_after_build || true
  440. end=$(date +%s)
  441. runtime=$(((end-start)/60))
  442. display_alert "Runtime" "$runtime min" "info"
  443. # Make it easy to repeat build by displaying build options used
  444. [ "$(systemd-detect-virt)" == 'docker' ] && BUILD_CONFIG='docker'
  445. display_alert "Repeat Build Options" "sudo ./build.sh ${BUILD_CONFIG} BOARD=${BOARD} BRANCH=${BRANCH} \
  446. $([[ -n $BUILD_OPT ]] && echo "BUILD_OPT=${BUILD_OPT} ")\
  447. $([[ -n $RELEASE ]] && echo "RELEASE=${RELEASE} ")\
  448. $([[ -n $BUILD_MINIMAL ]] && echo "BUILD_MINIMAL=${BUILD_MINIMAL} ")\
  449. $([[ -n $BUILD_DESKTOP ]] && echo "BUILD_DESKTOP=${BUILD_DESKTOP} ")\
  450. $([[ -n $KERNEL_CONFIGURE ]] && echo "KERNEL_CONFIGURE=${KERNEL_CONFIGURE} ")\
  451. $([[ -n $DESKTOP_ENVIRONMENT ]] && echo "DESKTOP_ENVIRONMENT=${DESKTOP_ENVIRONMENT} ")\
  452. $([[ -n $DESKTOP_ENVIRONMENT_CONFIG_NAME ]] && echo "DESKTOP_ENVIRONMENT_CONFIG_NAME=${DESKTOP_ENVIRONMENT_CONFIG_NAME} ")\
  453. $([[ -n $DESKTOP_APPGROUPS_SELECTED ]] && echo "DESKTOP_APPGROUPS_SELECTED=\"${DESKTOP_APPGROUPS_SELECTED}\" ")\
  454. $([[ -n $DESKTOP_APT_FLAGS_SELECTED ]] && echo "DESKTOP_APT_FLAGS_SELECTED=\"${DESKTOP_APT_FLAGS_SELECTED}\" ")\
  455. $([[ -n $COMPRESS_OUTPUTIMAGE ]] && echo "COMPRESS_OUTPUTIMAGE=${COMPRESS_OUTPUTIMAGE} ")\
  456. " "ext"
  457. } # end of do_default()
  458. if [[ -z $1 ]]; then
  459. do_default
  460. else
  461. eval "$@"
  462. fi