Bug 4072 - Avoid circular dependencies when building initramfs that includes kernel modules
Summary: Avoid circular dependencies when building initramfs that includes kernel modules
Status: VERIFIED FIXED
Alias: None
Product: OE-Core
Classification: Build System, Metadata & Runtime
Component: deployment (show other bugs)
Version: 1.4
Hardware: x86 Multiple
: High enhancement
Target Milestone: 1.5 M4
Assignee: Bruce Ashfield
QA Contact:
URL:
Whiteboard: 11 March 2014: resetting doc flag to ...
Depends on:
Blocks: 4106 4662
  Show dependency tree
 
Reported: 2013-03-21 14:54 UTC by Mark Hatle
Modified: 2014-03-11 13:32 UTC (History)
8 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: Done (doc changes complete)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Hatle 2013-03-21 14:54:10 UTC
Currently if you build an initramfs, and have a kernel attempt to use it -- you can end up with a circular dependency if the initramfs includes kernel modules.

There needs to be a way to generate the kernel components, then use these components in the initramfs and then rebuild/relink? the kernel with the initramfs avoiding these types of circular dependency problems.
Comment 1 Bruce Ashfield 2013-06-12 15:03:44 UTC
Bumping this to M3, since further design is required.
Comment 2 Darren Hart 2013-08-15 14:50:08 UTC
Hey Bruce, can you provide an update? Cutoff for M4 is Aug 25th.
Comment 3 Bruce Ashfield 2013-08-15 15:02:39 UTC
I'll check with a few people and update the progress.
Comment 4 Bruce Ashfield 2013-08-16 19:20:31 UTC
We are doing a RFC implementation. Jason Wessel can update when things are ready to post.
Comment 5 Jason Wessel 2013-08-19 19:14:16 UTC
A solution posted for review to the oe-core mailling list.  Patch is posted with patch header:

    kernel.bbclass,image.bbclass: Implement kernel INITRAMFS dependency and bundling
    
    This patch aims to fix the following two cases for the INITRAMFS generation.
      1) Allow an image recipe to specify a paired INITRAMFS recipe such
         as core-image-minimal-initramfs.  This allows building a base
         image which always generates the needed initramfs image in one step
      2) Allow building a single binary which contains a kernel and
         the initramfs.
    
    A key requirement of the initramfs is to be able to add kernel
    modules.  The current implementation of the INITRAMFS_IMAGE variable
    has a circular dependency when using kernel modules in the initramfs
    image.bb file that is caused by kernel.bbclass trying to build the
    initramfs before the kernel's do_install rule.
    
    The solution for this problem is to have the kernel's
    do_bundle_initramfs_image task depend on the do_rootfs from the
    INITRAMFS_IMAGE and not some intermediate point.  The image.bbclass
    will also sets up dependencies to make the initramfs creation task run
    last.
    
    The code to bundle the kernel and initramfs together has been added.
    At a high level, all it is doing is invoking a second compilation of
    the kernel but changing the value of CONFIG_INITRAMFS_SOURCE to point
    to the generated initramfs from the image recipe.
Comment 7 Darren Hart 2013-08-29 14:37:19 UTC
Bruce, where are we on this?
Comment 8 Bruce Ashfield 2013-08-29 14:53:40 UTC
Jason is running with it, I'll bring him into the loop. The first set of patches were rejected,
so we are re-evaluating.
Comment 9 Bruce Ashfield 2013-09-13 04:27:49 UTC
We are at a standstill on this issue. We don't have any clear direction
to solve it after the initial submission of the changes. 

I suggest moving this to 1.6.
Comment 10 Bruce Ashfield 2013-10-09 00:18:33 UTC
merged to oe-core master
Comment 11 Stoicescu Cornel 2013-10-09 11:06:16 UTC
Is this in poky dora? Please paste the commit link.
Comment 13 Stoicescu Cornel 2013-10-16 15:30:10 UTC
Hello,

Being a high feature, can you please help us with a compatible test scenario?

I cannot find INITRAMFS_IMAGE and INITRAMFS_IMAGE_BUNDLE being used in poky or meta-intel. What I do see is INITRD_IMAGE ?= "core-image-minimal-initramfs" being used in image-live.bbclass .

I also tried testing the resulting artifacts with runqemu but encountered issues:

1) runqemu does not recognise the initramfs format:
Error: unknown file arg [tmp/deploy/images/qemux86-64/core-image-minimal-initramfs-qemux86-64.cpio.gz]

2) using INITRAMFS_IMAGE_BUNDLE = "1", the bot process hangs after "mounting media"

