Nobuhiro Iwamatsu | 0b135cf | 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 | 6b44a43 | 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 | 0b135cf | 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> |
Nobuhiro Iwamatsu | 9980df5 | 2010-12-08 13:46:36 +0900 | [diff] [blame] | 30 | #include <asm/zimage.h> |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 31 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 32 | #ifdef CONFIG_SYS_DEBUG |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 33 | static void hexdump(unsigned char *buf, int len) |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 34 | { |
| 35 | int i; |
| 36 | |
| 37 | for (i = 0; i < len; i++) { |
| 38 | if ((i % 16) == 0) |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 39 | printf("%s%08x: ", i ? "\n" : "", |
| 40 | (unsigned int)&buf[i]); |
| 41 | printf("%02x ", buf[i]); |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 42 | } |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 43 | printf("\n"); |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 44 | } |
| 45 | #endif |
| 46 | |
Nobuhiro Iwamatsu | cf2c87d | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 47 | #ifdef CONFIG_SH_SDRAM_OFFSET |
| 48 | #define GET_INITRD_START(initrd, linux) (initrd - linux + CONFIG_SH_SDRAM_OFFSET) |
| 49 | #else |
| 50 | #define GET_INITRD_START(initrd, linux) (initrd - linux) |
| 51 | #endif |
| 52 | |
| 53 | static void set_sh_linux_param(unsigned long param_addr, unsigned long data) |
| 54 | { |
| 55 | *(unsigned long *)(param_addr) = data; |
| 56 | } |
| 57 | |
| 58 | static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base) |
| 59 | { |
| 60 | unsigned long val = 0; |
| 61 | char *p = strstr(cmdline, key); |
| 62 | if (p) { |
| 63 | p += strlen(key); |
| 64 | val = simple_strtol(p, NULL, base); |
| 65 | } |
| 66 | return val; |
| 67 | } |
| 68 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 69 | int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *images) |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 70 | { |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 71 | /* Linux kernel load address */ |
Kumar Gala | c160a95 | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 72 | void (*kernel) (void) = (void (*)(void))images->ep; |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 73 | /* empty_zero_page */ |
Nobuhiro Iwamatsu | b5d10a1 | 2008-09-18 19:34:36 +0900 | [diff] [blame] | 74 | unsigned char *param |
| 75 | = (unsigned char *)image_get_load(images->legacy_hdr_os); |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 76 | /* Linux kernel command line */ |
Nobuhiro Iwamatsu | cf2c87d | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 77 | char *cmdline = (char *)param + COMMAND_LINE; |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 78 | /* PAGE_SIZE */ |
Nobuhiro Iwamatsu | b5d10a1 | 2008-09-18 19:34:36 +0900 | [diff] [blame] | 79 | unsigned long size = images->ep - (unsigned long)param; |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 80 | char *bootargs = getenv("bootargs"); |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 81 | |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 82 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
| 83 | return 1; |
| 84 | |
Nobuhiro Iwamatsu | 9980df5 | 2010-12-08 13:46:36 +0900 | [diff] [blame] | 85 | /* Clear zero page */ |
| 86 | memset(param, 0, size); |
Nobuhiro Iwamatsu | cf2c87d | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 87 | |
| 88 | /* Set commandline */ |
Nobuhiro Iwamatsu | 6b44a43 | 2008-09-17 11:08:36 +0900 | [diff] [blame] | 89 | strcpy(cmdline, bootargs); |
Nobuhiro Iwamatsu | b02bad1 | 2007-09-23 02:12:30 +0900 | [diff] [blame] | 90 | |
Nobuhiro Iwamatsu | cf2c87d | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 91 | /* Initrd */ |
| 92 | if (images->rd_start || images->rd_end) { |
Nobuhiro Iwamatsu | de03f8b | 2010-10-19 17:14:15 +0900 | [diff] [blame] | 93 | unsigned long ramdisk_flags = 0; |
Nobuhiro Iwamatsu | cf2c87d | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 94 | int val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_PROMPT, 10); |
| 95 | if (val == 1) |
| 96 | ramdisk_flags |= RD_PROMPT; |
| 97 | else |
| 98 | ramdisk_flags &= ~RD_PROMPT; |
Wolfgang Denk | 071bc92 | 2010-10-27 22:48:30 +0200 | [diff] [blame] | 99 | |
Nobuhiro Iwamatsu | cf2c87d | 2010-09-28 12:14:57 +0900 | [diff] [blame] | 100 | val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_DOLOAD, 10); |
| 101 | if (val == 1) |
| 102 | ramdisk_flags |= RD_DOLOAD; |
| 103 | else |
| 104 | ramdisk_flags &= ~RD_DOLOAD; |
| 105 | |
| 106 | set_sh_linux_param((unsigned long)param + MOUNT_ROOT_RDONLY, 0x0001); |
| 107 | set_sh_linux_param((unsigned long)param + RAMDISK_FLAGS, ramdisk_flags); |
| 108 | set_sh_linux_param((unsigned long)param + ORIG_ROOT_DEV, 0x0200); |
| 109 | set_sh_linux_param((unsigned long)param + LOADER_TYPE, 0x0001); |
| 110 | set_sh_linux_param((unsigned long)param + INITRD_START, |
| 111 | GET_INITRD_START(images->rd_start, CONFIG_SYS_SDRAM_BASE)); |
| 112 | set_sh_linux_param((unsigned long)param + INITRD_SIZE, |
| 113 | images->rd_end - images->rd_start); |
| 114 | } |
| 115 | |
| 116 | /* Boot kernel */ |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 117 | kernel(); |
Marian Balakowicz | cd7c596 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 118 | |
Nobuhiro Iwamatsu | 9980df5 | 2010-12-08 13:46:36 +0900 | [diff] [blame] | 119 | /* does not return */ |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 120 | return 1; |
Nobuhiro Iwamatsu | 0b135cf | 2007-05-13 20:58:00 +0900 | [diff] [blame] | 121 | } |