Skip to contentSkip to conversation

add --map-file option to map arbitrary files into physmem

RFC PATCH New [email protected] 1 participant 1 message Mar 19, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 add --map-file option to map arbitrary files into physmem

This is useful e.g. in conjunction with the MTD "phram" driver on embedded devices: a kernel can be booted with kexec and a root filesystem entirely in RAM to see if it works before writing it to flash. Something like this:

   kexec --map-file ./squashfs@104857600 --dtb ./dtb  --command-line "mtdparts=phram0:9945088(rootfs) phram.phram=phram0,104857600,9945088 memmap=9945088$104857600" vmlinux

My use case might be quite niche :-) but the implementation is I hope general enough that it could be used for other things as well. Or maybe it's impossibly general and shouldn't be offered at all without safety warnings.

Feedback welcome on any or all of style, correctness, general desirability and/or other. This is clearly not ever going to work with KEXEC_FILE_LOAD.

Daniel

---
 kexec/kexec.8 | 14 ++++++++++++-
 kexec/kexec.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
 kexec/kexec.h |  4 +++-
 3 files changed, 73 insertions(+), 2 deletions(-)
kexec/kexec.8 +13 -1
index 3a344c5..3140ccb 100644
@@ -143,10 +143,17 @@ into the current kernel.
 .B \-p\ (\-\-load\-panic)
 Load the new kernel for use on panic.
 .TP
-.BI \-t\ (\-\-type= type )
+.BI \-m\ (\-\-type= type )
 Specify that the new kernel is of this
 .I type.
 .TP
+.BI \-t\ (\-\-map-file= filename@addr )
+Read
+.I filename
+and arrange for it to be mapped into physical memory at the address
+.I addr.
+This option may be repeated if there are multiple files to map.
+.TP
 .BI \-s\ (\-\-kexec-file-syscall)
 Specify that the new KEXEC_FILE_LOAD syscall should be used exclusively.
 .TP
@@ -206,6 +213,11 @@ Reuse initrd from first boot.
 .BI \-\-print-ckr-size
 Print crash kernel region size, if available.
 
+.PP
+Options taking an
+.I addr
+parameter will accept a memory address written in hexadecimal (with leading
+0x), or octal (leading 0), or decimal (no leading sigil).
 
 .SH SUPPORTED KERNEL FILE TYPES AND OPTIONS
 .B Beoboot-x86
kexec/kexec.c +57 -0

87 lines not on this page · raw message

kexec/kexec.h +3 -1
index 0d820ad..78022b6 100644
@@ -224,6 +224,7 @@ extern int file_types;
 #define OPT_STATUS		'S'
 #define OPT_MEM_MIN             256
 #define OPT_MEM_MAX             257
+#define OPT_MAP_FILE		'm'
 #define OPT_REUSE_INITRD	258
 #define OPT_LOAD_PRESERVE_CONTEXT 259
 #define OPT_LOAD_JUMP_BACK_HELPER 260
@@ -258,8 +259,9 @@ extern int file_types;
 	{ "debug",		0, 0, OPT_DEBUG }, \
 	{ "status",		0, 0, OPT_STATUS }, \
 	{ "print-ckr-size",     0, 0, OPT_PRINT_CKR_SIZE }, \
+	{ "map-file",		1, 0, OPT_MAP_FILE }, \
 
-#define KEXEC_OPT_STR "h?vdfixyluet:pscaS"
+#define KEXEC_OPT_STR "h?vdfixyluet:pscaSm"
 
 extern void dbgprint_mem_range(const char *prefix, struct memory_range *mr, int nr_mr);
 extern void die(const char *fmt, ...)
Signature · 7 lines
2.38.1


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec