mirror of
https://github.com/armbian/build
synced 2025-09-24 19:47:06 +07:00
Compare commits
3 Commits
bsp-bugfix
...
bootconfig
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e59da409a | ||
|
|
5e4dc7ee22 | ||
|
|
878443b603 |
@@ -56,10 +56,18 @@ setenv bootargs "${bootargs} root=${rootdev} rootwait rw"
|
||||
setenv bootargs "${bootargs} ${consoleargs}"
|
||||
setenv bootargs "${bootargs} ${extraargs}"
|
||||
|
||||
# Read bootconfig
|
||||
fatload ${bootdev} 0x20800000 /bootconfig || exit 1
|
||||
env import -t 0x20800000 ${filesize}
|
||||
|
||||
# Use default bootconfig
|
||||
test -n "${ARMBIAN_BOOTMENU_TITLE[0]}" || exit 1
|
||||
run "ARMBIAN_BOOTMENU_COMMAND[0]"
|
||||
|
||||
# Booting
|
||||
fatload ${bootdev} 0x20800000 /uImage || exit 1
|
||||
fatload ${bootdev} 0x22000000 /uInitrd || exit 1
|
||||
fatload ${bootdev} 0x21800000 /dtb/meson8b-onecloud.dtb || exit 1
|
||||
fatload ${bootdev} 0x20800000 "/${KERNEL_NAME}" || exit 1
|
||||
fatload ${bootdev} 0x22000000 "/${INITRD_NAME}" || exit 1
|
||||
fatload ${bootdev} 0x21800000 "/${DTB_NAME}/meson8b-onecloud.dtb" || exit 1
|
||||
|
||||
bootm 0x20800000 0x22000000 0x21800000
|
||||
|
||||
|
||||
@@ -120,6 +120,9 @@ function compile_armbian-bsp-cli() {
|
||||
|
||||
mkdir -p "${destination}"/usr/share/armbian/
|
||||
|
||||
# Refresh bootconfig
|
||||
postinst_functions+=(board_side_bsp_cli_postinst_update_bootconfig)
|
||||
|
||||
# get bootscript information.
|
||||
declare -A bootscript_info=()
|
||||
get_bootscript_info
|
||||
@@ -234,6 +237,7 @@ function reversion_armbian-bsp-cli_deb_contents() {
|
||||
|
||||
# Replaces: base-files is needed to replace the distro's base-files
|
||||
# Depends: linux-base is needed for "linux-version" command in initrd cleanup script
|
||||
# Depends: file is needed for /usr/bin/armbian-bootconfig
|
||||
# Depends: fping is needed for armbianmonitor to upload armbian-hardware-monitor.log
|
||||
# Depends: base-files (>= ${REVISION}) is to force usage of our base-files package (not the original Distro's).
|
||||
declare depends_base_files=", base-files (>= ${REVISION})"
|
||||
@@ -241,7 +245,7 @@ function reversion_armbian-bsp-cli_deb_contents() {
|
||||
depends_base_files=""
|
||||
fi
|
||||
cat <<- EOF >> "${control_file_new}"
|
||||
Depends: bash, linux-base, u-boot-tools, initramfs-tools, lsb-release, fping${depends_base_files}
|
||||
Depends: bash, linux-base, u-boot-tools, initramfs-tools, lsb-release, file, fping${depends_base_files}
|
||||
Replaces: zram-config, armbian-bsp-cli-${BOARD}${EXTRA_BSP_NAME} (<< ${REVISION})
|
||||
Breaks: armbian-bsp-cli-${BOARD}${EXTRA_BSP_NAME} (<< ${REVISION})
|
||||
EOF
|
||||
@@ -264,6 +268,10 @@ function reversion_armbian-bsp-cli_deb_contents() {
|
||||
return 0
|
||||
}
|
||||
|
||||
function board_side_bsp_cli_postinst_update_bootconfig() {
|
||||
/usr/bin/armbian-bootconfig scan
|
||||
}
|
||||
|
||||
function get_bootscript_info() {
|
||||
bootscript_info[has_bootscript]="no"
|
||||
bootscript_info[has_extlinux]="no"
|
||||
|
||||
9
packages/bsp/common/etc/kernel/postinst.d/xx-armbian-bootconfig
Executable file
9
packages/bsp/common/etc/kernel/postinst.d/xx-armbian-bootconfig
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This script should be run after `initramfs-tools` for the initrd image
|
||||
|
||||
version="$1"
|
||||
image_path="$2"
|
||||
|
||||
# `armbian-bootconfig` will check the arguments, so we don't need to do that
|
||||
/usr/bin/armbian-bootconfig install "${version}"
|
||||
6
packages/bsp/common/etc/kernel/prerm.d/armbian-bootconfig
Executable file
6
packages/bsp/common/etc/kernel/prerm.d/armbian-bootconfig
Executable file
@@ -0,0 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
version="$1"
|
||||
image_path="$2"
|
||||
|
||||
/usr/bin/armbian-bootconfig remove "${version}" || true
|
||||
260
packages/bsp/common/usr/bin/armbian-bootconfig
Executable file
260
packages/bsp/common/usr/bin/armbian-bootconfig
Executable file
@@ -0,0 +1,260 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
declare -g -a bootconfig=()
|
||||
|
||||
function detect_kernel_type() {
|
||||
declare kernel_path="$1"
|
||||
declare type=""
|
||||
declare compress_type=""
|
||||
|
||||
type="$(file --brief "${kernel_path}" | cut -d',' -f1)"
|
||||
|
||||
if [[ "${type}" == "gzip compressed data" ]]; then
|
||||
type="$(file --brief --uncompress "${kernel_path}" | cut -d',' -f1)"
|
||||
compress_type=".gz"
|
||||
fi
|
||||
|
||||
type="${type% (*-endian)}"
|
||||
case "${type}" in
|
||||
Linux\ kernel\ *\ boot\ executable\ *)
|
||||
echo "${type#Linux kernel * boot executable }${compress_type}"
|
||||
;;
|
||||
"u-boot legacy uImage")
|
||||
echo "uImage${compress_type}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function load() {
|
||||
bootconfig=()
|
||||
if [ -f "/boot/bootconfig" ]; then
|
||||
while read -r item; do
|
||||
[[ "${item}" == "# ARMBIAN_BOOTCONFIG;"* ]] || continue
|
||||
version="${item#\# ARMBIAN_BOOTCONFIG;}"
|
||||
bootconfig+=( "${version}" )
|
||||
done <"/boot/bootconfig"
|
||||
fi
|
||||
}
|
||||
|
||||
function save() {
|
||||
{
|
||||
cat <<- HEADER
|
||||
# DO NOT EDIT THIS FILE
|
||||
# Auto-generated by /usr/bin/armbian-bootconfig
|
||||
HEADER
|
||||
|
||||
echo -e "\n# Configuration used by armbian-bootconfig"
|
||||
for version in "${bootconfig[@]}"; do
|
||||
echo "# ARMBIAN_BOOTCONFIG;${version}"
|
||||
done
|
||||
|
||||
echo -e "\n# Configuration for bootscript"
|
||||
echo "ARMBIAN_BOOTMENU_NUMBER=${#bootconfig[@]}"
|
||||
declare -i i=0
|
||||
for i in "${!bootconfig[@]}"; do
|
||||
declare version="${bootconfig[${i}]}"
|
||||
|
||||
declare title="Armbian with Linux ${version}"
|
||||
declare -A env=(
|
||||
[VERSION]="${version}"
|
||||
[KERNEL_TYPE]="$(detect_kernel_type "/boot/vmlinuz-${version}")"
|
||||
[KERNEL_NAME]="vmlinuz-${version}"
|
||||
[INITRD_TYPE]="uInitrd"
|
||||
[INITRD_NAME]="uInitrd-${version}"
|
||||
[DTB_NAME]="dtb-${version}"
|
||||
)
|
||||
|
||||
echo ""
|
||||
echo "ARMBIAN_BOOTMENU_TITLE[${i}]=${title}"
|
||||
echo -n "ARMBIAN_BOOTMENU_COMMAND[${i}]="
|
||||
for name in "${!env[@]}"; do
|
||||
echo -n "setenv '${name}' '${env[${name}]}'; "
|
||||
done
|
||||
echo ""
|
||||
done
|
||||
} >/boot/bootconfig
|
||||
}
|
||||
|
||||
function containIn() {
|
||||
declare str="$1"
|
||||
shift 1
|
||||
for v in "$@"; do
|
||||
[[ "${v}" != "${str}" ]] || return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
function usage() {
|
||||
declare name
|
||||
name="$(basename "$0")"
|
||||
cat <<- USAGE >&2
|
||||
${name} - Tool to manage armbian bootconfig
|
||||
|
||||
Usage:
|
||||
${name} install VERSION - Install kernel bootconfig for VERSION
|
||||
${name} remove VERSION - Remove kernel bootconfig for VERSION
|
||||
${name} scan - Search all bootable kernel and insert them to the end of bootconfig
|
||||
${name} list - List all bootconfig
|
||||
${name} default [VERSION] - Choose default kernel
|
||||
USAGE
|
||||
}
|
||||
|
||||
function install() {
|
||||
declare insert_end=false
|
||||
declare version=""
|
||||
for arg in "$@"; do
|
||||
case "${arg}" in
|
||||
--insert-end)
|
||||
insert_end=true
|
||||
;;
|
||||
-*)
|
||||
echo "Unsupported option: $arg" >&2
|
||||
return 22
|
||||
;;
|
||||
*)
|
||||
version="$arg"
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[[ -n "${version}" ]] || return 22
|
||||
|
||||
if containIn "${version}" "${bootconfig[@]}"; then
|
||||
echo "Kernel version ${version} has installed" >&2
|
||||
return 17
|
||||
fi
|
||||
|
||||
if [ ! -f "/boot/vmlinuz-${version}" ]; then
|
||||
echo "Kernel /boot/vmlinuz-${version} not found" >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
if ${insert_end}; then
|
||||
echo "Installing new kernel version ${version} to the end of bootconfig"
|
||||
bootconfig=( "${bootconfig[@]}" "${version}" )
|
||||
else
|
||||
echo "Installing new kernel version ${version} to the head of bootconfig"
|
||||
bootconfig=( "${version}" "${bootconfig[@]}" )
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function remove() {
|
||||
declare version="$1"
|
||||
[[ -n "${version}" ]] || return 22
|
||||
|
||||
declare -i index=-1
|
||||
for i in "${!bootconfig[@]}"; do
|
||||
if [[ "${bootconfig[${i}]}" == "${version}" ]]; then
|
||||
index="${i}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "${index}" -lt 0 ]]; then
|
||||
echo "Kernel version ${version} not found" >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
echo "Removing kernel version ${version}"
|
||||
unset "bootconfig[${index}]"
|
||||
# Resort index
|
||||
bootconfig=( "${bootconfig[@]}" )
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function scan() {
|
||||
while read -r kernel_path; do
|
||||
declare version="${kernel_path#/boot/vmlinuz-}"
|
||||
if ! containIn "${version}" "${bootconfig[@]}"; then
|
||||
install --insert-end "${version}"
|
||||
fi
|
||||
done < <(ls --sort=time /boot/vmlinuz-*)
|
||||
}
|
||||
|
||||
function list() {
|
||||
for version in "${bootconfig[@]}"; do
|
||||
echo "${version}"
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function default_menu() {
|
||||
declare version=""
|
||||
while true; do
|
||||
echo -e "All installed kernel:"
|
||||
for i in "${!bootconfig[@]}"; do
|
||||
echo -e "\t${i}) ${bootconfig[${i}]}"
|
||||
done
|
||||
|
||||
declare resp
|
||||
read -r -p "Choose the default boot kernel: " resp
|
||||
if [[ "${resp}" =~ ^[0-9]+$ ]] && [[ -n "${bootconfig[${resp}]}" ]]; then
|
||||
version="${bootconfig[${resp}]}"
|
||||
break
|
||||
elif containIn "${resp}" "${bootconfig[@]}"; then
|
||||
version="${resp}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
default "${version}"
|
||||
}
|
||||
|
||||
function default() {
|
||||
declare version="$1"
|
||||
|
||||
if [[ -z "${version}" ]]; then
|
||||
default_menu
|
||||
return $?
|
||||
fi
|
||||
|
||||
declare -i index=-1
|
||||
for i in "${!bootconfig[@]}"; do
|
||||
if [[ "${bootconfig[${i}]}" == "${version}" ]]; then
|
||||
index="${i}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "${index}" -lt 0 ]]; then
|
||||
echo "Kernel version ${version} not found" >&2
|
||||
return 2
|
||||
fi
|
||||
|
||||
echo "Set default boot kernel version ${version}"
|
||||
unset "bootconfig[${index}]"
|
||||
bootconfig=( "${version}" "${bootconfig[@]}" )
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
function main() {
|
||||
declare ret=0
|
||||
|
||||
case "$1" in
|
||||
install|remove|scan|default)
|
||||
load
|
||||
"$@" || ret=$?
|
||||
if [[ ${ret} == 0 ]]; then
|
||||
save || ret=$?
|
||||
fi
|
||||
;;
|
||||
list)
|
||||
load
|
||||
"$@" || ret=$?
|
||||
;;
|
||||
*)
|
||||
ret=22
|
||||
;;
|
||||
esac
|
||||
|
||||
[[ ${ret} != 22 ]] || usage
|
||||
exit $ret
|
||||
}
|
||||
|
||||
main "$@"
|
||||
@@ -0,0 +1,26 @@
|
||||
# armbian-bootconfig completion
|
||||
|
||||
_armbian_bootconfig() {
|
||||
local cur prev words cword split
|
||||
_init_completion -s || return
|
||||
|
||||
if [[ ${cword} -eq 1 ]]; then
|
||||
COMPREPLY=( $( compgen -W "$($1 help |& grep "^ $1 " | awk '{print $2}')" -- "${cur}" ) )
|
||||
return 0
|
||||
fi
|
||||
|
||||
local cmd="${words[1]}"
|
||||
case "${cmd}" in
|
||||
install)
|
||||
# @TODO: Filter the installed kernel
|
||||
COMPREPLY=( $( compgen -W "$(ls "/boot/vmlinuz-"* | sed 's|^/boot/vmlinuz-||')" -- "${cur}" ) )
|
||||
;;
|
||||
remove|default)
|
||||
COMPREPLY=( $( compgen -W "$($1 list)" -- "${cur}" ) )
|
||||
;;
|
||||
scan|list)
|
||||
COMPREPLY=()
|
||||
;;
|
||||
esac
|
||||
} &&
|
||||
complete -F _armbian_bootconfig armbian-bootconfig
|
||||
Reference in New Issue
Block a user