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