[OE-core] [PATCH v3 1/1] image_overlay.bbclass: Add possibility to install overlays to image

Geoffrey Levillain geoffrey.levillain at smile.fr
Tue Mar 14 16:58:16 UTC 2017


There is often a need to add configuration files specific to an image,
with this class it's possible to fetch and install files from the
image recipe.

Fetching is set as noexec for images, but there is a need to fetch files
here. This class permit to fetch and unpack without the use of these
tasks in order to get your image-specific overlays to install.

This class must be inherited beside an image class (such as core-image).

Small example of usage in image recipe as it help to understand :
----------------------------------------------------------
FILESEXTRAPATHS_prepend := "${THISDIR}:"

DESCRIPTION = "An overlayable image"

OVERLAY_SRC_URI = "file://overlay.tar.gz file://overlay2"

OVERLAY_ROOT_DIRS = "overlay1 overlay2"

inherit core-image image_overlay
----------------------------------------------------------
(Where file://overlay2 refer to a directory, and overlay.tar.gz
cointain a directory named overlay1)

Signed-off-by: Geoffrey Levillain <geoffrey.levillain at smile.fr>
---
 meta/classes/image_overlay.bbclass | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 meta/classes/image_overlay.bbclass

diff --git a/meta/classes/image_overlay.bbclass b/meta/classes/image_overlay.bbclass
new file mode 100644
index 0000000000..ade2911410
--- /dev/null
+++ b/meta/classes/image_overlay.bbclass
@@ -0,0 +1,38 @@
+# When inherited by an image recipe, this class provide simple way to
+# put configuration files into rootfs.
+
+ROOTFS_POSTPROCESS_COMMAND_append = "install_overlay ; "
+
+python install_overlay() {
+    """Fetch and install overlays into rootfs
+    
+       Fetch overlays from OVERLAY_SRC_URI and copy the files
+       inside the folders listed in OVERLAY_ROOT_DIRS to rootfs.
+       
+       OVERLAY_ROOT_DIRS contains only names of folders, no path.
+       
+       OVERLAY_SRC_URI must be used to get dirs in OVERLAY_ROOT_DIRS
+       imported to the workdir, it's the same as SRC_URI, so it's 
+       possible to use distant repository, tarballs, etc.
+    """
+    workdir = d.getVar('WORKDIR', True)
+    rootfs = d.getVar('IMAGE_ROOTFS', True)
+    srcs = (d.getVar("OVERLAY_SRC_URI", True) or "").split()
+    overlay_root_dirs = (d.getVar('OVERLAY_ROOT_DIRS', True) or '').split()
+
+    fetcher = bb.fetch2.Fetch(srcs, d)
+    fetcher.download()
+    fetcher.unpack(workdir)
+
+    for i in range(len(overlay_root_dirs)):
+        fullpath = os.path.join(workdir, overlay_root_dirs[i])
+        
+        if not os.path.isdir(fullpath):
+            bb.fatal(fullpath +
+                     " : directory not found, please check your"\
+                     " OVERLAY_ROOT_DIRS and OVERLAY_SRC_URI variables.")
+            break
+        os.system("cp -dr " + os.path.join(fullpath, "*") + " " + rootfs)
+}
+
+do_rootfs[vardeps] += "OVERLAY_ROOT_DIRS OVERLAY_SRC_URI"
-- 
2.12.0




More information about the Openembedded-core mailing list