Message ID | 20240322141050.256793-2-Quirin.Gylstorff@siemens.com |
---|---|
State | Superseded, archived |
Headers | show |
Series | [v2,1/2] add new class to add files directly to the rootfs | expand |
On Fri, 2024-03-22 at 15:10 +0100, Quirin Gylstorff wrote: > From: Quirin Gylstorff <quirin.gylstorff@siemens.com> > > This allows to add files like the installer target directly > to rootfs without compressing the target file. It also reduces > the sstate size. > > Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com> > --- > meta/classes/rootfs-add-files.bbclass | 45 > +++++++++++++++++++++++++++ > 1 file changed, 45 insertions(+) > create mode 100644 meta/classes/rootfs-add-files.bbclass > > diff --git a/meta/classes/rootfs-add-files.bbclass > b/meta/classes/rootfs-add-files.bbclass > new file mode 100644 > index 00000000..dfee440f > --- /dev/null > +++ b/meta/classes/rootfs-add-files.bbclass > @@ -0,0 +1,45 @@ > +# This software is a part of ISAR. > +# Copyright (C) Siemens AG, 2024 > +# This class allows to add a file directly to > +# the rootfs. > +# An example usecase would be an installer which > +# contains an complete rootfs added with multiconfig. > +ROOTFS_INSTALL_COMMAND =+ "rootfs_add_files" > +ROOTFS_ADDITIONAL_FILES ??= "" > + > +# ROOTFS_ADDITIONAL_FILES ??= "installer-target" > +# > +# ROOTFS_ADDITIONAL_FILE_installer-target[source] = \ > +# "${DEPLOY_DIR_IMAGE}/${IMG_DATA_FILE}.${IMAGE_DATA_POSTFIX}" > +# ROOTFS_ADDITIONAL_FILE_installer-target[destination] = \ > +# "/install/${IMG_DATA_FILE}.${IMAGE_DATA_POSTFIX}" > + > + > +python rootfs_add_files() { > + import os > + if d.getVar("SOURCE_DATE_EPOCH") != None: > + os.environ["SOURCE_DATE_EPOCH"] = > d.getVar("SOURCE_DATE_EPOCH") > + > + postprocess_additional_files = > d.getVar('ROOTFS_ADDITIONAL_FILES').split() > + rootfsdir = d.getVar("ROOTFSDIR") > + > + for entry in postprocess_additional_files: > + additional_file_entry = f"ROOTFS_ADDITIONAL_FILE_{entry}" > + destination = d.getVarFlag(additional_file_entry, > "destination") or "" > + source = d.getVarFlag(additional_file_entry, "source") or "" > + if os.path.exists(f"{rootfsdir}/{destination}"): > + bb.process.run([ "/usr/bin/rm", "-f", f"{destination}"]) > + > + # empty source creates only an empty destination file > + if not source: > + dest_dir = os.path.dirname(destination) > + bb.process.run(["sudo", "-E", "/usr/bin/install", "-d", > "-m", "600", f"{rootfsdir}/{dest_dir}" ]) > + bb.process.run(["sudo", "-E", "/usr/bin/touch", > f"{rootfsdir}/{destination}" ]) > + return > + > + if not os.path.exists(f"{source}"): > + bb.error(f"{source} does not exists and cannot be copied > to the rootfs!") > + # no recursive copy only single files > + bb.process.run(["sudo", "-E", "/usr/bin/install", "-D", "- > m", "600", f"{source}", f"{rootfsdir}/{destination}" ]) Hi Quirin, we also need to copy the .bmap file (if available): bmaptool: info: no bmap given, copy entire image to '/dev/sda' Felix > +} > +ROOTFS_INSTALL_COMMAND += "rootfs_add_files"
diff --git a/meta/classes/rootfs-add-files.bbclass b/meta/classes/rootfs-add-files.bbclass new file mode 100644 index 00000000..dfee440f --- /dev/null +++ b/meta/classes/rootfs-add-files.bbclass @@ -0,0 +1,45 @@ +# This software is a part of ISAR. +# Copyright (C) Siemens AG, 2024 +# This class allows to add a file directly to +# the rootfs. +# An example usecase would be an installer which +# contains an complete rootfs added with multiconfig. +ROOTFS_INSTALL_COMMAND =+ "rootfs_add_files" +ROOTFS_ADDITIONAL_FILES ??= "" + +# ROOTFS_ADDITIONAL_FILES ??= "installer-target" +# +# ROOTFS_ADDITIONAL_FILE_installer-target[source] = \ +# "${DEPLOY_DIR_IMAGE}/${IMG_DATA_FILE}.${IMAGE_DATA_POSTFIX}" +# ROOTFS_ADDITIONAL_FILE_installer-target[destination] = \ +# "/install/${IMG_DATA_FILE}.${IMAGE_DATA_POSTFIX}" + + +python rootfs_add_files() { + import os + if d.getVar("SOURCE_DATE_EPOCH") != None: + os.environ["SOURCE_DATE_EPOCH"] = d.getVar("SOURCE_DATE_EPOCH") + + postprocess_additional_files = d.getVar('ROOTFS_ADDITIONAL_FILES').split() + rootfsdir = d.getVar("ROOTFSDIR") + + for entry in postprocess_additional_files: + additional_file_entry = f"ROOTFS_ADDITIONAL_FILE_{entry}" + destination = d.getVarFlag(additional_file_entry, "destination") or "" + source = d.getVarFlag(additional_file_entry, "source") or "" + if os.path.exists(f"{rootfsdir}/{destination}"): + bb.process.run([ "/usr/bin/rm", "-f", f"{destination}"]) + + # empty source creates only an empty destination file + if not source: + dest_dir = os.path.dirname(destination) + bb.process.run(["sudo", "-E", "/usr/bin/install", "-d", "-m", "600", f"{rootfsdir}/{dest_dir}" ]) + bb.process.run(["sudo", "-E", "/usr/bin/touch", f"{rootfsdir}/{destination}" ]) + return + + if not os.path.exists(f"{source}"): + bb.error(f"{source} does not exists and cannot be copied to the rootfs!") + # no recursive copy only single files + bb.process.run(["sudo", "-E", "/usr/bin/install", "-D", "-m", "600", f"{source}", f"{rootfsdir}/{destination}" ]) +} +ROOTFS_INSTALL_COMMAND += "rootfs_add_files"