diff --git a/lib/functions/compilation/packages/firmware-deb.sh b/lib/functions/compilation/packages/firmware-deb.sh index 27707ff446..a5b27e5e8b 100644 --- a/lib/functions/compilation/packages/firmware-deb.sh +++ b/lib/functions/compilation/packages/firmware-deb.sh @@ -1,34 +1,56 @@ -compile_firmware() { - display_alert "Merging and packaging linux firmware" "@host" "info" +function compile_firmware_light_and_possibly_full() { + if [[ "${INSTALL_ARMBIAN_FIRMWARE:-yes}" == "yes" ]]; then # Build firmware by default. + # Build the "light" version of firmware packages, with no conditions. + FULL="" REPLACE="-full" LOG_SECTION="compile_firmware" do_with_logging compile_firmware - local firmwaretempdir plugin_dir + # Now, we'll build the "full" version of firmware packages, if: + # 1) We've CI==true, or stdout is not a terminal, or + # 2) We've been asked to install it for the board being built, BOARD_FIRMWARE_INSTALL="-full" + if [[ "${CI}" == "true" || ! -t 1 || "${BOARD_FIRMWARE_INSTALL}" == "-full" ]]; then + # Build the full version of firmware package + FULL="-full" REPLACE="" LOG_SECTION="compile_firmware_full" do_with_logging compile_firmware + else + display_alert "Skipping full firmware package build" "" "info" + fi + fi + return 0 +} + +function compile_firmware() { + display_alert "Merging and packaging linux firmware" "@host --> firmware${FULL}" "info" + + local firmwaretempdir fw_dir firmwaretempdir=$(mktemp -d) # subject to TMPDIR/WORKDIR, so is protected by single/common error trapmanager to clean-up. chmod 700 "${firmwaretempdir}" - plugin_dir="armbian-firmware${FULL}" - mkdir -p "${firmwaretempdir}/${plugin_dir}/lib/firmware" + fw_dir="armbian-firmware${FULL}" + mkdir -p "${firmwaretempdir}/${fw_dir}/lib/firmware" local ARMBIAN_FIRMWARE_GIT_SOURCE="${ARMBIAN_FIRMWARE_GIT_SOURCE:-"https://github.com/armbian/firmware"}" local ARMBIAN_FIRMWARE_GIT_BRANCH="${ARMBIAN_FIRMWARE_GIT_BRANCH:-"master"}" + # Fetch Armbian firmware from git. fetch_from_repo "${ARMBIAN_FIRMWARE_GIT_SOURCE}" "armbian-firmware-git" "branch:${ARMBIAN_FIRMWARE_GIT_BRANCH}" if [[ -n $FULL ]]; then + # Fetch kernel firmware from git. This is huge... fetch_from_repo "$MAINLINE_FIRMWARE_SOURCE" "linux-firmware-git" "branch:main" - + # @TODO: rpardini: what is this thing with hardlinks? why? # cp : create hardlinks - run_host_command_logged cp -af --reflink=auto "${SRC}/cache/sources/linux-firmware-git/*" "${firmwaretempdir}/${plugin_dir}/lib/firmware/" + run_host_command_logged cp -af --reflink=auto "${SRC}/cache/sources/linux-firmware-git/*" "${firmwaretempdir}/${fw_dir}/lib/firmware/" # cp : create hardlinks for ath11k WCN685x hw2.1 firmware since they are using the same firmware with hw2.0 - run_host_command_logged cp -af --reflink=auto "${firmwaretempdir}/${plugin_dir}/lib/firmware/ath11k/WCN6855/hw2.0/" "${firmwaretempdir}/${plugin_dir}/lib/firmware/ath11k/WCN6855/hw2.1/" - fi - - # overlay Armbian's firmware on top of the mainline firmware - run_host_command_logged cp -af --reflink=auto "${SRC}/cache/sources/armbian-firmware-git/*" "${firmwaretempdir}/${plugin_dir}/lib/firmware/" + run_host_command_logged cp -af --reflink=auto "${firmwaretempdir}/${fw_dir}/lib/firmware/ath11k/WCN6855/hw2.0/" "${firmwaretempdir}/${fw_dir}/lib/firmware/ath11k/WCN6855/hw2.1/" - rm -rf "${firmwaretempdir}/${plugin_dir}"/lib/firmware/.git # @TODO: would have been better waste I/O putting in there - cd "${firmwaretempdir}/${plugin_dir}" || exit_with_error "can't change directory" + rm -rf "${firmwaretempdir}/${fw_dir}"/lib/firmware/.git # @TODO: would have been better not to waste I/O putting in there to begin with. + fi + + # overlay Armbian's firmware on top of the mainline firmware + run_host_command_logged cp -af --reflink=auto "${SRC}/cache/sources/armbian-firmware-git/*" "${firmwaretempdir}/${fw_dir}/lib/firmware/" + + rm -rf "${firmwaretempdir}/${fw_dir}"/lib/firmware/.git # @TODO: would have been better not to waste I/O putting in there to begin with. + cd "${firmwaretempdir}/${fw_dir}" || exit_with_error "can't change directory" # set up control file mkdir -p DEBIAN diff --git a/lib/functions/compilation/packages/utils-dpkgdeb.sh b/lib/functions/compilation/packages/utils-dpkgdeb.sh new file mode 100644 index 0000000000..d77ba29386 --- /dev/null +++ b/lib/functions/compilation/packages/utils-dpkgdeb.sh @@ -0,0 +1,22 @@ +# for deb building. +function fakeroot_dpkg_deb_build() { + display_alert "Building .deb package" "$*" "debug" + + declare -a orig_args=("$@") + # find the first non-option argument + declare first_arg + for first_arg in "${orig_args[@]}"; do + if [[ "${first_arg}" != -* ]]; then + break + fi + done + + if [[ ! -d "${first_arg}" ]]; then + exit_with_error "fakeroot_dpkg_deb_build: can't find source package directory: ${first_arg}" + fi + + # Show the total human size of the source package directory. + display_alert "Source package size" "${first_arg}: $(du -sh "${first_arg}" | cut -f1)" "debug" + + run_host_command_logged_raw fakeroot dpkg-deb -b "-Z${DEB_COMPRESS}" "${orig_args[@]}" +} diff --git a/lib/functions/logging/runners.sh b/lib/functions/logging/runners.sh index d2906f096a..8e5dbe78dd 100644 --- a/lib/functions/logging/runners.sh +++ b/lib/functions/logging/runners.sh @@ -122,12 +122,6 @@ function chroot_custom() { raw_command="$*" raw_extra="chroot_custom" TMPDIR="" run_host_command_logged_raw chroot "${target}" /bin/bash -e -o pipefail -c "$*" } -# for deb building. -function fakeroot_dpkg_deb_build() { - display_alert "Building .deb package" "$(basename "${3:-${2:-${1}}}" || true)" "debug" - run_host_command_logged_raw fakeroot dpkg-deb -b "-Z${DEB_COMPRESS}" "$@" -} - # for long-running, host-side expanded bash invocations. # the user gets a pv-based spinner based on the number of lines that flows to stdout (log messages). # the raw version is already redirect stderr to stdout, and we'll be running under do_with_logging, diff --git a/lib/functions/main/default-build.sh b/lib/functions/main/default-build.sh index e477629b41..868e21c043 100644 --- a/lib/functions/main/default-build.sh +++ b/lib/functions/main/default-build.sh @@ -146,14 +146,7 @@ function main_default_build_single() { if ! ls "${DEB_STORAGE}/armbian-firmware_${REVISION}_all.deb" 1> /dev/null 2>&1 || ! ls "${DEB_STORAGE}/armbian-firmware-full_${REVISION}_all.deb" 1> /dev/null 2>&1; then if [[ "${REPOSITORY_INSTALL}" != *armbian-firmware* ]]; then - if [[ "${INSTALL_ARMBIAN_FIRMWARE:-yes}" == "yes" ]]; then # Build firmware by default. - # Build the light version of firmware package - FULL="" REPLACE="-full" LOG_SECTION="compile_firmware" do_with_logging compile_firmware - - # Build the full version of firmware package - FULL="-full" REPLACE="" LOG_SECTION="compile_firmware_full" do_with_logging compile_firmware - - fi + compile_firmware_light_and_possibly_full # this has its own logging sections fi fi diff --git a/lib/library-functions.sh b/lib/library-functions.sh index 8d6ff1a0ab..51a7772fab 100644 --- a/lib/library-functions.sh +++ b/lib/library-functions.sh @@ -244,6 +244,15 @@ set -o errexit ## set -e : exit the script if any statement returns a non-true # shellcheck source=lib/functions/compilation/packages/plymouth-deb.sh source "${SRC}"/lib/functions/compilation/packages/plymouth-deb.sh +# no errors tolerated. invoked before each sourced file to make sure. +#set -o pipefail # trace ERR through pipes - will be enabled "soon" +#set -o nounset ## set -u : exit the script if you try to use an uninitialised variable - one day will be enabled +set -o errtrace # trace ERR through - enabled +set -o errexit ## set -e : exit the script if any statement returns a non-true return value - enabled +### lib/functions/compilation/packages/utils-dpkgdeb.sh +# shellcheck source=lib/functions/compilation/packages/utils-dpkgdeb.sh +source "${SRC}"/lib/functions/compilation/packages/utils-dpkgdeb.sh + # no errors tolerated. invoked before each sourced file to make sure. #set -o pipefail # trace ERR through pipes - will be enabled "soon" #set -o nounset ## set -u : exit the script if you try to use an uninitialised variable - one day will be enabled