resources: add ability to build squashfs images
Change-Id: I51982d2f9ae4cba8f2a5d54e0583e4a70118abb8
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5-resources/+/36676
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Maintainer: Jason Lowe-Power <power.jg@gmail.com>
Tested-by: Jason Lowe-Power <power.jg@gmail.com>
diff --git a/README.md b/README.md
index 909dcda..316620e 100755
--- a/README.md
+++ b/README.md
@@ -288,6 +288,29 @@
`aarch64/semihost_exit` only builds for baremetal, as semihosting is not
available on userland.
+The `simple` directory is also able to generate squashfs images containing
+only a single userland executable at `/sbin/init` for any of the userland
+executables. This can be done with a command of type:
+
+ make ISA=aarch64 out/aarch64/squashfs/m5_exit.squashfs
+
+Squashfs is a filesystem type that the Linux kernel understands natively,
+exactly like ext4, except that it is a bit more convenient to create, and
+write-only.
+
+You can therefore give those squashfs images to gem5 exactly as you
+would give a normal ext4 raw image, by pointing to it for example with
+`fs.py --disk-image=m5_exit.squashfs` as shown at:
+https://www.gem5.org/documentation/general_docs/fullsystem/building_arm_kernel
+Linux will then run the given userland executable after Linux boots as the
+init program.
+
+The initial motivation for this was to generate simple test images for
+Linux boot.
+
+Since this is a less common use case, squashfs images are not currently
+generated by any single phony target all at once.
+
## Pre-build binaries
<http://dist.gem5.org/dist/v20-1/test-progs/pthreads/x86/test_pthread_create_seq>
diff --git a/src/simple/Makefile b/src/simple/Makefile
index f3113aa..ed015f7 100644
--- a/src/simple/Makefile
+++ b/src/simple/Makefile
@@ -89,6 +89,8 @@
OUT_DIR_BASE = out
OUT_DIR = $(OUT_DIR_BASE)/$(ISA)
OUT_BARE_DIR = $(OUT_DIR)/bare
+OUT_SQUASHFS_DIR = $(OUT_DIR)/squashfs
+OUT_SQUASHFS_EXT = .squashfs
OUT_USER_DIR = $(OUT_DIR)/user
OBJ_EXT = .o
OUT_EXT = .out
@@ -131,6 +133,7 @@
# Calculated values.
BARE_OUTS = $(addprefix $(OUT_BARE_DIR)/, $(addsuffix $(OUT_EXT), $(BARE_INS) $(addprefix $(ISA)/,$(ISA_BARE_INS))))
+SQUASHFS_OUTS = $(addprefix $(OUT_USER_DIR)/, $(addsuffix $(OUT_EXT), $(USER_INS)))
USER_OUTS = $(addprefix $(OUT_USER_DIR)/, $(addsuffix $(OUT_EXT), $(USER_INS)))
.PHONY: all bare clean mkdir user
@@ -156,6 +159,11 @@
$(OUT_USER_DIR)/%$(OUT_EXT): %$(IN_EXT_C) $(M5OP_OBJ)
$(CC) $(CFLAGS_USER) -o '$@' $^ $(LDFLAGS_USER)
+$(OUT_SQUASHFS_DIR)/%$(OUT_SQUASHFS_EXT): $(OUT_USER_DIR)/%$(OUT_EXT)
+ mkdir -p '$(basename $@)/sbin'
+ cp '$<' '$(basename $@)/sbin/init'
+ mksquashfs '$(basename $@)' '$@'
+
$(OUT_BARE_DIR)/%$(OUT_EXT): %$(IN_EXT_CXX) $(M5OP_OBJ) $(BOOTLOADER_OBJ)
$(CXX) $(CXXFLAGS_BARE) -o '$@' $^