DistroKit Mailinglist
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: distrokit@pengutronix.de
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>, ore@pengutronix.de
Subject: [DistroKit] [PATCH 3/3] mipsel: qemu-run: enable emulation of little endian barebox
Date: Thu, 22 Aug 2024 15:45:51 +0200	[thread overview]
Message-ID: <20240822134551.3176638-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240822134551.3176638-1-a.fatoum@pengutronix.de>

qemu-system-mipsel unlike GXemul requires that the 32-bit words inside
the barebox binary are swapped when not using the default big-endian
mode. Recent barebox versions generate an additional swapped image
that can be used, so let's import the barebox patch that enables it.

We can drop this patch again, when update to a barebox version that
includes the stdout-path changes, probably v2024.10.0 or later.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 ...generate-swapped-image-as-part-of-mu.patch | 102 ++++++++++++++++++
 .../patches/barebox-2021.06.0/series          |   1 +
 .../platform-mipsel/rules/barebox-malta.make  |   2 +-
 configs/platform-mipsel/run                   |   2 +-
 4 files changed, 105 insertions(+), 2 deletions(-)
 create mode 100644 configs/platform-mipsel/patches/barebox-2021.06.0/0003-MIPS-qemu-malta-generate-swapped-image-as-part-of-mu.patch

diff --git a/configs/platform-mipsel/patches/barebox-2021.06.0/0003-MIPS-qemu-malta-generate-swapped-image-as-part-of-mu.patch b/configs/platform-mipsel/patches/barebox-2021.06.0/0003-MIPS-qemu-malta-generate-swapped-image-as-part-of-mu.patch
new file mode 100644
index 000000000000..de704edffd40
--- /dev/null
+++ b/configs/platform-mipsel/patches/barebox-2021.06.0/0003-MIPS-qemu-malta-generate-swapped-image-as-part-of-mu.patch
@@ -0,0 +1,102 @@
+From 152bbdb7cfefab89132549ea83fb0b859c290e8a Mon Sep 17 00:00:00 2001
+From: Ahmad Fatoum <a.fatoum@pengutronix.de>
+Date: Fri, 4 Jun 2021 10:46:55 +0200
+Subject: [PATCH] MIPS: qemu-malta: generate swapped image as part of
+ multi-image build
+
+Having to manually swap the words in the MIPS Malta image for QEMU
+little endian emulation is annoying.
+
+Have the multi-image build for Malta generate a second .swapped
+image that can be readily used if needed.
+
+Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
+Link: https://lore.barebox.org/20210604084704.17410-5-a.fatoum@pengutronix.de
+Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
+---
+ Documentation/boards/mips/qemu-malta.rst | 16 ++++------------
+ images/.gitignore                        |  1 +
+ images/Makefile                          |  2 +-
+ images/Makefile.malta                    | 10 +++++++++-
+ 4 files changed, 15 insertions(+), 14 deletions(-)
+
+diff --git a/Documentation/boards/mips/qemu-malta.rst b/Documentation/boards/mips/qemu-malta.rst
+index e188ae8c642a..fd37d5edb229 100644
+--- a/Documentation/boards/mips/qemu-malta.rst
++++ b/Documentation/boards/mips/qemu-malta.rst
+@@ -10,31 +10,23 @@ QEMU run string:
+ 
+   qemu-system-mips -nodefaults -M malta -m 256 \
+       -device VGA -serial stdio -monitor null \
+-      -bios barebox-flash-image
++      -bios ./images/barebox-qemu-malta.img
+ 
+ 
+ Little-endian mode
+ ------------------
+ 
+-Running little-endian Malta is a bit tricky.
+ In little-endian mode the 32bit words in the boot flash image are swapped,
+ a neat trick which allows bi-endian firmware.
+ 
+-You have to swap words of ``zbarebox.bin`` image, e.g.:
+-
+-.. code-block:: sh
+-
+-  echo arch/mips/pbl/zbarebox.bin \
+-      | cpio --create \
+-      | cpio --extract --swap --unconditional
+-
+-QEMU run string:
++The barebox build generates a second ``./images/barebox-qemu-malta.img.swapped``
++image that can be used in this case, e.g.:
+ 
+ .. code-block:: sh
+ 
+   qemu-system-mipsel -nodefaults -M malta -m 256 \
+       -device VGA -serial stdio -monitor null \
+-      -bios barebox-flash-image
++      -bios ./images/barebox-qemu-malta.img.swapped
+ 
+ 
+ Using GXemul
+diff --git a/images/.gitignore b/images/.gitignore
+index eafdb44b5bdd..3a9a77dad16e 100644
+--- a/images/.gitignore
++++ b/images/.gitignore
+@@ -32,3 +32,4 @@ barebox.sum
+ *.mvebu1img
+ *.stm32
+ *.nmon
++*.swapped
+diff --git a/images/Makefile b/images/Makefile
+index c185982c17ed..cc330d957597 100644
+--- a/images/Makefile
++++ b/images/Makefile
+@@ -218,5 +218,5 @@ $(flash-list): $(image-y-path)
+ clean-files := *.pbl *.pblb *.map start_*.imximg *.img barebox.z start_*.kwbimg \
+ 	start_*.kwbuartimg *.socfpgaimg *.mlo *.t20img *.t20img.cfg *.t30img \
+ 	*.t30img.cfg *.t124img *.t124img.cfg *.mlospi *.mlo *.mxsbs *.mxssd \
+-	start_*.simximg start_*.usimximg *.zynqimg *.image
++	start_*.simximg start_*.usimximg *.zynqimg *.image *.swapped
+ clean-files += pbl.lds
+diff --git a/images/Makefile.malta b/images/Makefile.malta
+index 5739ec464092..96d7b86b1187 100644
+--- a/images/Makefile.malta
++++ b/images/Makefile.malta
+@@ -1,3 +1,11 @@
++quiet_cmd_bswap32_image = BSWAP4  $@
++      cmd_bswap32_image = cp $< $@ && \
++			  truncate -s %4 $@ && \
++			  objcopy -I binary --reverse-byte=4 $@
++
++$(obj)/%.img.swapped: $(obj)/%.img FORCE
++	$(call if_changed,bswap32_image)
++
+ pblb-$(CONFIG_BOARD_QEMU_MALTA) += start_qemu_malta
+ FILE_barebox-qemu-malta.img = start_qemu_malta.pblb
+-image-$(CONFIG_BOARD_QEMU_MALTA) += barebox-qemu-malta.img
++image-$(CONFIG_BOARD_QEMU_MALTA) += barebox-qemu-malta.img barebox-qemu-malta.img.swapped
+-- 
+2.39.2
+
diff --git a/configs/platform-mipsel/patches/barebox-2021.06.0/series b/configs/platform-mipsel/patches/barebox-2021.06.0/series
index b9b6f404fa41..4852ea3fdfaa 100644
--- a/configs/platform-mipsel/patches/barebox-2021.06.0/series
+++ b/configs/platform-mipsel/patches/barebox-2021.06.0/series
@@ -1,2 +1,3 @@
 0001-MIPS-dts-add-chosen-stdout-path-where-it-is-missing.patch
 0002-MIPS-qemu-malta-explicitly-set-stdout-path.patch
