scripts/qemu-binfmt-conf.sh: add bFLT handler registration
PATCH v3 1/1 scripts/qemu-binfmt-conf.sh: add bFLT handler registration
bFLT format header doesn't have enough information to register a handler for a specific architecture. Add switch -f / --flat that registers one of the qemu binaries as a handler for bFLT executable images.
---
Changes v2->v3:
- fix bFLT in the patch subject
Changes v1->v2:
- drop unintended changes to dtc;
scripts/qemu-binfmt-conf.sh | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
scripts/qemu-binfmt-conf.sh +30 -2
@@ -132,6 +132,9 @@ or1k_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\ or1k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' or1k_family=or1k +flat_magic='bFLT\x00\x00\x00\x04' +flat_mask='\xff\xff\xff\xff\xff\xff\xff\xff' + qemu_get_family() { cpu=${HOST_ARCH:-$(uname -m)} case "$cpu" in
@@ -170,6 +173,7 @@ usage() { Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU] [--help][--credential yes|no][--exportdir PATH] [--persistent yes|no][--qemu-suffix SUFFIX] + [--flat CPU] Configure binfmt_misc to use qemu interpreter
@@ -188,7 +192,9 @@ Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU] calculated according to the binary to interpret --persistent: if yes, the interpreter is loaded when binfmt is configured and remains in memory. All future uses - are cloned from the open file. + are cloned from the open file + --flat: register QEMU for this CPU architecture as a handler + for the bFLT executable format. To import templates with update-binfmts, use :
@@ -311,6 +317,13 @@ qemu_set_binfmts() { $BINFMT_SET fi done + if [ -n "$QEMU_FLAT" ] ; then + cpu="${QEMU_FLAT}_bflt" + qemu="$QEMU_PATH/qemu-$QEMU_FLAT" + magic=$flat_magic + mask=$flat_mask + $BINFMT_SET + fi } CHECK=qemu_check_bintfmt_misc
@@ -324,7 +337,7 @@ CREDENTIAL=no PERSISTENT=no QEMU_SUFFIX="" -options=$(getopt -o ds:Q:S:e:hc:p: -l debian,systemd:,qemu-path:,qemu-suffix:,exportdir:,help,credential:,persistent: -- "$@") +options=$(getopt -o ds:Q:S:e:hc:p:f: -l debian,systemd:,qemu-path:,qemu-suffix:,exportdir:,help,credential:,persistent:,flat: -- "$@") eval set -- "$options" while true ; do
@@ -380,6 +393,21 @@ while true ; do shift PERSISTENT="$1" ;; + -f|--flat) + shift + QEMU_FLAT="$1" + for cpu in ${qemu_target_list} ; do + if [ "$cpu" = "$1" ] ; then + break + fi + done + + if [ "$cpu" != "$1" ] ; then + echo "ERROR: unknown CPU \"$1\"" 1>&2 + usage + exit 1 + fi + ;; *) break ;;
Signature · 1 line
2.11.0
Quoted 49 lines · Max Filippov
bFLT format header doesn't have enough information to register a handler for a specific architecture. Add switch -f / --flat that registers one of the qemu binaries as a handler for bFLT executable images.
Signed-off-by Max Filippov <[email protected]>---
Changesv2->v3:
- fix bFLT in the patch subjectChanges
v1->v2:
- drop unintended changes to dtc;scripts/qemu-binfmt-conf.sh | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)scripts/qemu-binfmt-conf.sh +7
-1@@ -132,6 +132,9 @@ or1k_magic='\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\ or1k_mask='\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff' or1k_family=or1k +flat_magic='bFLT\x00\x00\x00\x04' +flat_mask='\xff\xff\xff\xff\xff\xff\xff\xff' + qemu_get_family() { cpu=${HOST_ARCH:-$(uname -m)} case "$cpu" in@@ -170,6 +173,7 @@ usage() { Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU] [--help][--credential yes|no][--exportdir PATH] [--persistent yes|no][--qemu-suffix SUFFIX] + [--flat CPU] Configure binfmt_misc to use qemu interpreter@@ -188,7 +192,9 @@ Usage: qemu-binfmt-conf.sh [--qemu-path PATH][--debian][--systemd CPU] calculated according to the binary to interpret --persistent: if yes, the interpreter is loaded when binfmt is configured and remains in memory. All future uses - are cloned from the open file. + are cloned from the open file + --flat: register QEMU for this CPU architecture as a handler + for the bFLT executable format. To import templates with update-binfmts, use :
scripts/qemu-binfmt-conf.sh qemu_set_binfmts() { · line 321
Quoted 5 lines
scripts/qemu-binfmt-conf.sh +2
-0@@ -311,6 +317,13 @@ qemu_set_binfmts() { $BINFMT_SET fi done + if [ -n "$QEMU_FLAT" ] ; then + cpu="${QEMU_FLAT}_bflt"
I think you don't need this, you can let the user to use "--qemu-suffix" for that.
Thanks,
Laurent
Quoted 9 lines · Max Filippov
bFLT format header doesn't have enough information to register a handler for a specific architecture. Add switch -f / --flat that registers one of the qemu binaries as a handler for bFLT executable images.
Signed-off-by Max Filippov <[email protected]>---
Changesv2->v3:
- fix bFLT in the patch subject
Quoted 5 lines
Changes
v1->v2:
- drop unintended changes to dtc;scripts/qemu-binfmt-conf.sh | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)
BTW, I'm not sure it's the good way to do that. The script has been written with ELF in mind and no other alternative format.
Perhaps we can add a format parameter, like "--format elf" (default), "--format bflt" and then take the availabled CPU and mask/magic from the list corresponding for the selected format.
And then rename qemu_set_binfmts() to qemu_elf_set_binfmts(), add function qemu_bflt_set_binfmt() and call the one you you need according the format you have selected.
Somehing like:
FORMAT_BINFMT_MISC_SET=qemu_elf_set_binfmts
...
-F|--format)
shift
FORMAT_BINFMT_MISC_SET=qemu_$1_set_binfmts
;;...
$CHECK
$FORMAT_BINFMT_MISC_SET
and then
qemu_bflt_set_binfmts()
{
for cpu in ${qemu_target_list} ; do
magic='bFLT\x00\x00\x00\x04'
mask='\xff\xff\xff\xff\xff\xff\xff\xff'
qemu="$QEMU_PATH/qemu-$cpu"
qemu="$qemu$QEMU_SUFFIX"
$BINFMT_SET done
}
Then with --systemd you provide only the cpu you want to generate, with --debian you use update-binfmts to select the only one to import, for /proc case we could add another parameter to only register one interpreter (--proc CPU ?)
Thanks,
Laurent