firmware-deb.sh 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env bash
  2. #
  3. # SPDX-License-Identifier: GPL-2.0
  4. #
  5. # Copyright (c) 2013-2023 Igor Pecovnik, igor@armbian.com
  6. #
  7. # This file is a part of the Armbian Build Framework
  8. # https://github.com/armbian/build/
  9. function compile_firmware() {
  10. : "${artifact_version:?artifact_version is not set}"
  11. display_alert "Merging and packaging linux firmware" "@host --> firmware${FULL}" "info"
  12. declare cleanup_id="" fw_temp_dir=""
  13. prepare_temp_dir_in_workdir_and_schedule_cleanup "deb-firmware${FULL}" cleanup_id fw_temp_dir # namerefs
  14. declare fw_dir="armbian-firmware${FULL}"
  15. mkdir -p "${fw_temp_dir}/${fw_dir}/lib/firmware"
  16. local ARMBIAN_FIRMWARE_GIT_SOURCE="${ARMBIAN_FIRMWARE_GIT_SOURCE:-"https://github.com/armbian/firmware"}"
  17. local ARMBIAN_FIRMWARE_GIT_BRANCH="${ARMBIAN_FIRMWARE_GIT_BRANCH:-"master"}"
  18. # Fetch Armbian firmware from git.
  19. declare fetched_revision
  20. do_checkout="no" fetch_from_repo "${ARMBIAN_FIRMWARE_GIT_SOURCE}" "armbian-firmware-git" "branch:${ARMBIAN_FIRMWARE_GIT_BRANCH}"
  21. declare -r armbian_firmware_git_sha1="${fetched_revision}"
  22. declare extra_conflicts_comma=""
  23. if [[ -n $FULL ]]; then
  24. # Fetch kernel firmware from git. This is large, but we don't have two copies of it anymore. So more manageable.
  25. declare fetched_revision
  26. do_checkout="no" fetch_from_repo "$MAINLINE_FIRMWARE_SOURCE" "linux-firmware-git" "branch:main"
  27. declare -r mainline_firmware_git_sha1="${fetched_revision}"
  28. # use git archive to export the ${mainline_firmware_git_sha1} revision into "${fw_temp_dir}/${fw_dir}/lib/firmware/"
  29. run_host_command_logged git -C "${SRC}/cache/sources/linux-firmware-git" archive --format=tar "${mainline_firmware_git_sha1}" "|" tar -C "${fw_temp_dir}/${fw_dir}/lib/firmware/" -xf -
  30. # Full version conflicts with more stuff, of course.
  31. extra_conflicts_comma=",amd64-microcode,intel-microcode"
  32. # @TODO: rpardini: disabled, this is not the place to do this; move to extension/bsp/whatever
  33. # cp : create hardlinks for ath11k WCN685x hw2.1 firmware since they are using the same firmware with hw2.0
  34. # run_host_command_logged cp -af --reflink=auto "${fw_temp_dir}/${fw_dir}/lib/firmware/ath11k/WCN6855/hw2.0/" "${fw_temp_dir}/${fw_dir}/lib/firmware/ath11k/WCN6855/hw2.1/"
  35. fi
  36. # Armbian firmware; this overwrites anything in the mainline firmware repo (if that was included, in the full version only)
  37. run_host_command_logged git -C "${SRC}/cache/sources/armbian-firmware-git" archive --format=tar "${armbian_firmware_git_sha1}" "|" tar -C "${fw_temp_dir}/${fw_dir}/lib/firmware/" -xf -
  38. # Show the size of the firmware directory in a tree if debugging
  39. if [[ "${SHOW_DEBUG}" == "yes" ]]; then
  40. run_host_command_logged tree -C --du -h -L 1 "${fw_temp_dir}/${fw_dir}"/lib/firmware "|| true" # do not fail
  41. fi
  42. cd "${fw_temp_dir}/${fw_dir}" || exit_with_error "can't change directory"
  43. # set up control file
  44. mkdir -p DEBIAN
  45. # @TODO: rpardini: this needs Conflicts: with the standard Ubuntu/Debian linux-firmware packages and other firmware pkgs in Debian
  46. cat <<- END > DEBIAN/control
  47. Package: armbian-firmware${FULL}
  48. Version: ${artifact_version}
  49. Architecture: all
  50. Maintainer: $MAINTAINER <$MAINTAINERMAIL>
  51. Installed-Size: 1
  52. Conflicts: linux-firmware, firmware-brcm80211, firmware-ralink, firmware-samsung, firmware-realtek, armbian-firmware${REPLACE}${extra_conflicts_comma}
  53. Provides: linux-firmware, firmware-brcm80211, firmware-ralink, firmware-samsung, firmware-realtek, armbian-firmware${REPLACE}${extra_conflicts_comma}
  54. Section: kernel
  55. Priority: optional
  56. Description: Armbian - Linux firmware${FULL}
  57. END
  58. cd "${fw_temp_dir}" || exit_with_error "can't change directory"
  59. # package, directly to DEB_STORAGE; full version might be very big for tmpfs.
  60. display_alert "Building firmware package" "armbian-firmware${FULL}" "info"
  61. fakeroot_dpkg_deb_build "armbian-firmware${FULL}" "${DEB_STORAGE}"
  62. done_with_temp_dir "${cleanup_id}" # changes cwd to "${SRC}" and fires the cleanup function early
  63. }