main.sh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  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+=("orangepi4-lts" "Rockchip RK3399 hexa core 4GB RAM GBE eMMC USB3 USB-C WiFi/BT")
  168. options+=("orangepi800" "Rockchip RK3399 hexa core 4GB RAM GBE eMMC USB3 USB-C WiFi/BT VGA")
  169. options+=("orangepi5" "Rockchip RK3588S octa core 4-16GB RAM GBE USB3 USB-C NVMe")
  170. options+=("orangepicm5" "Rockchip RK3588S octa core 4-16GB RAM GBE USB3 USB-C")
  171. options+=("orangepicm5-tablet" "Rockchip RK3588S octa core 4-16GB RAM USB3 USB-C WiFi/BT")
  172. options+=("orangepi5b" "Rockchip RK3588S octa core 4-16GB RAM GBE USB3 USB-C WiFi/BT eMMC")
  173. #options+=("orangepitab" "Rockchip RK3588S octa core 4-16GB RAM USB-C WiFi/BT NVMe")
  174. #options+=("orangepi900" "Rockchip RK3588 octa core 4-16GB RAM 2.5GBE USB3 USB-C WiFi/BT NVMe")
  175. options+=("orangepi5pro" "Rockchip RK3588S octa core 4-16GB RAM GBE USB3 WiFi/BT NVMe eMMC")
  176. options+=("orangepi5max" "Rockchip RK3588 octa core 4-16GB RAM 2.5GBE USB3 WiFi/BT NVMe eMMC")
  177. options+=("orangepi5plus" "Rockchip RK3588 octa core 4-32GB RAM 2.5GBE USB3 USB-C WiFi/BT NVMe eMMC")
  178. options+=("orangepicm4" "Rockchip RK3566 quad core 2-8GB RAM GBE eMMC USB3 NvMe WiFi/BT")
  179. options+=("orangepi3b" "Rockchip RK3566 quad core 2-8GB RAM GBE eMMC USB3 NvMe WiFi/BT")
  180. #options+=("orangepir1plus" "Rockchip RK3328 quad core 1GB RAM 2xGBE USB2 SPI")
  181. #options+=("orangepi3plus" "Amlogic S905D3 quad core 2/4GB RAM SoC eMMC GBE USB3 SPI WiFi/BT")
  182. menustr="Please choose a Board."
  183. BOARD=$(whiptail --title "${titlestr}" --backtitle "${backtitle}" \
  184. --menu "${menustr}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
  185. --cancel-button Exit --ok-button Select "${options[@]}" \
  186. 3>&1 1>&2 2>&3)
  187. unset options
  188. [[ -z $BOARD ]] && exit_with_error "No option selected"
  189. fi
  190. BOARD_TYPE="conf"
  191. # shellcheck source=/dev/null
  192. source "${EXTER}/config/boards/${BOARD}.${BOARD_TYPE}"
  193. LINUXFAMILY="${BOARDFAMILY}"
  194. [[ -z $KERNEL_TARGET ]] && exit_with_error "Board configuration does not define valid kernel config"
  195. if [[ -z $BRANCH ]]; then
  196. options=()
  197. [[ $KERNEL_TARGET == *current* ]] && options+=("current" "Recommended. Come with best support")
  198. [[ $KERNEL_TARGET == *legacy* ]] && options+=("legacy" "Old stable / Legacy")
  199. [[ $KERNEL_TARGET == *next* ]] && options+=("next" "Use the latest kernel")
  200. menustr="Select the target kernel branch\nExact kernel versions depend on selected board"
  201. # do not display selection dialog if only one kernel branch is available
  202. if [[ "${#options[@]}" == 2 ]]; then
  203. BRANCH="${options[0]}"
  204. else
  205. BRANCH=$(whiptail --title "${titlestr}" --backtitle "${backtitle}" \
  206. --menu "${menustr}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
  207. --cancel-button Exit --ok-button Select "${options[@]}" \
  208. 3>&1 1>&2 2>&3)
  209. fi
  210. unset options
  211. [[ -z $BRANCH ]] && exit_with_error "No kernel branch selected"
  212. [[ $BRANCH == dev && $SHOW_WARNING == yes ]] && show_developer_warning
  213. fi
  214. if [[ $BUILD_OPT =~ rootfs|image && -z $RELEASE ]]; then
  215. options=()
  216. distros_options
  217. menustr="Select the target OS release package base"
  218. RELEASE=$(whiptail --title "Choose a release package base" --backtitle "${backtitle}" \
  219. --menu "${menustr}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
  220. --cancel-button Exit --ok-button Select "${options[@]}" \
  221. 3>&1 1>&2 2>&3)
  222. #echo "options : ${options}"
  223. [[ -z $RELEASE ]] && exit_with_error "No release selected"
  224. unset options
  225. fi
  226. # don't show desktop option if we choose minimal build
  227. [[ $BUILD_MINIMAL == yes ]] && BUILD_DESKTOP=no
  228. if [[ $BUILD_OPT =~ rootfs|image && -z $BUILD_DESKTOP ]]; then
  229. # read distribution support status which is written to the orangepi-release file
  230. set_distribution_status
  231. options=()
  232. options+=("no" "Image with console interface (server)")
  233. options+=("yes" "Image with desktop environment")
  234. menustr="Select the target image type"
  235. BUILD_DESKTOP=$(whiptail --title "Choose image type" --backtitle "${backtitle}" \
  236. --menu "${menustr}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
  237. --cancel-button Exit --ok-button Select "${options[@]}" \
  238. 3>&1 1>&2 2>&3)
  239. unset options
  240. [[ -z $BUILD_DESKTOP ]] && exit_with_error "No option selected"
  241. if [[ ${BUILD_DESKTOP} == "yes" ]]; then
  242. BUILD_MINIMAL=no
  243. SELECTED_CONFIGURATION="desktop"
  244. fi
  245. fi
  246. if [[ $BUILD_OPT =~ rootfs|image && $BUILD_DESKTOP == no && -z $BUILD_MINIMAL ]]; then
  247. options=()
  248. options+=("no" "Standard image with console interface")
  249. options+=("yes" "Minimal image with console interface")
  250. menustr="Select the target image type"
  251. BUILD_MINIMAL=$(whiptail --title "Choose image type" --backtitle "${backtitle}" \
  252. --menu "${menustr}" "${TTY_Y}" "${TTY_X}" $((TTY_Y - 8)) \
  253. --cancel-button Exit --ok-button Select "${options[@]}" \
  254. 3>&1 1>&2 2>&3)
  255. unset options
  256. [[ -z $BUILD_MINIMAL ]] && exit_with_error "No option selected"
  257. if [[ $BUILD_MINIMAL == "yes" ]]; then
  258. SELECTED_CONFIGURATION="cli_minimal"
  259. else
  260. SELECTED_CONFIGURATION="cli_standard"
  261. fi
  262. fi
  263. #prevent conflicting setup
  264. if [[ $BUILD_DESKTOP == "yes" ]]; then
  265. BUILD_MINIMAL=no
  266. SELECTED_CONFIGURATION="desktop"
  267. elif [[ $BUILD_MINIMAL != "yes" || -z "${BUILD_MINIMAL}" ]]; then
  268. BUILD_MINIMAL=no # Just in case BUILD_MINIMAL is not defined
  269. BUILD_DESKTOP=no
  270. SELECTED_CONFIGURATION="cli_standard"
  271. elif [[ $BUILD_MINIMAL == "yes" ]]; then
  272. BUILD_DESKTOP=no
  273. SELECTED_CONFIGURATION="cli_minimal"
  274. fi
  275. #[[ ${KERNEL_CONFIGURE} == prebuilt ]] && [[ -z ${REPOSITORY_INSTALL} ]] && \
  276. #REPOSITORY_INSTALL="u-boot,kernel,bsp,orangepi-zsh,orangepi-config,orangepi-firmware${BUILD_DESKTOP:+,orangepi-desktop}"
  277. #shellcheck source=configuration.sh
  278. source "${SRC}"/scripts/configuration.sh
  279. # optimize build time with 100% CPU usage
  280. CPUS=$(grep -c 'processor' /proc/cpuinfo)
  281. if [[ $USEALLCORES != no ]]; then
  282. CTHREADS="-j$((CPUS + CPUS/2))"
  283. else
  284. CTHREADS="-j1"
  285. fi
  286. call_extension_method "post_determine_cthreads" "config_post_determine_cthreads" << 'POST_DETERMINE_CTHREADS'
  287. *give config a chance modify CTHREADS programatically. A build server may work better with hyperthreads-1 for example.*
  288. Called early, before any compilation work starts.
  289. POST_DETERMINE_CTHREADS
  290. if [[ $BETA == yes ]]; then
  291. IMAGE_TYPE=nightly
  292. elif [[ $BETA != "yes" && $BUILD_ALL == yes && -n $GPG_PASS ]]; then
  293. IMAGE_TYPE=stable
  294. else
  295. IMAGE_TYPE=user-built
  296. fi
  297. branch2dir() {
  298. [[ "${1}" == "head" ]] && echo "HEAD" || echo "${1##*:}"
  299. }
  300. BOOTSOURCEDIR="${BOOTDIR}/$(branch2dir "${BOOTBRANCH}")"
  301. LINUXSOURCEDIR="${KERNELDIR}/$(branch2dir "${KERNELBRANCH}")"
  302. [[ -n $ATFSOURCE ]] && ATFSOURCEDIR="${ATFDIR}/$(branch2dir "${ATFBRANCH}")"
  303. BSP_CLI_PACKAGE_NAME="orangepi-bsp-cli-${BOARD}"
  304. BSP_CLI_PACKAGE_FULLNAME="${BSP_CLI_PACKAGE_NAME}_${REVISION}_${ARCH}"
  305. BSP_DESKTOP_PACKAGE_NAME="orangepi-bsp-desktop-${BOARD}"
  306. BSP_DESKTOP_PACKAGE_FULLNAME="${BSP_DESKTOP_PACKAGE_NAME}_${REVISION}_${ARCH}"
  307. CHOSEN_UBOOT=linux-u-boot-${BRANCH}-${BOARD}
  308. CHOSEN_KERNEL=linux-image-${BRANCH}-${LINUXFAMILY}
  309. CHOSEN_ROOTFS=${BSP_CLI_PACKAGE_NAME}
  310. CHOSEN_DESKTOP=orangepi-${RELEASE}-desktop-${DESKTOP_ENVIRONMENT}
  311. CHOSEN_KSRC=linux-source-${BRANCH}-${LINUXFAMILY}
  312. do_default() {
  313. start=$(date +%s)
  314. # Check and install dependencies, directory structure and settings
  315. # The OFFLINE_WORK variable inside the function
  316. prepare_host
  317. [[ "${JUST_INIT}" == "yes" ]] && exit 0
  318. [[ $CLEAN_LEVEL == *sources* ]] && cleaning "sources"
  319. # fetch_from_repo <url> <dir> <ref> <subdir_flag>
  320. # ignore updates help on building all images - for internal purposes
  321. if [[ ${IGNORE_UPDATES} != yes ]]; then
  322. display_alert "Downloading sources" "" "info"
  323. [[ $BUILD_OPT =~ u-boot|image ]] && fetch_from_repo "$BOOTSOURCE" "$BOOTDIR" "$BOOTBRANCH" "yes"
  324. [[ $BUILD_OPT =~ kernel|image ]] && fetch_from_repo "$KERNELSOURCE" "$KERNELDIR" "$KERNELBRANCH" "yes"
  325. if [[ -n ${ATFSOURCE} ]]; then
  326. [[ ${BUILD_OPT} =~ u-boot|image ]] && fetch_from_repo "$ATFSOURCE" "${EXTER}/cache/sources/$ATFDIR" "$ATFBRANCH" "yes"
  327. fi
  328. if [[ ${BOARD} =~ orangepi4|orangepi4-lts|orangepi800 && $BRANCH == legacy ]]; then
  329. [[ $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"
  330. fi
  331. if [[ ${BOARD} =~ orangepi4|orangepi4-lts|orangepi800 && $RELEASE =~ focal|buster|bullseye|bookworm ]]; then
  332. [[ ${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}"
  333. fi
  334. if [[ ${BOARDFAMILY} == "rockchip-rk3588" && $RELEASE =~ bullseye|bookworm|focal|jammy|raspi ]]; then
  335. [[ ${BUILD_OPT} == image ]] && fetch_from_repo "https://github.com/orangepi-xunlong/rk-rootfs-build.git" "${EXTER}/cache/sources/rk35xx_packages" "branch:rk35xx_packages"
  336. fi
  337. if [[ ${BOARDFAMILY} == "rockchip-rk356x" && $RELEASE =~ bullseye|focal|jammy|raspi ]]; then
  338. [[ ${BUILD_OPT} == image ]] && fetch_from_repo "https://github.com/orangepi-xunlong/rk-rootfs-build.git" "${EXTER}/cache/sources/rk35xx_packages" "branch:rk35xx_packages"
  339. fi
  340. if [[ ${BOARD} =~ orangepi3|orangepi3-lts && $RELEASE =~ bullseye && $BRANCH == current ]]; then
  341. [[ ${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}"
  342. fi
  343. if [[ ${BOARD} =~ orangepi4|orangepi4-lts|orangepi800 && $RELEASE =~ jammy && $BRANCH == next ]]; then
  344. [[ ${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}"
  345. fi
  346. call_extension_method "fetch_sources_tools" <<- 'FETCH_SOURCES_TOOLS'
  347. *fetch host-side sources needed for tools and build*
  348. Run early to fetch_from_repo or otherwise obtain sources for needed tools.
  349. FETCH_SOURCES_TOOLS
  350. call_extension_method "build_host_tools" <<- 'BUILD_HOST_TOOLS'
  351. *build needed tools for the build, host-side*
  352. After sources are fetched, build host-side tools needed for the build.
  353. BUILD_HOST_TOOLS
  354. if [[ ${BOARDFAMILY} == "rockchip-rk3588" ]]; then
  355. local rkbin_url="https://github.com/orangepi-xunlong/rk-rootfs-build/raw/rkbin/rk35"
  356. wget -nc -P ${EXTER}/cache/sources/rkbin-tools/rk35/ ${rkbin_url}/rk3588_bl31_v1.45_20240422.elf
  357. fi
  358. fi
  359. for option in $(tr ',' ' ' <<< "$CLEAN_LEVEL"); do
  360. [[ $option != sources ]] && cleaning "$option"
  361. done
  362. # Compile u-boot if packed .deb does not exist or use the one from Orange Pi
  363. if [[ $BUILD_OPT == u-boot || $BUILD_OPT == image ]]; then
  364. if [[ ! -f "${DEB_STORAGE}"/u-boot/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb ]]; then
  365. [[ -n "${ATFSOURCE}" && "${REPOSITORY_INSTALL}" != *u-boot* ]] && compile_atf
  366. [[ ${REPOSITORY_INSTALL} != *u-boot* ]] && compile_uboot
  367. fi
  368. if [[ $BUILD_OPT == "u-boot" ]]; then
  369. unset BUILD_MINIMAL BUILD_DESKTOP COMPRESS_OUTPUTIMAGE
  370. display_alert "U-boot build done" "@host" "info"
  371. display_alert "Target directory" "${DEB_STORAGE}/u-boot" "info"
  372. display_alert "File name" "${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb" "info"
  373. fi
  374. fi
  375. # Compile kernel if packed .deb does not exist or use the one from Orange Pi
  376. if [[ $BUILD_OPT == kernel || $BUILD_OPT == image ]]; then
  377. if [[ ! -f ${DEB_STORAGE}/${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb ]]; then
  378. KDEB_CHANGELOG_DIST=$RELEASE
  379. [[ "${REPOSITORY_INSTALL}" != *kernel* ]] && compile_kernel
  380. fi
  381. if [[ $BUILD_OPT == "kernel" ]]; then
  382. unset BUILD_MINIMAL BUILD_DESKTOP COMPRESS_OUTPUTIMAGE
  383. display_alert "Kernel build done" "@host" "info"
  384. display_alert "Target directory" "${DEB_STORAGE}/" "info"
  385. display_alert "File name" "${CHOSEN_KERNEL}_${REVISION}_${ARCH}.deb" "info"
  386. fi
  387. fi
  388. if [[ $BUILD_OPT == rootfs || $BUILD_OPT == image ]]; then
  389. # Compile orangepi-config if packed .deb does not exist or use the one from Orange Pi
  390. if [[ ! -f ${DEB_STORAGE}/orangepi-config_${REVISION}_all.deb ]]; then
  391. [[ "${REPOSITORY_INSTALL}" != *orangepi-config* ]] && compile_orangepi-config
  392. fi
  393. # Compile orangepi-zsh if packed .deb does not exist or use the one from repository
  394. if [[ ! -f ${DEB_STORAGE}/orangepi-zsh_${REVISION}_all.deb ]]; then
  395. [[ "${REPOSITORY_INSTALL}" != *orangepi-zsh* ]] && compile_orangepi-zsh
  396. fi
  397. # Compile plymouth-theme-orangepi if packed .deb does not exist or use the one from repository
  398. if [[ ! -f ${DEB_STORAGE}/plymouth-theme-orangepi_${REVISION}_all.deb ]]; then
  399. [[ "${REPOSITORY_INSTALL}" != *plymouth-theme-orangepi* ]] && compile_plymouth-theme-orangepi
  400. fi
  401. # Compile orangepi-firmware if packed .deb does not exist or use the one from repository
  402. if [[ "${REPOSITORY_INSTALL}" != *orangepi-firmware* ]]; then
  403. if ! ls "${DEB_STORAGE}/orangepi-firmware_${REVISION}_all.deb" 1> /dev/null 2>&1; then
  404. FULL=""
  405. REPLACE="-full"
  406. compile_firmware
  407. fi
  408. #if ! ls "${DEB_STORAGE}/orangepi-firmware-full_${REVISION}_all.deb" 1> /dev/null 2>&1; then
  409. #FULL="-full"
  410. #REPLACE=""
  411. #compile_firmware
  412. #fi
  413. fi
  414. overlayfs_wrapper "cleanup"
  415. # create board support package
  416. [[ -n $RELEASE && ! -f ${DEB_STORAGE}/$RELEASE/${BSP_CLI_PACKAGE_FULLNAME}.deb ]] && create_board_package
  417. # create desktop package
  418. #[[ -n $RELEASE && $DESKTOP_ENVIRONMENT && ! -f ${DEB_STORAGE}/$RELEASE/${CHOSEN_DESKTOP}_${REVISION}_all.deb ]] && create_desktop_package
  419. #[[ -n $RELEASE && $DESKTOP_ENVIRONMENT && ! -f ${DEB_STORAGE}/${RELEASE}/${BSP_DESKTOP_PACKAGE_FULLNAME}.deb ]] && create_bsp_desktop_package
  420. [[ -n $RELEASE && $DESKTOP_ENVIRONMENT ]] && create_desktop_package
  421. [[ -n $RELEASE && $DESKTOP_ENVIRONMENT ]] && create_bsp_desktop_package
  422. # build additional packages
  423. [[ $EXTERNAL_NEW == compile ]] && chroot_build_packages
  424. [[ $BSP_BUILD != yes ]] && debootstrap_ng
  425. fi
  426. # hook for function to run after build, i.e. to change owner of $SRC
  427. # NOTE: this will run only if there were no errors during build process
  428. [[ $(type -t run_after_build) == function ]] && run_after_build || true
  429. end=$(date +%s)
  430. runtime=$(((end-start)/60))
  431. display_alert "Runtime" "$runtime min" "info"
  432. # Make it easy to repeat build by displaying build options used
  433. [ "$(systemd-detect-virt)" == 'docker' ] && BUILD_CONFIG='docker'
  434. display_alert "Repeat Build Options" "sudo ./build.sh ${BUILD_CONFIG} BOARD=${BOARD} BRANCH=${BRANCH} \
  435. $([[ -n $BUILD_OPT ]] && echo "BUILD_OPT=${BUILD_OPT} ")\
  436. $([[ -n $RELEASE ]] && echo "RELEASE=${RELEASE} ")\
  437. $([[ -n $BUILD_MINIMAL ]] && echo "BUILD_MINIMAL=${BUILD_MINIMAL} ")\
  438. $([[ -n $BUILD_DESKTOP ]] && echo "BUILD_DESKTOP=${BUILD_DESKTOP} ")\
  439. $([[ -n $KERNEL_CONFIGURE ]] && echo "KERNEL_CONFIGURE=${KERNEL_CONFIGURE} ")\
  440. $([[ -n $DESKTOP_ENVIRONMENT ]] && echo "DESKTOP_ENVIRONMENT=${DESKTOP_ENVIRONMENT} ")\
  441. $([[ -n $DESKTOP_ENVIRONMENT_CONFIG_NAME ]] && echo "DESKTOP_ENVIRONMENT_CONFIG_NAME=${DESKTOP_ENVIRONMENT_CONFIG_NAME} ")\
  442. $([[ -n $DESKTOP_APPGROUPS_SELECTED ]] && echo "DESKTOP_APPGROUPS_SELECTED=\"${DESKTOP_APPGROUPS_SELECTED}\" ")\
  443. $([[ -n $DESKTOP_APT_FLAGS_SELECTED ]] && echo "DESKTOP_APT_FLAGS_SELECTED=\"${DESKTOP_APT_FLAGS_SELECTED}\" ")\
  444. $([[ -n $COMPRESS_OUTPUTIMAGE ]] && echo "COMPRESS_OUTPUTIMAGE=${COMPRESS_OUTPUTIMAGE} ")\
  445. " "ext"
  446. } # end of do_default()
  447. if [[ -z $1 ]]; then
  448. do_default
  449. else
  450. eval "$@"
  451. fi