first commit
This commit is contained in:
50
external/extensions/detect-unused-extensions.sh
vendored
Executable file
50
external/extensions/detect-unused-extensions.sh
vendored
Executable file
@@ -0,0 +1,50 @@
|
||||
## Configuration
|
||||
export LOG_ALL_HOOK_TRACES=no # Should we log all hook function traces to stdout? (no, or level: wrn info)
|
||||
|
||||
## Hooks
|
||||
|
||||
# A honeypot wishful hooking. To make sure the whole thing works.
|
||||
# This is exactly the kind of hooking this extension is meant to detect.
|
||||
# This will never run, and should be detected below, but is handled specially and ignored.
|
||||
# Note: this will never run, since we (hopefully) don't have a hook_point called 'wishful_hooking_example'.
|
||||
function wishful_hooking_example__this_will_never_run() {
|
||||
echo "WISHFUL HOOKING -- this will never run. I promise."
|
||||
}
|
||||
|
||||
# Run super late, hopefully at the last possible moment.
|
||||
function extension_metadata_ready__999_detect_wishful_hooking() {
|
||||
display_alert "Checking extensions and hooks for uncalled hook points"
|
||||
declare -i found_honeypot_function=0
|
||||
|
||||
# Loop over the defined functions' keys. Find the info about the call. If not found, warn the user.
|
||||
# shellcheck disable=SC2154 # hook-exported variable
|
||||
for one_defined_function in ${!defined_hook_point_functions[*]}; do
|
||||
local source_info defined_info line_info
|
||||
defined_info="${defined_hook_point_functions["${one_defined_function}"]}"
|
||||
source_info="${hook_point_function_trace_sources["${one_defined_function}"]}"
|
||||
line_info="${hook_point_function_trace_lines["${one_defined_function}"]}"
|
||||
stack="$(get_extension_hook_stracktrace "${source_info}" "${line_info}")"
|
||||
if [[ "$source_info" != "" ]]; then
|
||||
# log to debug log. it's reassuring.
|
||||
echo "\$\$\$ Hook function stacktrace for '${one_defined_function}': '${stack}' (${defined_info})" >>"${EXTENSION_MANAGER_LOG_FILE}"
|
||||
if [[ "${LOG_ALL_HOOK_TRACES}" != "no" ]]; then
|
||||
display_alert "Hook function stacktrace for '${one_defined_function}'" "${stack}" "${LOG_ALL_HOOK_TRACES}"
|
||||
fi
|
||||
continue # found a caller, move on.
|
||||
fi
|
||||
|
||||
# special handling for the honeypot function. it is supposed to be always detected as uncalled.
|
||||
if [[ "${one_defined_function}" == "wishful_hooking_example__this_will_never_run" ]]; then
|
||||
# we expect this wishful hooking, it is done on purpose below, to make sure this code works.
|
||||
found_honeypot_function=1
|
||||
else
|
||||
# unexpected wishful hooking. Log and wrn the user.
|
||||
echo "\$\$\$ Wishful hooking detected" "Function '${one_defined_function}' is defined (${defined_info}) but never called by the build." >>"${EXTENSION_MANAGER_LOG_FILE}"
|
||||
display_alert "Wishful hooking detected" "Function '${one_defined_function}' is defined (${defined_info}) but never called by the build." "wrn"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $found_honeypot_function -lt 1 ]]; then
|
||||
display_alert "Wishful hook DETECTION FAILED" "detect-wishful-hooking is not working. Good chance the environment vars are corrupted. Avoid child shells. Sorry." "wrn" | tee -a "${EXTENSION_MANAGER_LOG_FILE}"
|
||||
fi
|
||||
}
|
||||
122
external/extensions/flash-kernel.sh
vendored
Executable file
122
external/extensions/flash-kernel.sh
vendored
Executable file
@@ -0,0 +1,122 @@
|
||||
# This runs *after* user_config. Don't change anything not coming from other variables or meant to be configured by the user.
|
||||
function extension_prepare_config__prepare_flash_kernel() {
|
||||
# Configuration defaults, or lack thereof.
|
||||
export FK__TOOL_PACKAGE="${FK__TOOL_PACKAGE:-flash-kernel}"
|
||||
export FK__PUBLISHED_KERNEL_VERSION="${FK__PUBLISHED_KERNEL_VERSION:-undefined-flash-kernel-version}"
|
||||
export FK__EXTRA_PACKAGES="${FK__EXTRA_PACKAGES:-undefined-flash-kernel-kernel-package}"
|
||||
export FK__KERNEL_PACKAGES="${FK__KERNEL_PACKAGES:-}"
|
||||
export FK__MACHINE_MODEL="${FK__MACHINE_MODEL:-Undefined Flash-Kernel Machine}"
|
||||
|
||||
# Override certain variables. A case of "this extension knows better and modifies user configurable stuff".
|
||||
export BOOTCONFIG="none" # To try and convince lib/ to not build or install u-boot.
|
||||
unset BOOTSOURCE # To try and convince lib/ to not build or install u-boot.
|
||||
export UEFISIZE=256 # in MiB. Not really UEFI, but partition layout is the same.
|
||||
export BOOTSIZE=0 # No separate /boot, flash-kernel will "flash" the kernel+initrd to the firmware part.
|
||||
export UEFI_MOUNT_POINT="/boot/firmware" # mount uefi partition at /boot/firmware
|
||||
export CLOUD_INIT_CONFIG_LOCATION="/boot/firmware" # use /boot/firmware for cloud-init as well
|
||||
export VER="${FK__PUBLISHED_KERNEL_VERSION}" # For the VERSION
|
||||
export EXTRA_BSP_NAME="${EXTRA_BSP_NAME}-fk${FK__PUBLISHED_KERNEL_VERSION}" # Unique bsp name.
|
||||
echo "-- starting" >"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log # Zero out the log for this extension.
|
||||
}
|
||||
|
||||
function post_install_kernel_debs__install_kernel_and_flash_packages() {
|
||||
export INSTALL_ARMBIAN_FIRMWARE="no" # Disable Armbian-firmware install, which would happen after this method.
|
||||
|
||||
if [[ "${FK__EXTRA_PACKAGES}" != "" ]]; then
|
||||
display_alert "Installing flash-kernel extra packages" "${FK__EXTRA_PACKAGES}"
|
||||
echo "-- install extra pkgs" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log
|
||||
chroot "${SDCARD}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get ${APT_EXTRA_DIST_PARAMS} -yqq --no-install-recommends install ${FK__EXTRA_PACKAGES}" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log || {
|
||||
display_alert "Failed to install flash-kernel's extra packages." "${EXTENSION}" "err"
|
||||
exit 28
|
||||
}
|
||||
fi
|
||||
|
||||
if [[ "${FK__KERNEL_PACKAGES}" != "" ]]; then
|
||||
display_alert "Installing flash-kernel kernel packages" "${FK__KERNEL_PACKAGES}"
|
||||
echo "-- install kernel pkgs" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log
|
||||
chroot "${SDCARD}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get ${APT_EXTRA_DIST_PARAMS} -yqq --no-install-recommends install ${FK__KERNEL_PACKAGES}" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log || {
|
||||
display_alert "Failed to install flash-kernel's kernel packages." "${EXTENSION}" "err"
|
||||
exit 28
|
||||
}
|
||||
fi
|
||||
|
||||
display_alert "Installing flash-kernel package" "${FK__TOOL_PACKAGE}"
|
||||
# Create a fake /sys/firmware/efi directory so that flash-kernel does not try to do anything when installed
|
||||
# @TODO: this might or not work after flash-kernel 3.104 or later
|
||||
umount "${SDCARD}"/sys
|
||||
mkdir -p "${SDCARD}"/sys/firmware/efi
|
||||
|
||||
echo "-- install flash-kernel package" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log
|
||||
chroot "${SDCARD}" /bin/bash -c "DEBIAN_FRONTEND=noninteractive apt-get ${APT_EXTRA_DIST_PARAMS} -yqq --no-install-recommends install ${FK__TOOL_PACKAGE}" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log || {
|
||||
display_alert "Failed to install flash-kernel package." "${EXTENSION}" "err"
|
||||
exit 28
|
||||
}
|
||||
|
||||
# Remove fake /sys/firmware (/efi) directory
|
||||
rm -rf "${SDCARD}"/sys/firmware
|
||||
}
|
||||
|
||||
# @TODO: extract u-boot into an extension, so that core bsps don't have this stuff in there to begin with.
|
||||
# @TODO: this code is duplicated in grub.sh extension, so another reason to refactor the root of the evil
|
||||
post_family_tweaks_bsp__remove_uboot_flash_kernel() {
|
||||
display_alert "Removing uboot from BSP" "${EXTENSION}" "info"
|
||||
# Simply remove everything with 'uboot' or 'u-boot' in their filenames from the BSP package.
|
||||
# shellcheck disable=SC2154 # $destination is the target dir of the bsp building function
|
||||
find "$destination" -type f | grep -e "uboot" -e "u-boot" | xargs rm
|
||||
}
|
||||
|
||||
pre_umount_final_image__remove_uboot_initramfs_hook_flash_kernel() {
|
||||
# even if BSP still contained this (cached .deb), make sure by removing from ${MOUNT}
|
||||
[[ -f "$MOUNT"/etc/initramfs/post-update.d/99-uboot ]] && rm -v "$MOUNT"/etc/initramfs/post-update.d/99-uboot
|
||||
}
|
||||
|
||||
function pre_update_initramfs__setup_flash_kernel() {
|
||||
local chroot_target=$MOUNT
|
||||
cp /usr/bin/"$QEMU_BINARY" "$chroot_target"/usr/bin/
|
||||
mount_chroot "$chroot_target/" # this already handles /boot/firmware which is required for it to work.
|
||||
# hack, umount the chroot's /sys, otherwise flash-kernel tries to EFI flash due to the build host (!) being EFI
|
||||
umount "$chroot_target/sys"
|
||||
|
||||
echo "-- flash-kernel disabling hooks" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log
|
||||
chroot "$chroot_target" /bin/bash -c "chmod -v -x /etc/kernel/postinst.d/initramfs-tools" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log 2>&1
|
||||
chroot "$chroot_target" /bin/bash -c "chmod -v -x /etc/initramfs/post-update.d/flash-kernel" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log 2>&1
|
||||
|
||||
export FIRMWARE_DIR="${MOUNT}"/boot/firmware
|
||||
call_extension_method "pre_initramfs_flash_kernel" <<-'PRE_INITRAMFS_FLASH_KERNEL'
|
||||
*prepare to update-initramfs before flashing kernel via flash_kernel*
|
||||
A good spot to write firmware config to ${FIRMWARE_DIR} (/boot/firmware) before flash-kernel actually runs.
|
||||
PRE_INITRAMFS_FLASH_KERNEL
|
||||
|
||||
local update_initramfs_cmd="update-initramfs -c -k all"
|
||||
display_alert "Updating flash-kernel initramfs..." "$update_initramfs_cmd" ""
|
||||
echo "-- flash-kernel initramfs" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log
|
||||
chroot "$chroot_target" /bin/bash -c "$update_initramfs_cmd" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log 2>&1 || {
|
||||
display_alert "Failed to run '$update_initramfs_cmd'" "Check ${DEST}/"${LOG_SUBPATH}"/flash-kernel.log" "err"
|
||||
exit 29
|
||||
}
|
||||
|
||||
call_extension_method "pre_flash_kernel" <<-'PRE_FLASH_KERNEL'
|
||||
*run before running flash-kernel*
|
||||
Each board might need different stuff for flash-kernel to work. Implement it here.
|
||||
Write to `${MOUNT}`, eg: `"${MOUNT}"/etc/flash-kernel`
|
||||
PRE_FLASH_KERNEL
|
||||
|
||||
local flash_kernel_cmd="flash-kernel --machine '${FK__MACHINE_MODEL}'"
|
||||
display_alert "flash-kernel" "${FK__MACHINE_MODEL}" "info"
|
||||
echo "-- flash-kernel itself" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log
|
||||
chroot "$chroot_target" /bin/bash -c "${flash_kernel_cmd}" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log 2>&1 || {
|
||||
display_alert "Failed to run '${flash_kernel_cmd}'" "Check ${DEST}/"${LOG_SUBPATH}"/flash-kernel.log" "err"
|
||||
exit 29
|
||||
}
|
||||
|
||||
display_alert "Re-enabling" "initramfs-tools/flash-kernel hook for kernel"
|
||||
echo "-- flash-kernel re-enabling hooks" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log
|
||||
chroot "$chroot_target" /bin/bash -c "chmod -v +x /etc/kernel/postinst.d/initramfs-tools" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log 2>&1
|
||||
chroot "$chroot_target" /bin/bash -c "chmod -v +x /etc/initramfs/post-update.d/flash-kernel" >>"${DEST}"/"${LOG_SUBPATH}"/flash-kernel.log 2>&1
|
||||
|
||||
umount_chroot "$chroot_target/"
|
||||
rm "$chroot_target"/usr/bin/"$QEMU_BINARY"
|
||||
|
||||
display_alert "Disabling Armbian-core update_initramfs, was already done above." "${EXTENSION}"
|
||||
unset KERNELSOURCE # ugly. sorry. we'll have better mechanism for this soon. this is tested at lib/debootstrap.sh:844
|
||||
}
|
||||
126
external/extensions/gen-sample-extension-docs.sh
vendored
Executable file
126
external/extensions/gen-sample-extension-docs.sh
vendored
Executable file
@@ -0,0 +1,126 @@
|
||||
## Hooks
|
||||
function extension_metadata_ready__499_display_docs_generation_start_info() {
|
||||
display_alert "Generating hook documentation and sample extension"
|
||||
}
|
||||
|
||||
function extension_metadata_ready__docs_markdown() {
|
||||
generate_markdown_docs_to_stdout >"${DEST}/"${LOG_SUBPATH}"/hooks.auto.docs.md"
|
||||
}
|
||||
|
||||
function extension_metadata_ready__docs_sample_extension() {
|
||||
mkdir -p "${SRC}/userpatches/extensions"
|
||||
generate_sample_extension_to_stdout >"${SRC}/userpatches/extensions/sample-extension.sh"
|
||||
}
|
||||
|
||||
## Internal functions
|
||||
|
||||
### Common stuff
|
||||
function read_common_data() {
|
||||
export HOOK_POINT_CALLS_COUNT=$(wc -l <"${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt")
|
||||
export HOOK_POINT_CALLS_UNIQUE_COUNT=$(sort <"${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt" | uniq | wc -l)
|
||||
export HOOK_POINTS_WITH_MULTIPLE_CALLS=""
|
||||
|
||||
# Read the hook_points (main, official names) from the hook point ordering file.
|
||||
export ALL_HOOK_POINT_CALLS=$(xargs echo -n <"${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt")
|
||||
}
|
||||
|
||||
function loop_over_hook_points_and_call() {
|
||||
local callback="$1"
|
||||
HOOK_POINT_COUNTER=0
|
||||
for one_hook_point in ${ALL_HOOK_POINT_CALLS}; do
|
||||
export HOOK_POINT_COUNTER=$((HOOK_POINT_COUNTER + 1))
|
||||
export HOOK_POINT="${one_hook_point}"
|
||||
export MARKDOWN_HEAD="$(head -1 "${EXTENSION_MANAGER_TMP_DIR}/${one_hook_point}.orig.md")"
|
||||
export MARKDOWN_BODY="$(tail -n +2 "${EXTENSION_MANAGER_TMP_DIR}/${one_hook_point}.orig.md")"
|
||||
export COMPATIBILITY_NAMES="$(xargs echo -n <"${EXTENSION_MANAGER_TMP_DIR}/${one_hook_point}.compat")"
|
||||
${callback}
|
||||
done
|
||||
}
|
||||
|
||||
## Markdown stuff
|
||||
function generate_markdown_docs_to_stdout() {
|
||||
read_common_data
|
||||
cat <<MASTER_HEADER
|
||||
# Armbian build system extensibility documentation
|
||||
- This documentation is auto-generated.
|
||||
MASTER_HEADER
|
||||
|
||||
[[ $HOOK_POINT_CALLS_COUNT -gt $HOOK_POINT_CALLS_UNIQUE_COUNT ]] && {
|
||||
# Some hook points were called multiple times, determine which.
|
||||
HOOK_POINTS_WITH_MULTIPLE_CALLS=$(comm -13 <(sort <"${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt" | uniq) <(sort <"${EXTENSION_MANAGER_TMP_DIR}/hook_point_calls.txt") | sort | uniq | xargs echo -n)
|
||||
|
||||
cat <<MULTIPLE_CALLS_WARNING
|
||||
- *Important:* The following hook points where called multiple times during the documentation generation. This can be indicative of a bug in the build system. Please check the sources for the invocation of the following hooks: \`${HOOK_POINTS_WITH_MULTIPLE_CALLS}\`.
|
||||
MULTIPLE_CALLS_WARNING
|
||||
|
||||
}
|
||||
|
||||
cat <<PRE_HOOKS_HEADER
|
||||
## Hooks
|
||||
- Hooks are listed in the order they are called.
|
||||
PRE_HOOKS_HEADER
|
||||
|
||||
loop_over_hook_points_and_call "generate_markdown_one_hook_point_to_stdout"
|
||||
|
||||
cat <<MASTER_FOOTER
|
||||
------------------------------------------------------------------------------------------
|
||||
MASTER_FOOTER
|
||||
|
||||
}
|
||||
|
||||
function generate_markdown_one_hook_point_to_stdout() {
|
||||
# Hook name in 3rd level title, first line of description in a blockquote.
|
||||
# The rest in a normal block.
|
||||
cat <<HOOK_DOCS
|
||||
### \`${one_hook_point}\`
|
||||
> ${MARKDOWN_HEAD}
|
||||
|
||||
${MARKDOWN_BODY}
|
||||
|
||||
HOOK_DOCS
|
||||
|
||||
[[ "${COMPATIBILITY_NAMES}" != "" ]] && {
|
||||
echo -e "\n\nAlso known as (for backwards compatibility only):"
|
||||
for old_name in ${COMPATIBILITY_NAMES}; do
|
||||
echo "- \`${old_name}\`"
|
||||
done
|
||||
}
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
## Bash sample extension stuff
|
||||
generate_sample_extension_to_stdout() {
|
||||
read_common_data
|
||||
cat <<HEADER
|
||||
# Sample Armbian build system extension with all extension methods.
|
||||
# This file is auto-generated from and by the build system itself.
|
||||
# Please, always use the latest version of this file as a starting point for your own extensions.
|
||||
# Generation date: $(date)
|
||||
# Read more about the build system at https://docs.armbian.com/Developer-Guide_Build-Preparation/
|
||||
|
||||
HEADER
|
||||
|
||||
loop_over_hook_points_and_call "generate_bash_sample_for_hook_point"
|
||||
}
|
||||
|
||||
generate_bash_sample_for_hook_point() {
|
||||
# Include the markdown documentation as a comment.
|
||||
# Right now clean it up naively (remove backticks, mostly) but we could pipe through stuff to get better plaintext. (pandoc is a 155mb binary FYI)
|
||||
local COMMENT_HEAD="#### $(echo "${MARKDOWN_HEAD}" | tr '`' '"')"
|
||||
# shellcheck disable=SC2001
|
||||
local COMMENT_BODY="$(echo "${MARKDOWN_BODY}" | tr '`' '"' | sed -e 's/^/### /')"
|
||||
|
||||
local bonus=""
|
||||
[[ "${HOOK_POINT_COUNTER}" == "1" ]] && bonus="$(echo -e "\n\texport PROGRESS_DISPLAY=verysilent # Example: export a variable. This one silences the built.")"
|
||||
|
||||
cat <<SAMPLE_BASH_CODE
|
||||
${COMMENT_HEAD}
|
||||
${COMMENT_BODY}
|
||||
function ${HOOK_POINT}__be_more_awesome() {
|
||||
# @TODO: Please rename this function to reflect what it does, but preserve the "${HOOK_POINT}__" prefix.
|
||||
display_alert "Being awesome at \${HOOK_POINT}" "\${EXTENSION}" "info"${bonus}
|
||||
}
|
||||
|
||||
SAMPLE_BASH_CODE
|
||||
}
|
||||
163
external/extensions/grub.sh
vendored
Executable file
163
external/extensions/grub.sh
vendored
Executable file
@@ -0,0 +1,163 @@
|
||||
# This runs *after* user_config. Don't change anything not coming from other variables or meant to be configured by the user.
|
||||
function extension_prepare_config__prepare_flash_kernel() {
|
||||
# Extension configuration defaults.
|
||||
export DISTRO_GENERIC_KERNEL=${DISTRO_GENERIC_KERNEL:-no} # if yes, does not build our own kernel, instead, uses generic one from distro
|
||||
export UEFI_GRUB_TERMINAL="${UEFI_GRUB_TERMINAL:-serial console}" # 'serial' forces grub menu on serial console. empty to not include
|
||||
export UEFI_GRUB_DISABLE_OS_PROBER="${UEFI_GRUB_DISABLE_OS_PROBER:-}" # 'true' will disable os-probing, useful for SD cards.
|
||||
export UEFI_GRUB_DISTRO_NAME="${UEFI_GRUB_DISTRO_NAME:-Armbian}" # Will be used on grub menu display
|
||||
export UEFI_GRUB_TIMEOUT=${UEFI_GRUB_TIMEOUT:-0} # Small timeout by default
|
||||
export UEFI_ENABLE_BIOS_AMD64="${UEFI_ENABLE_BIOS_AMD64:-yes}" # Enable BIOS too if target is amd64
|
||||
export UEFI_EXPORT_KERNEL_INITRD="${UEFI_EXPORT_KERNEL_INITRD:-no}" # Export kernel and initrd for direct kernel boot "kexec"
|
||||
# User config overrides.
|
||||
export BOOTCONFIG="none" # To try and convince lib/ to not build or install u-boot.
|
||||
unset BOOTSOURCE # To try and convince lib/ to not build or install u-boot.
|
||||
export IMAGE_PARTITION_TABLE="gpt" # GPT partition table is essential for many UEFI-like implementations, eg Apple+Intel stuff.
|
||||
export UEFISIZE=256 # in MiB - grub EFI is tiny - but some EFI BIOSes ignore small too small EFI partitions
|
||||
export BOOTSIZE=0 # No separate /boot when using UEFI.
|
||||
export CLOUD_INIT_CONFIG_LOCATION="${CLOUD_INIT_CONFIG_LOCATION:-/boot/efi}" # use /boot/efi for cloud-init as default when using Grub.
|
||||
export EXTRA_BSP_NAME="${EXTRA_BSP_NAME}-grub" # Unique bsp name.
|
||||
export UEFI_GRUB_TARGET_BIOS="" # Target for BIOS GRUB install, set to i386-pc when UEFI_ENABLE_BIOS_AMD64=yes and target is amd64
|
||||
local uefi_packages="efibootmgr efivar cloud-initramfs-growroot" # Use growroot, add some efi-related packages
|
||||
uefi_packages="os-prober grub-efi-${ARCH}-bin ${uefi_packages}" # This works for Ubuntu and Debian, by sheer luck; common for EFI and BIOS
|
||||
|
||||
# BIOS-compatibility for amd64
|
||||
if [[ "${ARCH}" == "amd64" ]]; then
|
||||
export UEFI_GRUB_TARGET="x86_64-efi" # Default for x86_64
|
||||
if [[ "${UEFI_ENABLE_BIOS_AMD64}" == "yes" ]]; then
|
||||
export uefi_packages="${uefi_packages} grub-pc-bin grub-pc"
|
||||
export UEFI_GRUB_TARGET_BIOS="i386-pc"
|
||||
export BIOSSIZE=4 # 4 MiB BIOS partition
|
||||
else
|
||||
export uefi_packages="${uefi_packages} grub-efi-${ARCH}"
|
||||
fi
|
||||
fi
|
||||
|
||||
[[ "${ARCH}" == "arm64" ]] && export uefi_packages="${uefi_packages} grub-efi-${ARCH}"
|
||||
[[ "${ARCH}" == "arm64" ]] && export UEFI_GRUB_TARGET="arm64-efi" # Default for arm64-efi
|
||||
|
||||
if [[ "${DISTRIBUTION}" == "Ubuntu" ]]; then
|
||||
DISTRO_KERNEL_PACKAGES="linux-image-generic"
|
||||
DISTRO_FIRMWARE_PACKAGES="linux-firmware"
|
||||
elif [[ "${DISTRIBUTION}" == "Debian" ]]; then
|
||||
DISTRO_KERNEL_PACKAGES="linux-image-${ARCH}"
|
||||
DISTRO_FIRMWARE_PACKAGES="firmware-linux-free"
|
||||
# Debian's prebuilt kernels dont support hvc0, hack.
|
||||
if [[ "${SERIALCON}" == "hvc0" ]]; then
|
||||
display_alert "Debian's kernels don't support hvc0, changing to ttyS0" "${DISTRIBUTION}" "wrn"
|
||||
export SERIALCON="ttyS0"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ "${DISTRO_GENERIC_KERNEL}" == "yes" ]]; then
|
||||
export VER="generic"
|
||||
unset KERNELSOURCE # This should make Armbian skip most stuff. At least, I hacked it to.
|
||||
export INSTALL_ARMBIAN_FIRMWARE=no # Should skip build and install of Armbian-firmware.
|
||||
else
|
||||
export KERNELDIR="linux-uefi-${LINUXFAMILY}" # Avoid sharing a source tree with others, until we know it's safe.
|
||||
# Don't install anything. Armbian handles everything.
|
||||
DISTRO_KERNEL_PACKAGES=""
|
||||
DISTRO_FIRMWARE_PACKAGES=""
|
||||
fi
|
||||
|
||||
export PACKAGE_LIST_BOARD="${PACKAGE_LIST_BOARD} ${DISTRO_FIRMWARE_PACKAGES} ${DISTRO_KERNEL_PACKAGES} ${uefi_packages}"
|
||||
|
||||
display_alert "Activating" "GRUB with SERIALCON=${SERIALCON}; timeout ${UEFI_GRUB_TIMEOUT}; BIOS=${UEFI_GRUB_TARGET_BIOS}" ""
|
||||
}
|
||||
|
||||
# @TODO: extract u-boot into an extension, so that core bsps don't have this stuff in there to begin with.
|
||||
# @TODO: this code is duplicated in flash-kernel.sh extension, so another reason to refactor the root of the evil
|
||||
post_family_tweaks_bsp__remove_uboot_grub() {
|
||||
display_alert "Removing uboot from BSP" "${EXTENSION}" "info"
|
||||
# Simply remove everything with 'uboot' or 'u-boot' in their filenames from the BSP package.
|
||||
# shellcheck disable=SC2154 # $destination is the target dir of the bsp building function
|
||||
find "$destination" -type f | grep -e "uboot" -e "u-boot" | xargs rm
|
||||
}
|
||||
|
||||
pre_umount_final_image__remove_uboot_initramfs_hook_grub() {
|
||||
# even if BSP still contained this (cached .deb), make sure by removing from ${MOUNT}
|
||||
[[ -f "$MOUNT"/etc/initramfs/post-update.d/99-uboot ]] && rm -v "$MOUNT"/etc/initramfs/post-update.d/99-uboot
|
||||
}
|
||||
|
||||
pre_umount_final_image__install_grub() {
|
||||
configure_grub
|
||||
local chroot_target=$MOUNT
|
||||
display_alert "Installing bootloader" "GRUB" "info"
|
||||
|
||||
# getting rid of the dtb package, if installed, is hard. for now just zap it, otherwise update-grub goes bananas
|
||||
rm -rf "$MOUNT"/boot/dtb* || true
|
||||
|
||||
# add config to disable os-prober, otherwise image will have the host's other OSes boot entries.
|
||||
cat <<-grubCfgFragHostSide >>"${MOUNT}"/etc/default/grub.d/99-armbian-host-side.cfg
|
||||
GRUB_DISABLE_OS_PROBER=true
|
||||
grubCfgFragHostSide
|
||||
|
||||
# Mount the chroot...
|
||||
mount_chroot "$chroot_target/" # this already handles /boot/efi which is required for it to work.
|
||||
|
||||
if [[ "${UEFI_GRUB_TARGET_BIOS}" != "" ]]; then
|
||||
display_alert "Installing GRUB BIOS..." "${UEFI_GRUB_TARGET_BIOS} device ${LOOP}" ""
|
||||
chroot "$chroot_target" /bin/bash -c "grub-install --verbose --target=${UEFI_GRUB_TARGET_BIOS} ${LOOP}" >>"$DEST"/"${LOG_SUBPATH}"/install.log 2>&1 || {
|
||||
exit_with_error "${install_grub_cmdline} failed!"
|
||||
}
|
||||
fi
|
||||
|
||||
local install_grub_cmdline="update-initramfs -c -k all && update-grub && grub-install --verbose --target=${UEFI_GRUB_TARGET} --no-nvram --removable" # nvram is global to the host, even across chroot. take care.
|
||||
display_alert "Installing GRUB EFI..." "${UEFI_GRUB_TARGET}" ""
|
||||
chroot "$chroot_target" /bin/bash -c "$install_grub_cmdline" >>"$DEST"/"${LOG_SUBPATH}"/install.log 2>&1 || {
|
||||
exit_with_error "${install_grub_cmdline} failed!"
|
||||
}
|
||||
|
||||
# Remove host-side config.
|
||||
rm -f "${MOUNT}"/etc/default/grub.d/99-armbian-host-side.cfg
|
||||
|
||||
local root_uuid
|
||||
root_uuid=$(blkid -s UUID -o value "${LOOP}p1") # get the uuid of the root partition, this has been transposed
|
||||
|
||||
# Create /boot/efi/EFI/BOOT/grub.cfg (EFI/ESP) which will load /boot/grub/grub.cfg (in the rootfs, generated by update-grub)
|
||||
cat <<-grubEfiCfg >"${MOUNT}"/boot/efi/EFI/BOOT/grub.cfg
|
||||
search.fs_uuid ${root_uuid} root
|
||||
set prefix=(\$root)'/boot/grub'
|
||||
configfile \$prefix/grub.cfg
|
||||
grubEfiCfg
|
||||
|
||||
umount_chroot "$chroot_target/"
|
||||
|
||||
}
|
||||
|
||||
pre_umount_final_image__900_export_kernel_and_initramfs() {
|
||||
if [[ "${UEFI_EXPORT_KERNEL_INITRD}" == "yes" ]]; then
|
||||
display_alert "Exporting Kernel and Initrd for" "kexec" "info"
|
||||
# this writes to ${DESTIMG} directly, since debootstrap.sh will move them later.
|
||||
# capture the $MOUNT/boot/vmlinuz and initrd and send it out ${DESTIMG}
|
||||
cp "$MOUNT"/boot/vmlinuz-* "${DESTIMG}/${version}.kernel"
|
||||
cp "$MOUNT"/boot/initrd.img-* "${DESTIMG}/${version}.initrd"
|
||||
fi
|
||||
}
|
||||
|
||||
configure_grub() {
|
||||
display_alert "GRUB EFI kernel cmdline" "console=${SERIALCON} distro=${UEFI_GRUB_DISTRO_NAME} timeout=${UEFI_GRUB_TIMEOUT}" ""
|
||||
|
||||
if [[ "_${SERIALCON}_" != "__" ]]; then
|
||||
cat <<-grubCfgFrag >>"${MOUNT}"/etc/default/grub.d/98-armbian.cfg
|
||||
GRUB_CMDLINE_LINUX_DEFAULT="console=${SERIALCON}" # extra Kernel cmdline is configured here
|
||||
grubCfgFrag
|
||||
fi
|
||||
|
||||
cat <<-grubCfgFrag >>"${MOUNT}"/etc/default/grub.d/98-armbian.cfg
|
||||
GRUB_TIMEOUT_STYLE=menu # Show the menu with Kernel options (Armbian or -generic)...
|
||||
GRUB_TIMEOUT=${UEFI_GRUB_TIMEOUT} # ... for ${UEFI_GRUB_TIMEOUT} seconds, then boot the Armbian default.
|
||||
GRUB_DISTRIBUTOR="${UEFI_GRUB_DISTRO_NAME}" # On GRUB menu will show up as "Armbian GNU/Linux" (will show up in some UEFI BIOS boot menu (F8?) as "armbian", not on others)
|
||||
grubCfgFrag
|
||||
|
||||
if [[ "a${UEFI_GRUB_DISABLE_OS_PROBER}" != "a" ]]; then
|
||||
cat <<-grubCfgFragHostSide >>"${MOUNT}"/etc/default/grub.d/98-armbian.cfg
|
||||
GRUB_DISABLE_OS_PROBER=${UEFI_GRUB_DISABLE_OS_PROBER}
|
||||
grubCfgFragHostSide
|
||||
fi
|
||||
|
||||
if [[ "a${UEFI_GRUB_TERMINAL}" != "a" ]]; then
|
||||
cat <<-grubCfgFragTerminal >>"${MOUNT}"/etc/default/grub.d/98-armbian.cfg
|
||||
GRUB_TERMINAL="${UEFI_GRUB_TERMINAL}"
|
||||
grubCfgFragTerminal
|
||||
fi
|
||||
}
|
||||
16
external/extensions/rkbin-tools.sh
vendored
Executable file
16
external/extensions/rkbin-tools.sh
vendored
Executable file
@@ -0,0 +1,16 @@
|
||||
function fetch_sources_tools__rkbin_tools() {
|
||||
fetch_from_repo "https://github.com/orangepi-xunlong/rk-rootfs-build" "${EXTER}/cache/sources/rkbin-tools" "branch:rkbin"
|
||||
}
|
||||
|
||||
function build_host_tools__install_rkbin_tools() {
|
||||
# install only if git commit hash changed
|
||||
cd "${EXTER}"/cache/sources/rkbin-tools || exit
|
||||
# need to check if /usr/local/bin/loaderimage to detect new Docker containers with old cached sources
|
||||
if [[ ! -f .commit_id || $(improved_git rev-parse @ 2>/dev/null) != $(<.commit_id) || ! -f /usr/local/bin/loaderimage ]]; then
|
||||
display_alert "Installing" "rkbin-tools" "info"
|
||||
mkdir -p /usr/local/bin/
|
||||
install -m 755 tools/loaderimage /usr/local/bin/
|
||||
install -m 755 tools/trust_merger /usr/local/bin/
|
||||
improved_git rev-parse @ 2>/dev/null >.commit_id
|
||||
fi
|
||||
}
|
||||
17
external/extensions/sunxi-tools.sh
vendored
Executable file
17
external/extensions/sunxi-tools.sh
vendored
Executable file
@@ -0,0 +1,17 @@
|
||||
function fetch_sources_tools__sunxi_tools() {
|
||||
fetch_from_repo "https://github.com/linux-sunxi/sunxi-tools" "${EXTER}/cache/sources/sunxi-tools" "branch:master"
|
||||
}
|
||||
|
||||
function build_host_tools__compile_sunxi_tools() {
|
||||
# Compile and install only if git commit hash changed
|
||||
cd "${EXTER}"/cache/sources/sunxi-tools || exit
|
||||
# need to check if /usr/local/bin/sunxi-fexc to detect new Docker containers with old cached sources
|
||||
if [[ ! -f .commit_id || $(improved_git rev-parse @ 2>/dev/null) != $(<.commit_id) || ! -f /usr/local/bin/sunxi-fexc ]]; then
|
||||
display_alert "Compiling" "sunxi-tools" "info"
|
||||
make -s clean >/dev/null
|
||||
make -s tools >/dev/null
|
||||
mkdir -p /usr/local/bin/
|
||||
make install-tools >/dev/null 2>&1
|
||||
improved_git rev-parse @ 2>/dev/null >.commit_id
|
||||
fi
|
||||
}
|
||||
Reference in New Issue
Block a user