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
@@ -4,56 +4,33 @@ inherit user-key-store deploy
do_install[nostamp] = "1"
fakeroot python do_sign() {
initramfs = None
if d.getVar('BUNDLE', True) == '0':
initramfs = d.expand('${D}/boot/${INITRAMFS_IMAGE}${INITRAMFS_EXT_NAME}.cpio.gz')
for compr in d.getVar('INITRAMFS_FSTYPES').split():
uks_sel_sign(d.expand('${D}/boot/${INITRAMFS_IMAGE}${INITRAMFS_EXT_NAME}.') + compr, d)
else:
initramfs = d.expand('${D}/boot/${KERNEL_IMAGETYPE}-initramfs${INITRAMFS_EXT_NAME}')
if initramfs == None or not os.path.exists(initramfs):
return
uks_sel_sign(initramfs, d)
uks_sel_sign(d.expand('${D}/boot/${KERNEL_IMAGETYPE}-initramfs${INITRAMFS_EXT_NAME}'), d)
}
addtask sign after do_install before do_deploy do_package
do_sign[prefuncs] += "check_deploy_keys"
do_deploy() {
initramfs=""
initramfs_dest=""
if [ "${BUNDLE}" = "0" ]; then
initramfs="${D}/boot/${INITRAMFS_IMAGE}${INITRAMFS_EXT_NAME}.cpio.gz"
initramfs_dest="${DEPLOYDIR}/${INITRAMFS_IMAGE}-${MACHINE}.cpio.gz"
else
initramfs="${D}/boot/${KERNEL_IMAGETYPE}-initramfs${INITRAMFS_EXT_NAME}"
initramfs_dest="${DEPLOYDIR}/${KERNEL_IMAGETYPE}-initramfs-${MACHINE}.bin"
fi
if [ -f "$initramfs.p7b" ]; then
install -d "${DEPLOYDIR}"
install -m 0644 "$initramfs.p7b" "$initramfs_dest.p7b"
fi
install -d "${DEPLOYDIR}"
for SIG in ${D}/boot/*.p7b; do
install -m 0644 ${SIG} ${DEPLOYDIR}
done
}
addtask deploy after do_install before do_build
pkg_postinst_${PN}_append() {
if [ "${BUNDLE}" = "1" ] ; then
update-alternatives --install "/boot/${KERNEL_IMAGETYPE}.p7b" \
"${KERNEL_IMAGETYPE}.p7b" \
"/boot/${KERNEL_IMAGETYPE}-initramfs${INITRAMFS_EXT_NAME}.p7b" 50101
fi
true
}
pkg_prerm_${PN}_append() {
if [ "${BUNDLE}" = "1" ] ; then
update-alternatives --remove "${KERNEL_IMAGETYPE}.p7b" \
"${KERNEL_IMAGETYPE}-initramfs${INITRAMFS_EXT_NAME}.p7b"
fi
true
python do_package_prepend () {
if d.getVar('BUNDLE') == '1':
d.appendVar(d.expand('ALTERNATIVE_${PN}'), ' ' + d.expand('${KERNEL_IMAGETYPE}' + '-initramfs.p7b'))
d.setVarFlag('ALTERNATIVE_LINK_NAME', d.expand('${KERNEL_IMAGETYPE}') + '-initramfs.p7b', d.expand('/boot/${KERNEL_IMAGETYPE}-initramfs.p7b'))
d.setVarFlag('ALTERNATIVE_TARGET', d.expand('${KERNEL_IMAGETYPE}') + '-initramfs.p7b', d.expand('/boot/${KERNEL_IMAGETYPE}-initramfs${INITRAMFS_EXT_NAME}.p7b'))
d.setVarFlag('ALTERNATIVE_PRIORITY', d.expand('${KERNEL_IMAGETYPE}') + '-initramfs.p7b', '50101')
else:
for compr in d.getVar('INITRAMFS_FSTYPES').split():
d.appendVar(d.expand('ALTERNATIVE_${PN}'), ' ' + d.expand('${INITRAMFS_IMAGE}') + '.p7b')
d.setVarFlag('ALTERNATIVE_LINK_NAME', d.expand('${INITRAMFS_IMAGE}') + '.p7b', d.expand('/boot/${INITRAMFS_IMAGE}.p7b'))
d.setVarFlag('ALTERNATIVE_TARGET', d.expand('${INITRAMFS_IMAGE}') + '.p7b', d.expand('/boot/${INITRAMFS_IMAGE}${INITRAMFS_EXT_NAME}.' + compr + '.p7b'))
d.setVarFlag('ALTERNATIVE_PRIORITY', d.expand('${INITRAMFS_IMAGE}') + '.p7b', '50101')
}