From 6b5219b8034c9ffd3094657486e500119ad47325 Mon Sep 17 00:00:00 2001
From: Louai Al-Khanji <louai.al-khanji@qt.io>
Date: Thu, 28 Jul 2016 12:25:28 -0700
Subject: [PATCH] intel-corei7-64: fix race in image generation

Prepending to IMAGE_CMD_ext3 in order to push files into the rootfs is
flaky for a couple of reasons. First, it is conceptually inconsistent
with the rest of the build system - files that go into the rootfs should
really by installed by packages through the regular mechanisms. Second,
and what prompted this patch, with several concurrent image generation
tasks this is just unsafe. I regularly experienced .tgz image generation
failures, as tar complained that the files changed from under it.

Since this is related to the grub-efi packaging on this particular device,
just package the microcode into the required initramfs in that recipe.

Change-Id: I4e037ddbb017d1764852310b0b77900cde260dd6
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
---
 meta-intel-extras/classes/image_dd_efi.bbclass      |  9 ---------
 .../recipes/grub/grub-efi_2.00.bbappend             | 13 ++++++++++++-
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/meta-intel-extras/classes/image_dd_efi.bbclass b/meta-intel-extras/classes/image_dd_efi.bbclass
index 9cb20752..1f5fd9f7 100644
--- a/meta-intel-extras/classes/image_dd_efi.bbclass
+++ b/meta-intel-extras/classes/image_dd_efi.bbclass
@@ -33,15 +33,6 @@ LICENSE = "CLOSED"
 inherit image_dd
 
 EXTRA_IMAGECMD_ext3 += "-L rootfs"
-IMAGE_DEPENDS_ext3 += "initramfs-basic:do_rootfs"
-
-IMAGE_CMD_ext3_prepend() {
-
-    # https://www.kernel.org/doc/Documentation/x86/early-microcode.txt
-    microcode="${@bb.utils.contains('MACHINE_FEATURES', 'intel-ucode', '${DEPLOY_DIR_IMAGE}/microcode.cpio ', '', d)}"
-    cat ${microcode} ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.cpio.gz > ${IMAGE_ROOTFS}/boot/initramfs
-    chmod 0644 ${IMAGE_ROOTFS}/boot/initramfs
-}
 
 do_populate_boot() {
 
diff --git a/meta-intel-extras/recipes/grub/grub-efi_2.00.bbappend b/meta-intel-extras/recipes/grub/grub-efi_2.00.bbappend
index 8a223fe1..0104aabe 100644
--- a/meta-intel-extras/recipes/grub/grub-efi_2.00.bbappend
+++ b/meta-intel-extras/recipes/grub/grub-efi_2.00.bbappend
@@ -30,6 +30,12 @@
 FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"
 SRC_URI += "file://grub.cfg"
 
+do_install[depends] += " \
+    virtual/kernel:do_deploy \
+    ${INITRAMFS_IMAGE}:do_rootfs \
+    ${@bb.utils.contains('MACHINE_FEATURES', 'intel-ucode', 'intel-microcode:do_deploy', '', d)} \
+"
+
 do_deploy_prepend() {
 
 cat > ${WORKDIR}/cfg <<EOF
@@ -42,7 +48,12 @@ do_install_append() {
 
     install -d ${D}/boot/grub2/
     install -m 644 ${WORKDIR}/grub.cfg ${D}/boot/grub2/
+
+    # https://www.kernel.org/doc/Documentation/x86/early-microcode.txt
+    microcode="${@bb.utils.contains('MACHINE_FEATURES', 'intel-ucode', '${DEPLOY_DIR_IMAGE}/microcode.cpio ', '', d)}"
+    cat ${microcode} ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.cpio.gz > ${D}/boot/initramfs
+    chmod 0644 ${D}/boot/initramfs
 }
 
 PACKAGES += "${PN}-config"
-FILES_${PN}-config = "/boot/grub2/"
+FILES_${PN}-config = "/boot/grub2/ /boot/initramfs"
-- 
GitLab