Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2003 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 5 | * |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 6 | * (c) Copyright 2008 Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com> |
| 7 | * (c) Copyright 2008 Renesas Solutions Corp. |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <command.h> |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 12 | #include <env.h> |
Simon Glass | 4d72caa | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 13 | #include <image.h> |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 14 | #include <asm/byteorder.h> |
Marek Vasut | 1e0e557 | 2021-09-10 22:47:16 +0200 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Nobuhiro Iwamatsu | 9980df5 | 2010-12-08 13:46:36 +0900 | [diff] [blame] | 16 | #include <asm/zimage.h> |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 17 | |
Marek Vasut | 1e0e557 | 2021-09-10 22:47:16 +0200 | [diff] [blame] | 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Nobuhiro Iwamatsu | cf2c87d | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 20 | #ifdef CONFIG_SH_SDRAM_OFFSET |
| 21 | #define GET_INITRD_START(initrd, linux) (initrd - linux + CONFIG_SH_SDRAM_OFFSET) |
| 22 | #else |
| 23 | #define GET_INITRD_START(initrd, linux) (initrd - linux) |
| 24 | #endif |
| 25 | |
| 26 | static void set_sh_linux_param(unsigned long param_addr, unsigned long data) |
| 27 | { |
| 28 | *(unsigned long *)(param_addr) = data; |
| 29 | } |
| 30 | |
| 31 | static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base) |
| 32 | { |
| 33 | unsigned long val = 0; |
| 34 | char *p = strstr(cmdline, key); |
| 35 | if (p) { |
| 36 | p += strlen(key); |
| 37 | val = simple_strtol(p, NULL, base); |
| 38 | } |
| 39 | return val; |
| 40 | } |
| 41 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 42 | int do_bootm_linux(int flag, int argc, char *const argv[], |
Simon Glass | d9d7c20 | 2022-09-06 20:26:50 -0600 | [diff] [blame] | 43 | struct bootm_headers *images) |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 44 | { |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 45 | /* Linux kernel load address */ |
Kumar Gala | c160a95 | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 46 | void (*kernel) (void) = (void (*)(void))images->ep; |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 47 | /* empty_zero_page */ |
Nobuhiro Iwamatsu | b5d10a1 | 2008-09-18 19:34:36 +0900 | [diff] [blame] | 48 | unsigned char *param |
| 49 | = (unsigned char *)image_get_load(images->legacy_hdr_os); |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 50 | /* Linux kernel command line */ |
Nobuhiro Iwamatsu | cf2c87d | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 51 | char *cmdline = (char *)param + COMMAND_LINE; |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 52 | /* PAGE_SIZE */ |
Nobuhiro Iwamatsu | b5d10a1 | 2008-09-18 19:34:36 +0900 | [diff] [blame] | 53 | unsigned long size = images->ep - (unsigned long)param; |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 54 | char *bootargs = env_get("bootargs"); |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 55 | |
Andreas Bießmann | 2cb0e55 | 2013-07-02 13:57:44 +0200 | [diff] [blame] | 56 | /* |
| 57 | * allow the PREP bootm subcommand, it is required for bootm to work |
| 58 | */ |
| 59 | if (flag & BOOTM_STATE_OS_PREP) |
| 60 | return 0; |
| 61 | |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 62 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 63 | return 1; |
| 64 | |
Nobuhiro Iwamatsu | 9980df5 | 2010-12-08 13:46:36 +0900 | [diff] [blame] | 65 | /* Clear zero page */ |
| 66 | memset(param, 0, size); |
Nobuhiro Iwamatsu | cf2c87d | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 67 | |
| 68 | /* Set commandline */ |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 69 | strcpy(cmdline, bootargs); |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 70 | |
Nobuhiro Iwamatsu | cf2c87d | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 71 | /* Initrd */ |
| 72 | if (images->rd_start || images->rd_end) { |
Nobuhiro Iwamatsu | de03f8b | 2010-10-19 17:14:15 +0900 | [diff] [blame] | 73 | unsigned long ramdisk_flags = 0; |
Nobuhiro Iwamatsu | cf2c87d | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 74 | int val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_PROMPT, 10); |
| 75 | if (val == 1) |
| 76 | ramdisk_flags |= RD_PROMPT; |
| 77 | else |
| 78 | ramdisk_flags &= ~RD_PROMPT; |
Wolfgang Denk | 071bc92 | 2010-10-27 22:48:30 +0200 | [diff] [blame] | 79 | |
Nobuhiro Iwamatsu | cf2c87d | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 80 | val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_DOLOAD, 10); |
| 81 | if (val == 1) |
| 82 | ramdisk_flags |= RD_DOLOAD; |
| 83 | else |
| 84 | ramdisk_flags &= ~RD_DOLOAD; |
| 85 | |
| 86 | set_sh_linux_param((unsigned long)param + MOUNT_ROOT_RDONLY, 0x0001); |
| 87 | set_sh_linux_param((unsigned long)param + RAMDISK_FLAGS, ramdisk_flags); |
| 88 | set_sh_linux_param((unsigned long)param + ORIG_ROOT_DEV, 0x0200); |
| 89 | set_sh_linux_param((unsigned long)param + LOADER_TYPE, 0x0001); |
| 90 | set_sh_linux_param((unsigned long)param + INITRD_START, |
Tom Rini | aa6e94d | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 91 | GET_INITRD_START(images->rd_start, CFG_SYS_SDRAM_BASE)); |
Nobuhiro Iwamatsu | cf2c87d | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 92 | set_sh_linux_param((unsigned long)param + INITRD_SIZE, |
| 93 | images->rd_end - images->rd_start); |
| 94 | } |
| 95 | |
| 96 | /* Boot kernel */ |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 97 | kernel(); |
Marian Balakowicz | cd7c596 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 98 | |
Nobuhiro Iwamatsu | 9980df5 | 2010-12-08 13:46:36 +0900 | [diff] [blame] | 99 | /* does not return */ |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 100 | return 1; |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 101 | } |
Marek Vasut | 1e0e557 | 2021-09-10 22:47:16 +0200 | [diff] [blame] | 102 | |
| 103 | static ulong get_sp(void) |
| 104 | { |
| 105 | ulong ret; |
| 106 | |
| 107 | asm("mov r15, %0" : "=r"(ret) : ); |
| 108 | return ret; |
| 109 | } |
| 110 | |
| 111 | void arch_lmb_reserve(struct lmb *lmb) |
| 112 | { |
| 113 | arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096); |
| 114 | } |