Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 5 | * (c) Copyright 2008 Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com> |
| 6 | * (c) Copyright 2008 Renesas Solutions Corp. |
| 7 | * |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <command.h> |
| 29 | #include <asm/byteorder.h> |
| 30 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 31 | #ifdef CONFIG_SYS_DEBUG |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 32 | static void hexdump(unsigned char *buf, int len) |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 33 | { |
| 34 | int i; |
| 35 | |
| 36 | for (i = 0; i < len; i++) { |
| 37 | if ((i % 16) == 0) |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 38 | printf("%s%08x: ", i ? "\n" : "", |
| 39 | (unsigned int)&buf[i]); |
| 40 | printf("%02x ", buf[i]); |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 41 | } |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 42 | printf("\n"); |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 43 | } |
| 44 | #endif |
| 45 | |
Nobuhiro Iwamatsu | 190f4f7 | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 46 | #define MOUNT_ROOT_RDONLY 0x000 |
| 47 | #define RAMDISK_FLAGS 0x004 |
| 48 | #define ORIG_ROOT_DEV 0x008 |
| 49 | #define LOADER_TYPE 0x00c |
| 50 | #define INITRD_START 0x010 |
| 51 | #define INITRD_SIZE 0x014 |
| 52 | #define COMMAND_LINE 0x100 |
| 53 | |
| 54 | #define RD_PROMPT (1<<15) |
| 55 | #define RD_DOLOAD (1<<14) |
| 56 | #define CMD_ARG_RD_PROMPT "prompt_ramdisk=" |
| 57 | #define CMD_ARG_RD_DOLOAD "load_ramdisk=" |
| 58 | |
| 59 | #ifdef CONFIG_SH_SDRAM_OFFSET |
| 60 | #define GET_INITRD_START(initrd, linux) (initrd - linux + CONFIG_SH_SDRAM_OFFSET) |
| 61 | #else |
| 62 | #define GET_INITRD_START(initrd, linux) (initrd - linux) |
| 63 | #endif |
| 64 | |
| 65 | static void set_sh_linux_param(unsigned long param_addr, unsigned long data) |
| 66 | { |
| 67 | *(unsigned long *)(param_addr) = data; |
| 68 | } |
| 69 | |
| 70 | static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base) |
| 71 | { |
| 72 | unsigned long val = 0; |
| 73 | char *p = strstr(cmdline, key); |
| 74 | if (p) { |
| 75 | p += strlen(key); |
| 76 | val = simple_strtol(p, NULL, base); |
| 77 | } |
| 78 | return val; |
| 79 | } |
| 80 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 81 | int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *images) |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 82 | { |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 83 | /* Linux kernel load address */ |
Kumar Gala | 93467bc | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 84 | void (*kernel) (void) = (void (*)(void))images->ep; |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 85 | /* empty_zero_page */ |
Nobuhiro Iwamatsu | e58917e | 2008-09-18 19:34:36 +0900 | [diff] [blame] | 86 | unsigned char *param |
| 87 | = (unsigned char *)image_get_load(images->legacy_hdr_os); |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 88 | /* Linux kernel command line */ |
Nobuhiro Iwamatsu | 190f4f7 | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 89 | char *cmdline = (char *)param + COMMAND_LINE; |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 90 | /* PAGE_SIZE */ |
Nobuhiro Iwamatsu | e58917e | 2008-09-18 19:34:36 +0900 | [diff] [blame] | 91 | unsigned long size = images->ep - (unsigned long)param; |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 92 | char *bootargs = getenv("bootargs"); |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 93 | |
Kumar Gala | 18178bc | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 94 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 95 | return 1; |
| 96 | |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 97 | /* Setup parameters */ |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 98 | memset(param, 0, size); /* Clear zero page */ |
Nobuhiro Iwamatsu | 190f4f7 | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 99 | |
| 100 | /* Set commandline */ |
Nobuhiro Iwamatsu | 752a595 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 101 | strcpy(cmdline, bootargs); |
Nobuhiro Iwamatsu | 547b67f | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 102 | |
Nobuhiro Iwamatsu | 190f4f7 | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 103 | sh_check_cmd_arg(bootargs, CMD_ARG_RD_DOLOAD, 10); |
| 104 | /* Initrd */ |
| 105 | if (images->rd_start || images->rd_end) { |
Nobuhiro Iwamatsu | 0b43bd8 | 2010-10-19 17:14:15 +0900 | [diff] [blame] | 106 | unsigned long ramdisk_flags = 0; |
Nobuhiro Iwamatsu | 190f4f7 | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 107 | int val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_PROMPT, 10); |
| 108 | if (val == 1) |
| 109 | ramdisk_flags |= RD_PROMPT; |
| 110 | else |
| 111 | ramdisk_flags &= ~RD_PROMPT; |
Wolfgang Denk | 1136f69 | 2010-10-27 22:48:30 +0200 | [diff] [blame] | 112 | |
Nobuhiro Iwamatsu | 190f4f7 | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 113 | val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_DOLOAD, 10); |
| 114 | if (val == 1) |
| 115 | ramdisk_flags |= RD_DOLOAD; |
| 116 | else |
| 117 | ramdisk_flags &= ~RD_DOLOAD; |
| 118 | |
| 119 | set_sh_linux_param((unsigned long)param + MOUNT_ROOT_RDONLY, 0x0001); |
| 120 | set_sh_linux_param((unsigned long)param + RAMDISK_FLAGS, ramdisk_flags); |
| 121 | set_sh_linux_param((unsigned long)param + ORIG_ROOT_DEV, 0x0200); |
| 122 | set_sh_linux_param((unsigned long)param + LOADER_TYPE, 0x0001); |
| 123 | set_sh_linux_param((unsigned long)param + INITRD_START, |
| 124 | GET_INITRD_START(images->rd_start, CONFIG_SYS_SDRAM_BASE)); |
| 125 | set_sh_linux_param((unsigned long)param + INITRD_SIZE, |
| 126 | images->rd_end - images->rd_start); |
| 127 | } |
| 128 | |
| 129 | /* Boot kernel */ |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 130 | kernel(); |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 131 | /* does not return */ |
Marian Balakowicz | df8ff33 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 132 | |
Kumar Gala | 48626aa | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 133 | return 1; |
Nobuhiro Iwamatsu | 970dc33 | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 134 | } |