bootm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (c) Copyright 2008 Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com>
  6. * (c) Copyright 2008 Renesas Solutions Corp.
  7. *
  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. #include <common.h>
  27. #include <command.h>
  28. #include <asm/byteorder.h>
  29. #ifdef CONFIG_SYS_DEBUG
  30. static void hexdump(unsigned char *buf, int len)
  31. {
  32. int i;
  33. for (i = 0; i < len; i++) {
  34. if ((i % 16) == 0)
  35. printf("%s%08x: ", i ? "\n" : "",
  36. (unsigned int)&buf[i]);
  37. printf("%02x ", buf[i]);
  38. }
  39. printf("\n");
  40. }
  41. #endif
  42. #define MOUNT_ROOT_RDONLY 0x000
  43. #define RAMDISK_FLAGS 0x004
  44. #define ORIG_ROOT_DEV 0x008
  45. #define LOADER_TYPE 0x00c
  46. #define INITRD_START 0x010
  47. #define INITRD_SIZE 0x014
  48. #define COMMAND_LINE 0x100
  49. #define RD_PROMPT (1<<15)
  50. #define RD_DOLOAD (1<<14)
  51. #define CMD_ARG_RD_PROMPT "prompt_ramdisk="
  52. #define CMD_ARG_RD_DOLOAD "load_ramdisk="
  53. #ifdef CONFIG_SH_SDRAM_OFFSET
  54. #define GET_INITRD_START(initrd, linux) (initrd - linux + CONFIG_SH_SDRAM_OFFSET)
  55. #else
  56. #define GET_INITRD_START(initrd, linux) (initrd - linux)
  57. #endif
  58. static void set_sh_linux_param(unsigned long param_addr, unsigned long data)
  59. {
  60. *(unsigned long *)(param_addr) = data;
  61. }
  62. static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base)
  63. {
  64. unsigned long val = 0;
  65. char *p = strstr(cmdline, key);
  66. if (p) {
  67. p += strlen(key);
  68. val = simple_strtol(p, NULL, base);
  69. }
  70. return val;
  71. }
  72. int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *images)
  73. {
  74. /* Linux kernel load address */
  75. void (*kernel) (void) = (void (*)(void))images->ep;
  76. /* empty_zero_page */
  77. unsigned char *param
  78. = (unsigned char *)image_get_load(images->legacy_hdr_os);
  79. /* Linux kernel command line */
  80. char *cmdline = (char *)param + COMMAND_LINE;
  81. /* PAGE_SIZE */
  82. unsigned long size = images->ep - (unsigned long)param;
  83. char *bootargs = getenv("bootargs");
  84. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  85. return 1;
  86. /* Setup parameters */
  87. memset(param, 0, size); /* Clear zero page */
  88. /* Set commandline */
  89. strcpy(cmdline, bootargs);
  90. sh_check_cmd_arg(bootargs, CMD_ARG_RD_DOLOAD, 10);
  91. /* Initrd */
  92. if (images->rd_start || images->rd_end) {
  93. unsigned long ramdisk_flags = 0;
  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;
  99. val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_DOLOAD, 10);
  100. if (val == 1)
  101. ramdisk_flags |= RD_DOLOAD;
  102. else
  103. ramdisk_flags &= ~RD_DOLOAD;
  104. set_sh_linux_param((unsigned long)param + MOUNT_ROOT_RDONLY, 0x0001);
  105. set_sh_linux_param((unsigned long)param + RAMDISK_FLAGS, ramdisk_flags);
  106. set_sh_linux_param((unsigned long)param + ORIG_ROOT_DEV, 0x0200);
  107. set_sh_linux_param((unsigned long)param + LOADER_TYPE, 0x0001);
  108. set_sh_linux_param((unsigned long)param + INITRD_START,
  109. GET_INITRD_START(images->rd_start, CONFIG_SYS_SDRAM_BASE));
  110. set_sh_linux_param((unsigned long)param + INITRD_SIZE,
  111. images->rd_end - images->rd_start);
  112. }
  113. /* Boot kernel */
  114. kernel();
  115. /* does not return */
  116. return 1;
  117. }