From 4a53996d4904da64d1f022b565add7e9e1d2c036 Mon Sep 17 00:00:00 2001
From: gavin-Angry-Birds <gavincodegk@gmail.com>
Date: Mon, 15 Jun 2026 16:47:25 +0800
Subject: [PATCH] csky: fix initrd setup for initrd= command line parameter

The generic early_param("initrd") handler records physical initrd
location in phys_initrd_start/phys_initrd_size.  C-SKY setup_initrd()
only checked initrd_start/end, which are not populated from the
command line, so initrd= was effectively ignored.

Convert phys_initrd_* to virtual addresses with __va(), similar to
ARC and reserve_initrd_mem().

Tested on kd5886 vendor platform (private, not for upstream):
- External DTB with /chosen/bootargs containing
  initrd=0x12000000,0x54000 and root=/dev/ram0
- rootfs.squashfs (344064 bytes) loaded via TFTP to physical 0x12000000
- Kernel command line parsed correctly; "Freeing initrd memory: 336k
  freed"; squashfs root mounted on /dev/ram0; userspace reached

Signed-off-by: gavin-Angry-Birds <gavincodegk@gmail.com>
---
 arch/csky/kernel/setup.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/arch/csky/kernel/setup.c b/arch/csky/kernel/setup.c
index 45c98dcf7f50..a490ff2c20b5 100644
--- a/arch/csky/kernel/setup.c
+++ b/arch/csky/kernel/setup.c
@@ -8,6 +8,7 @@
 #include <linux/of_fdt.h>
 #include <linux/start_kernel.h>
 #include <linux/dma-map-ops.h>
+#include <asm/page.h>
 #include <asm/sections.h>
 #include <asm/mmu_context.h>
 #include <asm/pgalloc.h>
@@ -17,6 +18,12 @@ static void __init setup_initrd(void)
 {
 	unsigned long size;
 
+	/* initrd= on the command line specifies physical addresses */
+	if (phys_initrd_size) {
+		initrd_start = (unsigned long)__va(phys_initrd_start);
+		initrd_end = initrd_start + phys_initrd_size;
+	}
+
 	if (initrd_start >= initrd_end) {
 		pr_err("initrd not found or empty");
 		goto disable;
-- 
2.50.1 (Apple Git-155)