Tested with qemux86-64 machine on dora/master:faf8f8660fae26a14578738b642fdeb08bcb9d54
Comment 14 Bruce Ashfield 2013-10-17 19:32:38 UTC
(In reply to comment #13)
> Hello,
> 
> Being a high feature, can you please help us with a compatible test scenario?
> 
> I cannot find INITRAMFS_IMAGE and INITRAMFS_IMAGE_BUNDLE being used in poky
> or meta-intel. What I do see is INITRD_IMAGE ?=
> "core-image-minimal-initramfs" being used in image-live.bbclass .
> 
> I also tried testing the resulting artifacts with runqemu but encountered
> issues:
> 
> 1) runqemu does not recognise the initramfs format:
> Error: unknown file arg
> [tmp/deploy/images/qemux86-64/core-image-minimal-initramfs-qemux86-64.cpio.
> gz]
> 
> 2) using INITRAMFS_IMAGE_BUNDLE = "1", the bot process hangs after "mounting
> media"
> 
> Tested with qemux86-64 machine on
> dora/master:faf8f8660fae26a14578738b642fdeb08bcb9d54

Jason W posted the test steps with the series on the list. Have we tried those ?
Comment 15 Stoicescu Cornel 2013-11-25 09:22:09 UTC
Hello. I could not find those steps. Can you please direct us to the specific mails that contain them (or their titles).

Thank you!
Comment 16 Jason Wessel 2013-12-11 05:49:43 UTC
The real use case behind this feature is a bit more complex in that it is aimed at customized images where the initramfs comes from one recipe and it will pivot root to the real file system.

There is a simple way to test this feature though:

Add the following to local.conf:

INITRAMFS_IMAGE_BUNDLE = "1"
INITRAMFS_IMAGE = "core-image-minimal-initramfs"

Now bitbake core-image-minimal

You can boot the resulting image as follows:

kvm -nographic -kernel tmp-eglibc/deploy/images/qemux86-64/bzImage-initramfs-qemux86-64.bin -append "console=ttyS0,115200 rdinit=/bin/sh"

Next you can add a kernel dependency to the initramfs to test the circular dependency logic.  For this you can add the kernel-module-reiserfs to the core-image-minimal-initramfs.bb.

========== Example ====================

--- a/meta/recipes-core/images/core-image-minimal-initramfs.bb
+++ b/meta/recipes-core/images/core-image-minimal-initramfs.bb
@@ -3,7 +3,7 @@ DESCRIPTION = "Small image capable of booting a device. The kernel includes \
 the Minimal RAM-based Initial Root Filesystem (initramfs), which finds the \
 first 'init' program more efficiently."
 
-IMAGE_INSTALL = "initramfs-live-boot initramfs-live-install initramfs-live-install-efi busybox udev base-passwd"
+IMAGE_INSTALL = "initramfs-live-boot initramfs-live-install initramfs-live-install-efi busybox udev base-passwd kernel-module-reiserfs"
 
 # Do not pollute the initrd image with rootfs features
 IMAGE_FEATURES = ""

========== End Example ====================

Now bitbake the core-image-minimal again, and boot it with kvm or qemu.

kvm -nographic -kernel tmp-eglibc/deploy/images/qemux86-64/bzImage-initramfs-qemux86-64.bin -append "console=ttyS0,115200 rdinit=/bin/sh"

# Finally inspect the kernel module is there

/ # find /lib/modules/ |grep reiserfs.ko
/lib/modules/3.10.19-yocto-standard/kernel/fs/reiserfs/reiserfs.ko

---

With this functionality it is possible to generate images which have a kernel and initramfs which containes kernel modules and use it to attach to other file systems or pivot root etc...
Comment 17 Stoicescu Cornel 2013-12-11 11:01:08 UTC
I was able to test this with the instructions Jason gave. I used qemu to test it instead of kvm.

One more thing needs to be taken care of: documentation.

Scott, is there documentation for this in the manual? All the documentation I was able to find is in the poky sources, inside meta-yocto/conf/local.conf.sample.extended . Is this enough or do we need to create a manual entry?
Comment 18 Jason Wessel 2013-12-11 11:56:09 UTC
For clarity I pulled in the clip from the oe-core's:
meta/conf/local.conf.sample.extended

---------- start ------------
#
# Kernel image features
#
# The INITRAMFS_IMAGE image variable will cause an additional recipe to
# be built as a dependency to the what ever rootfs recipe you might be
# using such as core-image-sato.  The initramfs might be needed for
# the initial boot of of the target system such as to load kernel
# modules prior to mounting the root file system.
#
# INITRAMFS_IMAGE_BUNDLE variable controls if the image recipe
# specified by the INITRAMFS_IMAGE will be run through an extra pass
# through the kernel compilation in order to build a single binary
# which contains both the kernel image and the initramfs.  The
# combined binary will be deposited into the tmp/deploy directory.
# NOTE: You can set INITRAMFS_IMAGE in an image recipe, but
#       INITRAMFS_IMAGE_BUNDLE can only be set in a conf file.
#
#INITRAMFS_IMAGE = "core-image-minimal-initramfs"
#INITRAMFS_IMAGE_BUNDLE = "1"
---------- end ------------

