u-boot: Ensure we rebuild on change of VERSION_ID

Systems utilising the obmc-ubi-fs DISTRO_FEATURE may fail to boot a
freshly built image under some circumstances. Typically the error will
be a mismatch in the u-boot environment between the value set in
`kernelname` and the on-flash volume name for the kernel. They differ in
the "Image ID" portion.

The image ID is derived from the VERSION_ID field of `/etc/os-release`,
and is currently added to the u-boot environment by sed-patching both a
patch file adding the necessary information to the appropriate u-boot
header, and the u-boot header itself.

Why the current approach is wrong requires a bit of background on
bitbake:

1. bitbake tasks must be idempotent
2. Building on 1, bitbake caches build state using stamp files
3. bitbake tasks will not be re-run if a stamp exists and the task
   input state matches
4. bitbake requires actions execute in the appropriate build phase

To the issues:

A. The sed-patching was performed by hooking the do_configure() task.
   This is wrong: There's a do_patch() phase whose purpose is to handle
   modifying the source tree, and will handle cache invalidation
   appropriately. The patch modifies the recipe to append the
   sed-patching to the do_patch() phase when the obmc-ubi-fs
   DISTRO_FEATURE is enabled.

B. Sed-patching a patch is unnecessary. We can just sed the target file.
   By appending to the do_patch() phase we know the patches listed in
   SRC_URI have be applied, so drop any mangling of the patch. Note that
   as the existing approach hooked do_configure(), the source (including
   the patch) will not be redeployed, therefore the patch may remain in
   its mangled state.

C. The search regex of the sed line only accounted for the case where
   the source was freshly unpacked and patched, and `kernelname` was
   assigned `kernel-0`. This will not be the case under a rebuild of a
   new commit to the OpenBMC repository that doesn't touch u-boot, as
   the source will not be redeployed due to the caching behaviour.

D: We need an explicit dependency for the do_patch() phase on
   os-release:do_populate_sysroot to ensure that if os-release changes
   that we redo the patch phase to pick up the new image ID in the
   u-boot environment.

The change addresses all of the issues outlined above.

Change-Id: I01c95693053cb58aa0c0a90da04a03bca8eeec9e
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/common/recipes-bsp/u-boot/u-boot-aspeed.inc b/common/recipes-bsp/u-boot/u-boot-aspeed.inc
index e1eb738..56d1235 100644
--- a/common/recipes-bsp/u-boot/u-boot-aspeed.inc
+++ b/common/recipes-bsp/u-boot/u-boot-aspeed.inc
@@ -8,16 +8,15 @@
     file://0004-config-ast-common-Add-conditional-factory-reset-comm.patch \
     "
 
+do_patch[depends] = "os-release:do_populate_sysroot"
 
-python do_configure_aspeed_df-obmc-ubi-fs () {
+python do_patch_append_aspeed_df-obmc-ubi-fs () {
     version_id=do_get_versionID(d)
     d.setVar('VERSION_ID', version_id)
-    bb.build.exec_func("patch_uboot", d)
+    bb.build.exec_func("patch_kernelname", d)
 }
 
-patch_uboot () {
-	sed -i "s/kernel-0/kernel-${VERSION_ID}/g" \
-	${S}/patches/0003-config-ast-common-Add-bootopts-to-support-ubi-and-mt.patch &> /dev/null
-	sed -i "s/kernel-0/kernel-${VERSION_ID}/g" \
-	${S}/include/configs/ast-common.h &> /dev/null
+patch_kernelname () {
+    sed -ri "s/kernel-(0|[a-fA-F0-9]{8})/kernel-${VERSION_ID}/g" \
+    ${S}/include/configs/ast-common.h &> /dev/null
 }