From: Magnus Lindholm <linmag7@gmail.com>
To: davem@davemloft.net, andreas@gaisler.com
Cc: sam@ravnborg.org, sparclinux@vger.kernel.org,
linux-kernel@vger.kernel.org, linmag7@gmail.com,
stable@vger.kernel.org
Subject: [PATCH 05/18] sparc32: preserve both LEON PROM character-output conventions
Date: Thu, 26 Nov 2026 10:30:10 +0100 [thread overview]
Message-ID: <20261126093106.1345825-6-linmag7@gmail.com> (raw)
In-Reply-To: <20261126093106.1345825-1-linmag7@gmail.com>
Factory GR-LEON4-ITX U-Boot returns zero after character output, while
modern MKLINUXIMG returns zero when busy and one after transmission.
Recognize the legacy PROM before printing and adapt only its zero-success
callback. Match the exact legacy properties and accept its getprop()
success value of one; preserve other firmware conventions.
Fixes: 154337688bfa ("sparc: prom: Sanitize return value from prom_nbputchar()")
Cc: stable@vger.kernel.org
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
arch/sparc/include/asm/oplib_32.h | 2 ++
arch/sparc/prom/console_32.c | 5 +++--
arch/sparc/prom/init_32.c | 23 +++++++++++++++++++++++
3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/arch/sparc/include/asm/oplib_32.h b/arch/sparc/include/asm/oplib_32.h
index d1cf3a27a40d..5f009615cecf 100644
--- a/arch/sparc/include/asm/oplib_32.h
+++ b/arch/sparc/include/asm/oplib_32.h
@@ -25,6 +25,8 @@ enum prom_major_version {
};
extern enum prom_major_version prom_vers;
+/* Old LEON U-Boot uses a blocking, zero-success V0 putchar. */
+extern bool prom_leon_legacy;
/* Revision, and firmware revision. */
extern unsigned int prom_rev, prom_prev;
diff --git a/arch/sparc/prom/console_32.c b/arch/sparc/prom/console_32.c
index 6404e5bbb7e6..8615005ca67f 100644
--- a/arch/sparc/prom/console_32.c
+++ b/arch/sparc/prom/console_32.c
@@ -22,12 +22,13 @@ extern void restore_current(void);
static int prom_nbputchar(const char *buf)
{
unsigned long flags;
- int i = -1;
+ int i = -1, ret;
spin_lock_irqsave(&prom_lock, flags);
switch(prom_vers) {
case PROM_V0:
- if ((*(romvec->pv_nbputchar))(*buf))
+ ret = romvec->pv_nbputchar(*buf);
+ if (prom_leon_legacy ? ret == 0 : ret)
i = 1;
break;
case PROM_V2:
diff --git a/arch/sparc/prom/init_32.c b/arch/sparc/prom/init_32.c
index d20470166cb1..d36fa4e7207a 100644
--- a/arch/sparc/prom/init_32.c
+++ b/arch/sparc/prom/init_32.c
@@ -10,6 +10,7 @@
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
+#include <linux/string.h>
#include <asm/openprom.h>
#include <asm/oplib.h>
@@ -19,6 +20,7 @@ EXPORT_SYMBOL(romvec);
enum prom_major_version prom_vers;
unsigned int prom_rev, prom_prev;
+bool prom_leon_legacy __ro_after_init;
/* The root node of the prom device tree. */
phandle prom_root_node;
@@ -27,6 +29,25 @@ EXPORT_SYMBOL(prom_root_node);
/* Pointer to the device tree operations structure. */
struct linux_nodeops *prom_nodeops;
+/* Identify the old U-Boot PROM before any library routine can print. */
+static void __init prom_check_legacy_leon(void)
+{
+ char compat[5] = { };
+
+ if (!IS_ENABLED(CONFIG_SPARC_LEON) || prom_vers != PROM_V0 ||
+ romvec->pv_stdin || romvec->pv_stdout)
+ return;
+ if (prom_getproplen(prom_root_node, "compatible") >= 0)
+ return;
+ /* Old U-Boot's getprop returns one on success, not the byte count. */
+ if (prom_getproplen(prom_root_node, "compatability") != sizeof(compat))
+ return;
+ if (prom_getproperty(prom_root_node, "compatability", compat,
+ sizeof(compat)) > 0 &&
+ !memcmp(compat, "leon2", sizeof(compat)))
+ prom_leon_legacy = true;
+}
+
/* You must call prom_init() before you attempt to use any of the
* routines in the prom library.
* It gets passed the pointer to the PROM vector.
@@ -65,6 +86,8 @@ void __init prom_init(struct linux_romvec *rp)
(((unsigned long) prom_nodeops) == -1))
prom_halt();
+ prom_check_legacy_leon();
+
prom_meminit();
prom_ranges_init();
--
2.43.0
next prev parent reply other threads:[~2026-11-26 9:31 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-26 9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
2026-11-26 9:30 ` [PATCH 01/18] sparc32,leon: give the cross-call IRQ highest priority Magnus Lindholm
2026-11-26 9:30 ` [PATCH 02/18] sparc32,leon: retain SMP TLB shootdowns Magnus Lindholm
2026-11-26 9:41 ` sashiko-bot
2026-11-27 11:37 ` Magnus Lindholm
2026-11-26 9:30 ` [PATCH 03/18] sparc32,leon: publish instruction updates across CPUs Magnus Lindholm
2026-11-26 9:30 ` [PATCH 04/18] sparc32,leon: avoid nested IRQ accounting in the timer handler Magnus Lindholm
2026-11-26 9:30 ` Magnus Lindholm [this message]
2026-11-26 9:30 ` [PATCH 06/18] sparc32: tolerate firmware nodes without a name property Magnus Lindholm
2026-11-26 9:42 ` sashiko-bot
2026-11-26 9:30 ` [PATCH 07/18] sparc32: skip unavailable PROM V0 console metadata Magnus Lindholm
2026-11-26 9:30 ` [PATCH 08/18] sparc32,leon: identify LEON before the firmware model lookup Magnus Lindholm
2026-11-26 9:30 ` [PATCH 09/18] sparc32,leon: preserve the Linux IRQ14 vector during startup Magnus Lindholm
2026-11-26 9:30 ` [PATCH 10/18] sparc32,leon: use ASI 1 for locks on the GR-LEON4-ITX Magnus Lindholm
2026-11-26 9:30 ` [PATCH 11/18] sparc32,leon: restore the kernel header offsets used by U-Boot Magnus Lindholm
2026-11-26 9:30 ` [PATCH 12/18] sparc32: recognize the legacy LEON firmware machine ID Magnus Lindholm
2026-11-26 9:30 ` [PATCH 13/18] sparc32,leon: discover AMBA devices for legacy U-Boot PROMs Magnus Lindholm
2026-11-26 9:30 ` [PATCH 14/18] sparc32,leon: describe legacy AMBA I2C controllers Magnus Lindholm
2026-11-26 9:30 ` [PATCH 15/18] sparc32,leon: skip the GR-LEON4-ITX PROM mapping import Magnus Lindholm
2026-11-26 9:30 ` [PATCH 16/18] sparc32,leon: use the upper SDRAM on the GR-LEON4-ITX Magnus Lindholm
2026-11-26 9:30 ` [PATCH 17/18] sparc32,leon: combine legacy GRPCI1 plug-and-play resources Magnus Lindholm
2026-11-26 9:30 ` [PATCH 18/18] sparc32,leon: describe the DS1672 on the GR-LEON4-ITX Magnus Lindholm
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=20261126093106.1345825-6-linmag7@gmail.com \
--to=linmag7@gmail.com \
--cc=andreas@gaisler.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=sam@ravnborg.org \
--cc=sparclinux@vger.kernel.org \
--cc=stable@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.