If something more is needed or you have questions, please let me know.
Comment 19 Scott Rifenbark 2013-12-23 20:04:18 UTC
Right now we document only the INITRAMFS_FSTYPES variable in our reference manual.  The fix described in this bug seems to also involve the INITRAMFS_IMAGE_BUNDLE and INITRAMFS_IMAGE variables.  So, I need some descriptions of these variables in the context of how a user would use them (not just for this solution, but for the variables in general).  

Another variable we probably should create an entry for is CONFIG_INITRAMFS_SOURCE.  So, I need some information for that.  

Adding variable entries for INITRAMFS_IMAGE_BUNDLE, CONFIG_INITRAMFS_SOURCE and INITRAMFS_IMAGE would be part of the documentation change we need to fully resolve this bug.

I put in an explanation of the circular dependency problem and how to get around it through use of the variable(s) we add.  If that is sufficient, we don't need to create any separate usage sections.  However, if we feel we need a whole separate section on creating initram type stuff... then we need more.

Comments?

Thanks,
Scott
Comment 20 Bruce Ashfield 2014-01-02 04:15:54 UTC
Scott,

Your plan is fine with me. Just the basic documentation updates you are
describing are good enough.

A full section about build, deployment and boot would be appropriate 
(if they don't already exist), but with upcoming changes to deployment
in Yocto 1.6, it would be better to wait until then for a bigger doc
update.

Bruce

(In reply to comment #19)
> Right now we document only the INITRAMFS_FSTYPES variable in our reference
> manual.  The fix described in this bug seems to also involve the
> INITRAMFS_IMAGE_BUNDLE and INITRAMFS_IMAGE variables.  So, I need some
> descriptions of these variables in the context of how a user would use them
> (not just for this solution, but for the variables in general).  
> 
> Another variable we probably should create an entry for is
> CONFIG_INITRAMFS_SOURCE.  So, I need some information for that.  
> 
> Adding variable entries for INITRAMFS_IMAGE_BUNDLE, CONFIG_INITRAMFS_SOURCE
> and INITRAMFS_IMAGE would be part of the documentation change we need to
> fully resolve this bug.
> 
> I put in an explanation of the circular dependency problem and how to get
> around it through use of the variable(s) we add.  If that is sufficient, we
> don't need to create any separate usage sections.  However, if we feel we
> need a whole separate section on creating initram type stuff... then we need
> more.
> 
> Comments?
> 
> Thanks,
> Scott
Comment 21 Scott Rifenbark 2014-01-02 14:50:32 UTC
Hi 

I have added two new variable descriptions to the ref-manual and they need to be looked at.  I took some guesses on how to describe these based on 'git grep' results I go inside poky.  Here are the links:

http://www.yoctoproject.org/docs/1.6/ref-manual/ref-manual.html#var-INITRAMFS_IMAGE

http://www.yoctoproject.org/docs/1.6/ref-manual/ref-manual.html#var-INITRAMFS_IMAGE_BUNDLE

Regarding the CONFIG_INITRAMFS_SOURCE variable.  I see that it is used in the kernel.bbclass file but I don't understand it.  Comment #5 below from Jason says that it simply points to the generated initramfs from the additional recipe.  Is that it?  Is this all automated so that if a user includes the kernel.bbclass and then sets INITRAMFS_IMAGE and specifies INITRAMFS_IMAGE_BUNDLE the CONFIG_INITRAMFS_SOURCE variable is automatically handled without any user intervention?

Note that I have not mentioned the circular dependencies issue at all yet in the INITRAMFS_IMAGE and INITRAMFS_IMAGE_BUNDLE variable descriptions.  I need to add that in still.  I would like to get the basic descriptions of these variables nailed down first though. 

thanks,
Scott
Comment 22 Stoicescu Cornel 2014-02-18 09:08:58 UTC
Can we have an update on the documentation status? Is the current documentation enough? Also, is it correct?
Comment 23 Scott Rifenbark 2014-02-20 18:55:54 UTC
Before we can close the doc portion of this, I need the following:

* A description of the CONFIG_INITRAMFS_SOURCE variable.

* An explanation describing what steps the user needs to take to avoid the circular dependency.  Presumably, the user is going to set some magic combination of the CONFIG_INITRAMFS_SOURCE, INITRAMFS_IMAGE and INITRAMFS_IMAGE_BUNDLE variables?

I can't close this doc part until I have this information. 

Thanks, 
Scott
Comment 24 Bruce Ashfield 2014-03-06 16:18:00 UTC
(In reply to comment #23)
> Before we can close the doc portion of this, I need the following:
> 
> * A description of the CONFIG_INITRAMFS_SOURCE variable.

This is the kernel Kconfig variable, passed via the build system as an
environment variable to the kernel build. The details here are a cut and
paste from the kernel Kconfig file:

config INITRAMFS_SOURCE
        string "Initramfs source file(s)"
        default ""
        help
          This can be either a single cpio archive with a .cpio suffix or a
          space-separated list of directories and files for building the
          initramfs image.  A cpio archive should contain a filesystem archive
          to be used as an initramfs image.  Directories should contain a
          filesystem layout to be included in the initramfs image.  Files
          should contain entries according to the format described by the
          "usr/gen_init_cpio" program in the kernel tree.

          When multiple directories and files are specified then the
          initramfs image will be the aggregate of all of them.

> 
> * An explanation describing what steps the user needs to take to avoid the
> circular dependency.  Presumably, the user is going to set some magic
> combination of the CONFIG_INITRAMFS_SOURCE, INITRAMFS_IMAGE and
> INITRAMFS_IMAGE_BUNDLE variables?

They don't need to set the initramfs source, from the comments in the
code is the rest of the answer:

+#
+# Kernel image features
+#
+# The INITRAMFS_IMAGE image variable will cause an additional recipe to
+# be built as a dependency to the what ever rootfs recipe you might be
+# using such as core-image-sato.  The initramfs might be needed for
+# the initial boot of of the target system such as to load kernel
+# modules prior to mounting the root file system.
+#
+# INITRAMFS_IMAGE_BUNDLE variable controls if the image recipe
+# specified by the INITRAMFS_IMAGE will be run through an extra pass
+# through the kernel compilation in order to build a single binary
+# which contains both the kernel image and the initramfs.  The
+# combined binary will be deposited into the tmp/deploy directory.
+# NOTE: You can set INITRAMFS_IMAGE in an image recipe, but
+#       INITRAMFS_IMAGE_BUNDLE can only be set in a conf file.
+#
+#INITRAMFS_IMAGE = "core-image-minimal-initramfs"
+#INITRAMFS_IMAGE_BUNDLE = "1"


> 
> I can't close this doc part until I have this information. 
> 
> Thanks, 
> Scott
Comment 25 Scott Rifenbark 2014-03-07 22:48:49 UTC
Hi, 

I have made some additional documentation changes to hopefully close this bug out.  I added the variable entry in the glossary for CONFIG_INITRAMFS_SOURCE.  Please look this over at http://www.yoctoproject.org/docs/1.6/ref-manual/ref-manual.html#var-CONFIG_INITRAMFS_SOURCE.  It basically says that this identifies the initramfs source.

The other change was to the INITRAMFS_IMAGE_BUNDLE variable.  I added some to the first paragraph of this variable explaining how it can be used to avoid the circular dependency issue.  Please look it over at http://www.yoctoproject.org/docs/1.6/ref-manual/ref-manual.html#var-INITRAMFS_IMAGE_BUNDLE.

It seems to me that this should do it for the docs.  I could be wrong though so comment as needed.

Thanks, 
Scott
Comment 26 Bruce Ashfield 2014-03-08 02:54:02 UTC
The doc updates look fine to me.

Bruce

(In reply to comment #25)
> Hi, 
> 
> I have made some additional documentation changes to hopefully close this
> bug out.  I added the variable entry in the glossary for
> CONFIG_INITRAMFS_SOURCE.  Please look this over at
> http://www.yoctoproject.org/docs/1.6/ref-manual/ref-manual.html#var-
> CONFIG_INITRAMFS_SOURCE.  It basically says that this identifies the
> initramfs source.
> 
> The other change was to the INITRAMFS_IMAGE_BUNDLE variable.  I added some
> to the first paragraph of this variable explaining how it can be used to
> avoid the circular dependency issue.  Please look it over at
> http://www.yoctoproject.org/docs/1.6/ref-manual/ref-manual.html#var-
> INITRAMFS_IMAGE_BUNDLE.
> 
> It seems to me that this should do it for the docs.  I could be wrong though
> so comment as needed.
> 
> Thanks, 
> Scott
Comment 27 Scott Rifenbark 2014-03-11 13:09:21 UTC
Thanks Bruce, 

I am resetting the doc flag on this bug to "Done".

Scott
Comment 28 Stoicescu Cornel 2014-03-11 13:32:31 UTC
Thank you all for the work on the feature and its documentation! Setting to VERIFIED.