+0003-MIPS-qemu-malta-generate-swapped-image-as-part-of-mu.patch
diff --git a/configs/platform-mipsel/rules/barebox-malta.make b/configs/platform-mipsel/rules/barebox-malta.make
index 9143d47433c8..8eb765609ffe 100644
--- a/configs/platform-mipsel/rules/barebox-malta.make
+++ b/configs/platform-mipsel/rules/barebox-malta.make
@@ -48,7 +48,7 @@ BAREBOX_MALTA_CONF_OPT	:= \
 
 BAREBOX_MALTA_MAKE_OPT	:= $(BAREBOX_MALTA_CONF_OPT)
 
-BAREBOX_MALTA_IMAGES := images/barebox-qemu-malta.img
+BAREBOX_MALTA_IMAGES := images/barebox-qemu-malta.img.swapped
 BAREBOX_MALTA_IMAGES := $(addprefix $(BAREBOX_MALTA_BUILD_DIR)/,$(BAREBOX_MALTA_IMAGES))
 
 ifdef PTXCONF_BAREBOX_MALTA
diff --git a/configs/platform-mipsel/run b/configs/platform-mipsel/run
index 9ecf65b2e429..b6126531d8a8 100755
--- a/configs/platform-mipsel/run
+++ b/configs/platform-mipsel/run
@@ -72,7 +72,7 @@ QEMU_ARGS=( "${QEMU_ARGS[@]}" -rtc base=2021-01-01 )
 
 QEMU_LINUX_ARGS=( -kernel ${PTXDIST_PLATFORMDIR}/images/vmlinuz-malta -dtb ${PTXDIST_PLATFORMDIR}/images/qemu-malta.dtb-bb )
 # the barebox device tree has a state node for bootchooser
-QEMU_BAREBOX_ARGS=( -bios  ${PTXDIST_PLATFORMDIR}/images/barebox-qemu-malta.img )
+QEMU_BAREBOX_ARGS=( -bios  ${PTXDIST_PLATFORMDIR}/images/barebox-qemu-malta.img.swapped-malta )
 
 check_hd() {
 	if [ ! -e "${PTXDIST_PLATFORMDIR}/images/malta.hdimg" ]; then
-- 
2.39.2




  parent reply	other threads:[~2024-08-22 13:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-22 13:45 [DistroKit] [PATCH 1/3] MIPS(EL): barebox: add /chosen/stdout-path properties for all boards Ahmad Fatoum
2024-08-22 13:45 ` [DistroKit] [PATCH 2/3] MIPS: qemu-run: fix barebox Malta image name Ahmad Fatoum
2024-08-22 13:45 ` Ahmad Fatoum [this message]
2024-08-22 17:26 ` [DistroKit] [PATCH 1/3] MIPS(EL): barebox: add /chosen/stdout-path properties for all boards Oleksij Rempel
2024-08-22 17:39 ` Robert Schwebel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240822134551.3176638-3-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=distrokit@pengutronix.de \
    --cc=ore@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox