Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Nobuhiro Iwamatsu | 970dc33 | 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 | 752a595 | 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 | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 8 | */ |
| 9 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 10 | #include <config.h> |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 11 | #include <bootm.h> |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 12 | #include <command.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 13 | #include <env.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 14 | #include <image.h> |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 15 | #include <asm/byteorder.h> |
Marek Vasut | 35c6d0e | 2021-09-10 22:47:16 +0200 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Nobuhiro Iwamatsu | 3db6055 | 2010-12-08 13:46:36 +0900 | [diff] [blame] | 17 | #include <asm/zimage.h> |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 18 | |
Marek Vasut | 35c6d0e | 2021-09-10 22:47:16 +0200 | [diff] [blame] | 19 | DECLARE_GLOBAL_DATA_PTR; |
| 20 | |
Nobuhiro Iwamatsu | 190f4f7 | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 21 | #ifdef CONFIG_SH_SDRAM_OFFSET |
| 22 | #define GET_INITRD_START(initrd, linux) (initrd - linux + CONFIG_SH_SDRAM_OFFSET) |
| 23 | #else |
| 24 | #define GET_INITRD_START(initrd, linux) (initrd - linux) |
| 25 | #endif |
| 26 | |
| 27 | static void set_sh_linux_param(unsigned long param_addr, unsigned long data) |
| 28 | { |
| 29 | *(unsigned long *)(param_addr) = data; |
| 30 | } |
| 31 | |
| 32 | static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base) |
| 33 | { |
| 34 | unsigned long val = 0; |
| 35 | char *p = strstr(cmdline, key); |
| 36 | if (p) { |
| 37 | p += strlen(key); |
| 38 | val = simple_strtol(p, NULL, base); |
| 39 | } |
| 40 | return val; |
| 41 | } |
| 42 | |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 43 | int do_bootm_linux(int flag, struct bootm_info *bmi) |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 44 | { |
Simon Glass | 0726d9d | 2023-12-15 20:14:13 -0700 | [diff] [blame] | 45 | struct bootm_headers *images = bmi->images; |
| 46 | |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 47 | /* Linux kernel load address */ |
Kumar Gala | 93467bc | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 48 | void (*kernel) (void) = (void (*)(void))images->ep; |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 49 | /* empty_zero_page */ |
Nobuhiro Iwamatsu | e58917e | 2008-09-18 19:34:36 +0900 | [diff] [blame] | 50 | unsigned char *param |
| 51 | = (unsigned char *)image_get_load(images->legacy_hdr_os); |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 52 | /* Linux kernel command line */ |
Nobuhiro Iwamatsu | 190f4f7 | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 53 | char *cmdline = (char *)param + COMMAND_LINE; |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 54 | /* PAGE_SIZE */ |
Nobuhiro Iwamatsu | e58917e | 2008-09-18 19:34:36 +0900 | [diff] [blame] | 55 | unsigned long size = images->ep - (unsigned long)param; |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 56 | char *bootargs = env_get("bootargs"); |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 57 | |
Andreas Bießmann | da233ce | 2013-07-02 13:57:44 +0200 | [diff] [blame] | 58 | /* |
| 59 | * allow the PREP bootm subcommand, it is required for bootm to work |
| 60 | */ |
| 61 | if (flag & BOOTM_STATE_OS_PREP) |
| 62 | return 0; |
| 63 | |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 64 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 65 | return 1; |
| 66 | |
Nobuhiro Iwamatsu | 3db6055 | 2010-12-08 13:46:36 +0900 | [diff] [blame] | 67 | /* Clear zero page */ |
| 68 | memset(param, 0, size); |
Nobuhiro Iwamatsu | 190f4f7 | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 69 | |
| 70 | /* Set commandline */ |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 71 | strcpy(cmdline, bootargs); |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 72 | |
Nobuhiro Iwamatsu | 190f4f7 | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 73 | /* Initrd */ |
| 74 | if (images->rd_start || images->rd_end) { |
Nobuhiro Iwamatsu | 0b43bd8 | 2010-10-19 17:14:15 +0900 | [diff] [blame] | 75 | unsigned long ramdisk_flags = 0; |
Nobuhiro Iwamatsu | 190f4f7 | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 76 | int val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_PROMPT, 10); |
| 77 | if (val == 1) |
| 78 | ramdisk_flags |= RD_PROMPT; |
| 79 | else |
| 80 | ramdisk_flags &= ~RD_PROMPT; |
Wolfgang Denk | 1136f69 | 2010-10-27 22:48:30 +0200 | [diff] [blame] | 81 | |
Nobuhiro Iwamatsu | 190f4f7 | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 82 | val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_DOLOAD, 10); |
| 83 | if (val == 1) |
| 84 | ramdisk_flags |= RD_DOLOAD; |
| 85 | else |
| 86 | ramdisk_flags &= ~RD_DOLOAD; |
| 87 | |
| 88 | set_sh_linux_param((unsigned long)param + MOUNT_ROOT_RDONLY, 0x0001); |
| 89 | set_sh_linux_param((unsigned long)param + RAMDISK_FLAGS, ramdisk_flags); |
| 90 | set_sh_linux_param((unsigned long)param + ORIG_ROOT_DEV, 0x0200); |
| 91 | set_sh_linux_param((unsigned long)param + LOADER_TYPE, 0x0001); |
| 92 | set_sh_linux_param((unsigned long)param + INITRD_START, |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 93 | GET_INITRD_START(images->rd_start, CFG_SYS_SDRAM_BASE)); |
Nobuhiro Iwamatsu | 190f4f7 | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 94 | set_sh_linux_param((unsigned long)param + INITRD_SIZE, |
| 95 | images->rd_end - images->rd_start); |
| 96 | } |
| 97 | |
| 98 | /* Boot kernel */ |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 99 | kernel(); |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 100 | |
Nobuhiro Iwamatsu | 3db6055 | 2010-12-08 13:46:36 +0900 | [diff] [blame] | 101 | /* does not return */ |
Kumar Gala | 48626aa | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 102 | return 1; |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 103 | } |
Marek Vasut | 35c6d0e | 2021-09-10 22:47:16 +0200 | [diff] [blame] | 104 | |
| 105 | static ulong get_sp(void) |
| 106 | { |
| 107 | ulong ret; |
| 108 | |
| 109 | asm("mov r15, %0" : "=r"(ret) : ); |
| 110 | return ret; |
| 111 | } |
| 112 | |
| 113 | void arch_lmb_reserve(struct lmb *lmb) |
| 114 | { |
| 115 | arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096); |
| 116 | } |