kernel-initramfs: Rework to use update-alternatives directly

- All valid initramfs types will be listed in INITRAMFS_FSTYPES so use
  that variable rather than open-coding a list of possibilities.
- Since we're using the list of things that must exist now we don't need
  to test if the files exist anymore.  And when signing, we can sign all
  of them now.
- Add some python to do_package to update all of the ALTERNATIVES
  variables dynamically based on how we're configured.  This introduces
  an alternative for the initramfs portion as well so there is a stable
  name.

Signed-off-by: Tom Rini <trini@konsulko.com>
This commit is contained in:
Tom Rini
2018-05-05 09:38:03 -04:00
committed by Jia Zhang
parent e00aed3e08
commit 4d27285e28
2 changed files with 38 additions and 62 deletions
+19 -20
View File
@@ -35,39 +35,38 @@ do_populate_lic[depends] += "virtual/kernel:do_deploy"
do_install() {
[ -z "${INITRAMFS_IMAGE}" ] && exit 0
install -d "${D}/boot"
if [ "${BUNDLE}" = "0" ]; then
for suffix in cpio.gz cpio.lzo cpio.lzma cpio.xz; do
for suffix in ${INITRAMFS_FSTYPES}; do
img="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.$suffix"
if [ -s "$img" ]; then
install -d "${D}/boot"
install -m 0644 "$img" \
"${D}/boot/${INITRAMFS_IMAGE}${INITRAMFS_EXT_NAME}.$suffix"
break
fi
install -m 0644 "$img" \
"${D}/boot/${INITRAMFS_IMAGE}${INITRAMFS_EXT_NAME}.$suffix"
done
else
if [ -e "${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-initramfs-${MACHINE}.bin" ]; then
install -d "${D}/boot"
install -m 0644 "${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE}-initramfs-${MACHINE}.bin" \
"${D}/boot/${KERNEL_IMAGETYPE}-initramfs${INITRAMFS_EXT_NAME}"
fi
fi
}
pkg_postinst_${PN}() {
if [ "${BUNDLE}" = "1" ]; then
update-alternatives --install "/boot/${KERNEL_IMAGETYPE}" \
"${KERNEL_IMAGETYPE}" "/boot/${KERNEL_IMAGETYPE}-initramfs${INITRAMFS_EXT_NAME}" \
50101 || true
fi
}
inherit update-alternatives
pkg_prerm_${PN}() {
if [ "${BUNDLE}" = "1" ]; then
update-alternatives --remove "${KERNEL_IMAGETYPE}" \
"${KERNEL_IMAGETYPE}-initramfs${INITRAMFS_EXT_NAME}" || true
fi
ALTERNATIVES_${PN} = ""
python do_package_prepend () {
if d.getVar('BUNDLE') == '1':
d.appendVar(d.expand('ALTERNATIVE_${PN}'), ' ' + d.expand('${KERNEL_IMAGETYPE}' + '-initramfs'))
d.setVarFlag('ALTERNATIVE_LINK_NAME', d.expand('${KERNEL_IMAGETYPE}') + '-initramfs', d.expand('/boot/${KERNEL_IMAGETYPE}-initramfs'))
d.setVarFlag('ALTERNATIVE_TARGET', d.expand('${KERNEL_IMAGETYPE}') + '-initramfs', d.expand('/boot/${KERNEL_IMAGETYPE}-initramfs${INITRAMFS_EXT_NAME}'))
d.setVarFlag('ALTERNATIVE_PRIORITY', d.expand('${KERNEL_IMAGETYPE}') + '-initramfs', '50101')
else:
for compr in d.getVar('INITRAMFS_FSTYPES').split():
d.appendVar(d.expand('ALTERNATIVE_${PN}'), ' ' + d.expand('${INITRAMFS_IMAGE}'))
d.setVarFlag('ALTERNATIVE_LINK_NAME', d.expand('${INITRAMFS_IMAGE}'), d.expand('/boot/${INITRAMFS_IMAGE}'))
d.setVarFlag('ALTERNATIVE_TARGET', d.expand('${INITRAMFS_IMAGE}'), d.expand('/boot/${INITRAMFS_IMAGE}${INITRAMFS_EXT_NAME}.' + compr))
d.setVarFlag('ALTERNATIVE_PRIORITY', d.expand('${INITRAMFS_IMAGE}'), '50101')
}
PACKAGE_ARCH = "${MACHINE_ARCH}"