summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eclass/linux-build.eclass136
1 files changed, 105 insertions, 31 deletions
diff --git a/eclass/linux-build.eclass b/eclass/linux-build.eclass
index c03f8d10..28d08d3b 100644
--- a/eclass/linux-build.eclass
+++ b/eclass/linux-build.eclass
@@ -68,6 +68,45 @@ _linux-build_configval() {
esac
}
+_linux-build_protect() {
+ local _dir="${1%/*}"
+ local _file="${1##*/}"
+ local _path
+ local i
+
+ _path="${EPREFIX}/${_dir}/${_file}"
+ if [[ ! -e "${_path}" ]] ; then
+ echo "${_path}"
+ return 0
+ fi
+
+ for (( i = 0 ; i < 9999 ; i++ )) ; do
+ printf -v _path "${EPREFIX}/${_dir}/._cfg%04d_${_file}" "${i}"
+
+ if [[ ! -e "${_path}" ]] ; then
+ echo "${_path}"
+ return 0
+ fi
+ done
+
+ return 1
+}
+
+_linux-build_relpath() {
+ local _file="${1}"
+ local _mnt
+
+ # FIXME find a way to identify path of file relative to mount point
+ # when file does not exist yet, neither stat or findmnt support it,
+ # until then, use a prefix whitelist
+ case "${_file}" in
+ /boot/*) _mnt="$(stat -c '%m' /boot)" ;;
+ *) die "${FUNCNAME} does not handle ${_file}" ;;
+ esac
+
+ echo "${_file/#${_mnt}}"
+}
+
_linux-build_get-portage-versions() {
local -a _v
local _rv
@@ -181,19 +220,27 @@ _linux-build_src_prepare_build() {
echo "${CONFIG_CMDLINE}" > "${WORKDIR}/boot/kernel.arg"
fi
- local -a BOOTLOADERS=()
+ local -a BOOTLOADERS=(
+ sys-boot/gnu-efi
+ /boot/loader/loader.conf "/boot/loader/entries/${KV_FULL}.conf"
+ )
case "${ARCH}" in
amd64|x86)
BOOTLOADERS+=(
- sys-boot/grub:0 /boot/grub/grub.conf
- sys-boot/grub:2 /boot/grub/grub.cfg
- sys-boot/syslinux:0 /boot/extlinux/syslinux.cfg
- sys-boot/syslinux:0 /boot/extlinux/extlinux.conf
+ sys-boot/grub:0
+ /boot/grub/grub.conf none
+ sys-boot/grub:2
+ /boot/grub/grub.cfg "/boot/grub/entries/${KV_FULL}.cfg"
+ sys-boot/syslinux:0
+ /boot/extlinux/syslinux.cfg none
+ sys-boot/syslinux:0
+ /boot/extlinux/extlinux.conf none
) ;;
arm|arm64)
BOOTLOADERS+=(
- sys-boot/raspberrypi-firmware /boot/config.txt
+ sys-boot/raspberrypi-firmware
+ /boot/config.txt none
) ;;
esac
@@ -201,41 +248,68 @@ _linux-build_src_prepare_build() {
KV_INSTALLED="${KV_INSTALLED/#${CATEGORY}\/${PN}-}${KV_EXTRA}"
# Generate bootloader configuration
- if [[ -n "${KV_INSTALLED}" ]] ; then
- for (( i = 0 ; i < ${#BOOTLOADERS[@]} ; i += 2 )) ; do
- if has_version "${BOOTLOADERS[i]}" && [[ -e "${EPREFIX}/${BOOTLOADERS[i+1]}" ]] ; then
- BOOTLOADER_DIR="${BOOTLOADERS[i+1]%/*}"
- BOOTLOADER_FILE="${BOOTLOADERS[i+1]##*/}"
- break
- fi
- done
+ for (( i = 0 ; i < ${#BOOTLOADERS[@]} ; i += 3 )) ; do
+ BOOTLOADER_PKG="${BOOTLOADERS[i]}"
+ BOOTLOADER_CONFIG_FILE_MAIN="${BOOTLOADERS[i+1]}"
+ BOOTLOADER_CONFIG_FILE_KV="${BOOTLOADERS[i+2]}"
- if [[ -n "${BOOTLOADER_DIR}" && -n "${BOOTLOADER_FILE}" ]] ; then
- mkdir -p "${WORKDIR}/bootloader/${BOOTLOADER_DIR}"
+ if ! has_version "${BOOTLOADER_PKG}" ; then
+ continue
+ fi
- # Handle collision protect
- for (( i = 0 ; i < 9999 ; i++ )) ; do
- printf -v BOOTLOADER_PROTECTED_FILE "._cfg%04d_${BOOTLOADER_FILE}" "${i}"
- if [[ ! -e "${EPREFIX}/${BOOTLOADER_DIR}/${BOOTLOADER_PROTECTED_FILE}" ]] ; then
- break
- fi
- done
-
- einfo "Generating ${BOOTLOADER_DIR}/${BOOTLOADER_FILE}"
+ # Handle collision protect
+ WORKDIR_BOOTLOADER_CONFIG_FILE_MAIN="$(_linux-build_protect "${BOOTLOADER_CONFIG_FILE_MAIN}")"
+
+ if [[ -n "${KV_INSTALLED}" && -e "${BOOTLOADER_CONFIG_FILE_MAIN}" ]] ; then
+ einfo "Updating ${BOOTLOADER_CONFIG_FILE_MAIN}"
+ mkdir -p "${WORKDIR}/bootloader/${WORKDIR_BOOTLOADER_CONFIG_FILE_MAIN%/*}"
sed -e "s@${KV_INSTALLED}@${KV_FULL}@g" \
- "${EPREFIX}/${BOOTLOADER_DIR}/${BOOTLOADER_FILE}" \
- > "${WORKDIR}/bootloader/${BOOTLOADER_DIR}/${BOOTLOADER_PROTECTED_FILE}"
+ "${BOOTLOADER_CONFIG_FILE_MAIN}" \
+ > "${WORKDIR}/bootloader/${WORKDIR_BOOTLOADER_CONFIG_FILE_MAIN}"
if diff -q \
- "${EPREFIX}/${BOOTLOADER_DIR}/${BOOTLOADER_FILE}" \
- "${WORKDIR}/bootloader/${BOOTLOADER_DIR}/${BOOTLOADER_PROTECTED_FILE}" > /dev/null ; then
+ "${BOOTLOADER_CONFIG_FILE_MAIN}" \
+ "${WORKDIR}/bootloader/${WORKDIR_BOOTLOADER_CONFIG_FILE_MAIN}" > /dev/null ; then
- rm "${WORKDIR}/bootloader/${BOOTLOADER_DIR}/${BOOTLOADER_PROTECTED_FILE}"
+ rm "${WORKDIR}/bootloader/${WORKDIR_BOOTLOADER_CONFIG_FILE_MAIN}"
fi
- _CONFIG_PROTECT+=( "${BOOTLOADER_DIR}/${BOOTLOADER_FILE}" )
+ _CONFIG_PROTECT+=( "${BOOTLOADER_CONFIG_FILE_MAIN}" )
fi
+ if [[ "${BOOTLOADER_CONFIG_FILE_KV}" != "none" ]] ; then
+ # Handle collision protect
+ WORKDIR_BOOTLOADER_CONFIG_FILE_KV="$(_linux-build_protect "${BOOTLOADER_CONFIG_FILE_KV}")"
+
+ einfo "Generating ${BOOTLOADER_CONFIG_FILE_KV}"
+ mkdir -p "${WORKDIR}/bootloader/${WORKDIR_BOOTLOADER_CONFIG_FILE_KV%/*}"
+
+ case "${BOOTLOADER_PKG}" in
+ sys-boot/gnu-efi)
+ cat > "${WORKDIR}/bootloader/${WORKDIR_BOOTLOADER_CONFIG_FILE_KV}" <<-EOF
+ title Gentoo Linux
+ version ${KV_FULL}
+ linux $(_linux-build_relpath /boot/${KV_FULL}/kernel.img)
+ options ${CONFIG_CMDLINE}
+ EOF
+ ;;
+ sys-boot/grub:2)
+ cat > "${WORKDIR}/bootloader/${WORKDIR_BOOTLOADER_CONFIG_FILE_KV}" <<-EOF
+ menuentry 'Gentoo Linux' --class gentoo --class gnu-linux --class gnu --class os {
+ $(echo ' ')linux $(_linux-build_relpath /boot/${KV_FULL}/kernel.img) ${CONFIG_CMDLINE}
+ }
+ EOF
+ ;;
+ *)
+ die "${ECLASS} does not know how to generate bootloader configuration for ${BOOTLOADER_PKG}"
+ ;;
+ esac
+
+ _CONFIG_PROTECT+=( "${BOOTLOADER_CONFIG_FILE_KV}" )
+ fi
+ done
+
+ if [[ -n "${_CONFIG_PROTECT[@]}" ]] ; then
echo "CONFIG_PROTECT='${_CONFIG_PROTECT[@]}'" > "${WORKDIR}/env.d_42-${P}"
fi