From patchwork Tue Dec 5 09:45:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshinori Sato X-Patchwork-Id: 13479662 Received: from sakura.ysato.name (ik1-413-38519.vs.sakura.ne.jp [153.127.30.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 82DF2AA for ; Tue, 5 Dec 2023 01:46:15 -0800 (PST) Received: from SIOS1075.ysato.name (ZM005235.ppp.dion.ne.jp [222.8.5.235]) by sakura.ysato.name (Postfix) with ESMTPSA id 164F21C04FD; Tue, 5 Dec 2023 18:46:13 +0900 (JST) From: Yoshinori Sato To: linux-sh@vger.kernel.org Cc: Yoshinori Sato , Damien Le Moal , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Geert Uytterhoeven , Michael Turquette , Stephen Boyd , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Thomas Gleixner , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Bjorn Helgaas , Greg Kroah-Hartman , Jiri Slaby , Magnus Damm , Daniel Lezcano , Rich Felker , John Paul Adrian Glaubitz , Lee Jones , Helge Deller , Heiko Stuebner , Jernej Skrabec , Chris Morgan , Linus Walleij , Randy Dunlap , Arnd Bergmann , Hyeonggon Yoo <42.hyeyoo@gmail.com>, David Rientjes , Vlastimil Babka , Baoquan He , Andrew Morton , Guenter Roeck , Stephen Rothwell , Guo Ren , Javier Martinez Canillas , Azeem Shaikh , Palmer Dabbelt , Bin Meng , Max Filippov , Tom Rix , Herve Codina , Jacky Huang , Lukas Bulwahn , Jonathan Corbet , Biju Das , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Sam Ravnborg , Michael Karcher , Sergey Shtylyov , Laurent Pinchart , linux-ide@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-clk@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-pci@vger.kernel.org, linux-serial@vger.kernel.org, linux-fbdev@vger.kernel.org Subject: [DO NOT MERGE v5 06/37] sh: kernel/setup Update DT support. Date: Tue, 5 Dec 2023 18:45:25 +0900 Message-Id: <76bbd45b22ef6cc1fa69369aff908c9c4e366860.1701768028.git.ysato@users.sourceforge.jp> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-sh@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Fix extrnal fdt initialize and bootargs. Signed-off-by: Yoshinori Sato --- arch/sh/kernel/setup.c | 51 ++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/arch/sh/kernel/setup.c b/arch/sh/kernel/setup.c index 3d80515298d2..b299abff68e0 100644 --- a/arch/sh/kernel/setup.c +++ b/arch/sh/kernel/setup.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -74,7 +75,13 @@ extern int root_mountflags; #define RAMDISK_PROMPT_FLAG 0x8000 #define RAMDISK_LOAD_FLAG 0x4000 +#if defined(CONFIG_OF) && !defined(CONFIG_USE_BUILTIN_DTB) +#define CHOSEN_BOOTARGS +#endif + +#ifndef CHOSEN_BOOTARGS static char __initdata command_line[COMMAND_LINE_SIZE] = { 0, }; +#endif static struct resource code_resource = { .name = "Kernel code", @@ -244,18 +251,18 @@ void __init __weak plat_early_device_setup(void) void __ref sh_fdt_init(phys_addr_t dt_phys) { static int done = 0; - void *dt_virt; + void *fdt; /* Avoid calling an __init function on secondary cpus. */ if (done) return; #ifdef CONFIG_USE_BUILTIN_DTB - dt_virt = __dtb_start; + fdt = __dtb_start; #else - dt_virt = phys_to_virt(dt_phys); + fdt = phys_to_virt(dt_phys); #endif - if (!dt_virt || !early_init_dt_scan(dt_virt)) { + if (!fdt || !early_init_dt_scan(fdt)) { pr_crit("Error: invalid device tree blob" " at physical address %p\n", (void *)dt_phys); @@ -269,8 +276,20 @@ void __ref sh_fdt_init(phys_addr_t dt_phys) void __init setup_arch(char **cmdline_p) { +#ifdef CONFIG_OF_EARLY_FLATTREE + if (IS_ENABLED(CONFIG_USE_BUILTIN_DTB)) { + /* Relocate Embedded DTB */ + unflatten_and_copy_device_tree(); + } else if (initial_boot_params) { + /* Reserve external DTB area */ + memblock_reserve(__pa(initial_boot_params), + fdt_totalsize(initial_boot_params)); + unflatten_device_tree(); + } +#endif enable_mmu(); +#ifndef CONFIG_OF ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV); printk(KERN_NOTICE "Boot params:\n" @@ -299,19 +318,25 @@ void __init setup_arch(char **cmdline_p) bss_resource.start = virt_to_phys(__bss_start); bss_resource.end = virt_to_phys(__bss_stop)-1; -#ifdef CONFIG_CMDLINE_OVERWRITE - strscpy(command_line, CONFIG_CMDLINE, sizeof(command_line)); -#else +#endif + +#ifndef CHOSEN_BOOTARGS +#ifndef CONFIG_CMDLINE_OVERWRITE strscpy(command_line, COMMAND_LINE, sizeof(command_line)); #ifdef CONFIG_CMDLINE_EXTEND strlcat(command_line, " ", sizeof(command_line)); strlcat(command_line, CONFIG_CMDLINE, sizeof(command_line)); #endif -#endif - +#else /* !CONFIG_CMDLINE_OVERWRITE*/ + strscpy(command_line, CONFIG_CMDLINE, sizeof(command_line)); +#endif /* CONFIG_CMDLINE_OVERWRITE */ /* Save unparsed command line copy for /proc/cmdline */ memcpy(boot_command_line, command_line, COMMAND_LINE_SIZE); *cmdline_p = command_line; +#else /* CHOSEN_BOOTARGS */ + /* Use "/chosen/bootargs" specified in devicetree. */ + *cmdline_p = boot_command_line; +#endif parse_early_param(); @@ -322,14 +347,6 @@ void __init setup_arch(char **cmdline_p) /* Let earlyprintk output early console messages */ sh_early_platform_driver_probe("earlyprintk", 1, 1); -#ifdef CONFIG_OF_EARLY_FLATTREE -#ifdef CONFIG_USE_BUILTIN_DTB - unflatten_and_copy_device_tree(); -#else - unflatten_device_tree(); -#endif -#endif - paging_init(); /* Perform the machine specific initialisation */