Bladeren bron

nds32: some more experiments, 3.10-nds32 boots and works, 5.10 crashes, but gives earlyprintk messages

Waldemar Brodkorb 3 weken geleden
bovenliggende
commit
9a7b936910

+ 33 - 0
target/linux/patches/3.10-nds32/sigcontext.patch

@@ -0,0 +1,33 @@
+diff -Nur linux-3.10-nds32.orig/arch/nds32/include/uapi/asm/sigcontext.h linux-3.10-nds32/arch/nds32/include/uapi/asm/sigcontext.h
+--- linux-3.10-nds32.orig/arch/nds32/include/uapi/asm/sigcontext.h	2016-09-06 11:38:18.000000000 +0200
++++ linux-3.10-nds32/arch/nds32/include/uapi/asm/sigcontext.h	2026-06-18 04:54:13.353977605 +0200
+@@ -55,7 +55,7 @@
+         unsigned long nds32_r25;
+         unsigned long nds32_fp;	/* $r28 */
+         unsigned long nds32_gp;	/* $r29 */
+-        unsigned long nds32_lp;	/* $r30 */
++        unsigned long nds32_lr;	/* $r30 */
+         unsigned long nds32_sp;	/* $r31 */
+         unsigned long nds32_ipc;
+         unsigned long fault_address;
+diff -Nur linux-3.10-nds32.orig/arch/nds32/kernel/signal.c linux-3.10-nds32/arch/nds32/kernel/signal.c
+--- linux-3.10-nds32.orig/arch/nds32/kernel/signal.c	2016-09-06 11:38:18.000000000 +0200
++++ linux-3.10-nds32/arch/nds32/kernel/signal.c	2026-06-18 04:59:18.044804646 +0200
+@@ -197,7 +197,7 @@
+ 	__get_user_error(regs->NDS32_r25, &sf->uc.uc_mcontext.nds32_r25, err);
+ 	__get_user_error(regs->NDS32_fp, &sf->uc.uc_mcontext.nds32_fp, err);
+ 	__get_user_error(regs->NDS32_gp, &sf->uc.uc_mcontext.nds32_gp, err);
+-	__get_user_error(regs->NDS32_lp, &sf->uc.uc_mcontext.nds32_lp, err);
++	__get_user_error(regs->NDS32_lp, &sf->uc.uc_mcontext.nds32_lr, err);
+ 	__get_user_error(regs->NDS32_sp, &sf->uc.uc_mcontext.nds32_sp, err);
+ 	__get_user_error(regs->NDS32_ipc, &sf->uc.uc_mcontext.nds32_ipc, err);
+ #if defined(CONFIG_HWZOL)
+@@ -312,7 +312,7 @@
+ 	__put_user_error(regs->NDS32_r25, &sf->uc.uc_mcontext.nds32_r25, err);
+ 	__put_user_error(regs->NDS32_fp, &sf->uc.uc_mcontext.nds32_fp, err);
+ 	__put_user_error(regs->NDS32_gp, &sf->uc.uc_mcontext.nds32_gp, err);
+-	__put_user_error(regs->NDS32_lp, &sf->uc.uc_mcontext.nds32_lp, err);
++	__put_user_error(regs->NDS32_lp, &sf->uc.uc_mcontext.nds32_lr, err);
+ 	__put_user_error(regs->NDS32_sp, &sf->uc.uc_mcontext.nds32_sp, err);
+ 	__put_user_error(regs->NDS32_ipc, &sf->uc.uc_mcontext.nds32_ipc, err);
+ #if defined(CONFIG_HWZOL)

+ 220 - 0
target/linux/patches/5.10.257/nds32-early-printk.patch

