[Buildroot] [PATCH 1/1] support/scripts/genimage.sh: allow setting rootpath from parameters.

raphael.melotte at essensium.com raphael.melotte at essensium.com
Tue Sep 3 12:09:51 UTC 2019


From: Raphaël Mélotte <raphael.melotte at essensium.com>

Previously the rootpath was always set to $TARGET_DIR.
This patch allows using other directories as rootpath.

When you use genimage's mountpoints to generate an image with
multiple (non-empty) partitions, it does two things:
- copy $TARGET_DIR to $GENIMAGE_TMP/root
- move any mountpoint from GENIMAGE_TMP/root to $GENIMAGE_TMP/<mountpoint>

If you want to have an additional partition besides the rootfs, you
will have to make sure it's content is in $TARGET_DIR so that genimage
can find it.

If you also use rootfs generated by buildroot, you will end up
with two copies of the mountpoint: once in the rootfs itself, and once
in the partition using the mountpoint.

To better illustrate that behavior, here's an example configuration:

image myhome.ext4 {
      name = "myhome"
      ext4{}
      size = 1G
      mountpoint = "/home/myhome"
      # Files will be copied from '<rootpath>/home/myhome'
}

image sdcard.img {
	hdimage {
		gpt = true
	}

	partition rootfs {
		partition-type = 0x83
		image = "rootfs.ext4"
		# This the buildroot-generated rootfs, which already
		# contains the mountpoint
	}

	partition myhome {
		partition-type = 0x83
		size = 1G
		image = "myhome.ext4"
		# genimage will generate and fill the partition itself
	}
}

As genimage correctly moves mountpoint from
<rootpath>/root/<mountpoint> to <rootpath>/<mountpoint>, a possible
solution is to not use the rootfs generated by buildroot, but to use
genimage to generate it from <rootpath>/root directly. The problem is
that buildroot apply some additional fixups in the rootfs generation,
that genimage doesn't have (see THIS_IS_NOT_YOUR_ROOT_FILESYSTEM).

The remaining solutions are then to either:
- Use the buildroot-generated rootfs, and patch genimage.sh
  to allow other rootpaths to be used.
- Generate a filesystem for genimage, so that it's called under
  fakeroot and have all the fixups.

This patch implements the first solution.

Signed-off-by: Raphaël Mélotte <raphael.melotte at essensium.com>
---
 support/scripts/genimage.sh | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/support/scripts/genimage.sh b/support/scripts/genimage.sh
index 039b3fef1d..071298a4b5 100755
--- a/support/scripts/genimage.sh
+++ b/support/scripts/genimage.sh
@@ -4,22 +4,26 @@ die() {
   cat <<EOF >&2
 Error: $@
 
-Usage: ${0} -c GENIMAGE_CONFIG_FILE
+Usage: ${0} -c GENIMAGE_CONFIG_FILE [--rootpath ROOTPATH]
 EOF
   exit 1
 }
 
 # Parse arguments and put into argument list of the script
-opts="$(getopt -n "${0##*/}" -o c: -- "$@")" || exit $?
+opts="$(getopt -n "${0##*/}" -o c: -l rootpath: -- "$@")" || exit $?
 eval set -- "$opts"
 
 GENIMAGE_TMP="${BUILD_DIR}/genimage.tmp"
+GENIMAGE_ROOTPATH="${TARGET_DIR}"
 
 while true ; do
 	case "$1" in
 	-c)
 	  GENIMAGE_CFG="${2}";
 	  shift 2 ;;
+	--rootpath)
+	  GENIMAGE_ROOTPATH="${2}"
+	  shift 2 ;;
 	--) # Discard all non-option parameters
 	  shift 1;
 	  break ;;
@@ -33,8 +37,8 @@ done
 rm -rf "${GENIMAGE_TMP}"
 
 genimage \
-	--rootpath "${TARGET_DIR}"     \
-	--tmppath "${GENIMAGE_TMP}"    \
-	--inputpath "${BINARIES_DIR}"  \
-	--outputpath "${BINARIES_DIR}" \
+	--rootpath "${GENIMAGE_ROOTPATH}" \
+	--tmppath "${GENIMAGE_TMP}"       \
+	--inputpath "${BINARIES_DIR}"     \
+	--outputpath "${BINARIES_DIR}"    \
 	--config "${GENIMAGE_CFG}"
-- 
2.21.0




More information about the buildroot mailing list