@@ -0,0 +1,220 @@
+diff -Nur linux-5.10.257.orig/arch/nds32/include/asm/fixmap.h linux-5.10.257/arch/nds32/include/asm/fixmap.h
+--- linux-5.10.257.orig/arch/nds32/include/asm/fixmap.h	2026-05-23 13:40:03.000000000 +0200
++++ linux-5.10.257/arch/nds32/include/asm/fixmap.h	2026-06-14 19:54:35.522285109 +0200
+@@ -16,6 +16,9 @@
+ #ifdef CONFIG_HIGHMEM
+ 	FIX_KMAP_END = FIX_KMAP_BEGIN + (KM_TYPE_NR * NR_CPUS),
+ #endif
++#ifdef CONFIG_EARLY_PRINTK
++	FIX_EARLY_DEBUG,
++#endif
+ 	FIX_EARLYCON_MEM_BASE,
+ 	__end_of_fixed_addresses
+ };
+diff -Nur linux-5.10.257.orig/arch/nds32/Kconfig.debug linux-5.10.257/arch/nds32/Kconfig.debug
+--- linux-5.10.257.orig/arch/nds32/Kconfig.debug	2026-05-23 13:40:03.000000000 +0200
++++ linux-5.10.257/arch/nds32/Kconfig.debug	2026-06-14 18:52:53.595799176 +0200
+@@ -1,2 +1,11 @@
+ # SPDX-License-Identifier: GPL-2.0-only
+ # dummy file, do not delete
++
++config EARLY_PRINTK
++        bool "Early printk support"
++        default y
++        help
++          Say Y here if you want to have an early console using the
++          earlyprintk=<name>[,<addr>][,<options>] kernel parameter. It
++          is assumed that the early console device has been initialised
++          by the boot loader prior to starting the Linux kernel.
+diff -Nur linux-5.10.257.orig/arch/nds32/kernel/early_printk.c linux-5.10.257/arch/nds32/kernel/early_printk.c
+--- linux-5.10.257.orig/arch/nds32/kernel/early_printk.c	1970-01-01 01:00:00.000000000 +0100
++++ linux-5.10.257/arch/nds32/kernel/early_printk.c	2026-06-14 18:55:22.649111388 +0200
+@@ -0,0 +1,126 @@
++/*
++ * Earlyprintk support.
++ *
++ * Copyright (C) 2012 ARM Ltd.
++ * Author: Catalin Marinas <catalin.marinas@arm.com>
++ *
++ * This program is free software: you can redistribute it and/or modify
++ * it under the terms of the GNU General Public License version 2 as
++ * published by the Free Software Foundation.
++ *
++ * This program is distributed in the hope that it will be useful,
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
++ * GNU General Public License for more details.
++ *
++ * You should have received a copy of the GNU General Public License
++ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
++ */
++#include <linux/kernel.h>
++#include <linux/console.h>
++#include <linux/init.h>
++#include <linux/string.h>
++#include <linux/mm.h>
++#include <linux/io.h>
++
++#include <linux/serial_reg.h>
++#include <asm/setup.h>
++
++extern void __iomem *early_io_map(phys_addr_t phys);
++static void __iomem *early_base;
++static void (*printch) (char ch);
++
++/*
++ * 8250/16550 (8-bit aligned registers) single character TX.
++ */
++static void uart8250_8bit_printch(char ch)
++{
++	while (!(readb(early_base + UART_LSR) & UART_LSR_THRE)) ;
++	writeb(ch, early_base + UART_TX);
++}
++
++/*
++ * 8250/16550 (32-bit aligned registers) single character TX.
++ */
++static void uart8250_32bit_printch(char ch)
++{
++	while (!(readl(early_base + (UART_LSR << 2)) & UART_LSR_THRE)) ;
++	writel(ch, early_base + (UART_TX << 2));
++}
++
++struct earlycon_match {
++	const char *name;
++	void (*printch) (char ch);
++};
++
++static const struct earlycon_match earlycon_match[] __initconst = {
++	{.name = "uart8250-8bit",.printch = uart8250_8bit_printch,},
++	{.name = "uart8250-32bit",.printch = uart8250_32bit_printch,},
++	{}
++};
++
++static void early_write(struct console *con, const char *s, unsigned n)
++{
++	while (n-- > 0) {
++		if (*s == '\n')
++			printch('\r');
++		printch(*s);
++		s++;
++	}
++}
++
++static struct console early_console_dev = {
++	.name = "earlycon",
++	.write = early_write,
++	.flags = CON_PRINTBUFFER | CON_BOOT,
++	.index = -1,
++};
++
++/*
++ * Parse earlyprintk=... parameter in the format:
++ *
++ *   <name>[,<addr>][,<options>]
++ *
++ * and register the early console. It is assumed that the UART has been
++ * initialised by the bootloader already.
++ */
++static int __init setup_early_printk(char *buf)
++{
++	const struct earlycon_match *match = earlycon_match;
++	phys_addr_t paddr = 0;
++
++	if (!buf) {
++		pr_warn("No earlyprintk arguments passed.\n");
++		return 0;
++	}
++
++	while (match->name) {
++		size_t len = strlen(match->name);
++		if (!strncmp(buf, match->name, len)) {
++			buf += len;
++			break;
++		}
++		match++;
++	}
++	if (!match->name) {
++		pr_warn("Unknown earlyprintk arguments: %s\n", buf);
++		return 0;
++	}
++
++	/* I/O address */
++	if (!strncmp(buf, ",0x", 3)) {
++		char *e;
++		paddr = simple_strtoul(buf + 1, &e, 16);
++		buf = e;
++	}
++
++	if (paddr)
++		early_base = early_io_map(paddr);
++	printch = match->printch;
++	//early_console = &early_console_dev;
++	register_console(&early_console_dev);
++
++	return 0;
++}
++
++early_param("earlyprintk", setup_early_printk);
+diff -Nur linux-5.10.257.orig/arch/nds32/kernel/ex-entry.S linux-5.10.257/arch/nds32/kernel/ex-entry.S
+--- linux-5.10.257.orig/arch/nds32/kernel/ex-entry.S	2026-05-23 13:40:03.000000000 +0200
++++ linux-5.10.257/arch/nds32/kernel/ex-entry.S	2026-06-14 16:40:51.574298067 +0200
+@@ -162,7 +162,7 @@
+ 	jral.ton $p0, $p0
+ 	.endm
+ 
+-	.section	".text.init", #alloc, #execinstr
++	.section	".text.init", "ax"
+ 	.global	exception_vector
+ exception_vector:
+ .rept 6
+diff -Nur linux-5.10.257.orig/arch/nds32/kernel/Makefile linux-5.10.257/arch/nds32/kernel/Makefile
+--- linux-5.10.257.orig/arch/nds32/kernel/Makefile	2026-05-23 13:40:03.000000000 +0200
++++ linux-5.10.257/arch/nds32/kernel/Makefile	2026-06-14 18:12:54.765210343 +0200
+@@ -19,6 +19,8 @@
+ obj-$(CONFIG_CACHE_L2)		+= atl2c.o
+ obj-$(CONFIG_PERF_EVENTS) += perf_event_cpu.o
+ obj-$(CONFIG_PM)		+= pm.o sleep.o
++obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
++
+ extra-y := head.o vmlinux.lds
+ 
+ CFLAGS_fpu.o += -mext-fpu-sp -mext-fpu-dp
+diff -Nur linux-5.10.257.orig/arch/nds32/mm/init.c linux-5.10.257/arch/nds32/mm/init.c
+--- linux-5.10.257.orig/arch/nds32/mm/init.c	2026-05-23 13:40:03.000000000 +0200
++++ linux-5.10.257/arch/nds32/mm/init.c	2026-06-14 19:28:16.484988055 +0200
+@@ -262,3 +262,34 @@
+ 		flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
+ 	}
+ }
++
++#ifdef CONFIG_EARLY_PRINTK
++#include <asm/fixmap.h>
++
++/*
++ * Using tlbop to create an early I/O mapping
++ */
++void __iomem *__init early_io_map(phys_addr_t pa)
++{
++	unsigned long va;
++	pa &= PAGE_MASK;
++	pa += pgprot_val(PAGE_DEVICE);
++	va = fix_to_virt(FIX_EARLY_DEBUG);
++	/* insert and lock this page to tlb entry directly */
++	asm volatile ("mtsr   %0, $TLB_VPN\n\t"
++		      "dsb\n\t"
++		      "tlbop  %1, RWLK\n\t" "isb\n\t"::"r" (va), "r"(pa));
++	return (void __iomem *)va;
++}
++
++int __init early_io_unmap(void)
++{
++	unsigned long va;
++	va = fix_to_virt(FIX_EARLY_DEBUG);
++	asm volatile ("tlbop  %0, UNLK\n\t"
++		      "tlbop  %0, INV\n\t" "isb\n\t"::"r" (va));
++	return 0;
++}
++
++late_initcall(early_io_unmap);
++#endif

+ 2 - 1
target/nds32/kernel/andes-ag101p

@@ -2,4 +2,5 @@ CONFIG_NDS32=y
 CONFIG_PLATFORM_AHBDMA=y
 CONFIG_PLATFORM_APBDMA=y
 CONFIG_UART_CLK=14745600
-CONFIG_DEBUG_USER=y
+CONFIG_NDS32_BUILTIN_DTB="ag101p"
+CONFIG_EVIC=y