bootm.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #include <asm/zimage.h>
  30. #ifdef CONFIG_SYS_DEBUG
  31. static void hexdump(unsigned char *buf, int len)
  32. {
  33. int i;
  34. for (i = 0; i < len; i++) {
  35. if ((i % 16) == 0)
  36. printf("%s%08x: ", i ? "\n" : "",
  37. (unsigned int)&buf[i]);
  38. printf("%02x ", buf[i]);
  39. }
  40. printf("\n");
  41. }
  42. #endif
  43. #ifdef CONFIG_SH_SDRAM_OFFSET
  44. #define GET_INITRD_START(initrd, linux) (initrd - linux + CONFIG_SH_SDRAM_OFFSET)
  45. #else
  46. #define GET_INITRD_START(initrd, linux) (initrd - linux)
  47. #endif
  48. static void set_sh_linux_param(unsigned long param_addr, unsigned long data)
  49. {
  50. *(unsigned long *)(param_addr) = data;
  51. }
  52. static unsigned long sh_check_cmd_arg(char *cmdline, char *key, int base)
  53. {
  54. unsigned long val = 0;
  55. char *p = strstr(cmdline, key);
  56. if (p) {
  57. p += strlen(key);
  58. val = simple_strtol(p, NULL, base);
  59. }
  60. return val;
  61. }
  62. int do_bootm_linux(int flag, int argc, char * const argv[], bootm_headers_t *images)
  63. {
  64. /* Linux kernel load address */
  65. void (*kernel) (void) = (void (*)(void))images->ep;
  66. /* empty_zero_page */
  67. unsigned char *param
  68. = (unsigned char *)image_get_load(images->legacy_hdr_os);
  69. /* Linux kernel command line */
  70. char *cmdline = (char *)param + COMMAND_LINE;
  71. /* PAGE_SIZE */
  72. unsigned long size = images->ep - (unsigned long)param;
  73. char *bootargs = getenv("bootargs");
  74. /*
  75. * allow the PREP bootm subcommand, it is required for bootm to work
  76. */
  77. if (flag & BOOTM_STATE_OS_PREP)
  78. return 0;
  79. if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
  80. return 1;
  81. /* Clear zero page */
  82. memset(param, 0, size);
  83. /* Set commandline */
  84. strcpy(cmdline, bootargs);
  85. /* Initrd */
  86. if (images->rd_start || images->rd_end) {
  87. unsigned long ramdisk_flags = 0;
  88. int val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_PROMPT, 10);
  89. if (val == 1)
  90. ramdisk_flags |= RD_PROMPT;
  91. else
  92. ramdisk_flags &= ~RD_PROMPT;
  93. val = sh_check_cmd_arg(bootargs, CMD_ARG_RD_DOLOAD, 10);
  94. if (val == 1)
  95. ramdisk_flags |= RD_DOLOAD;
  96. else
  97. ramdisk_flags &= ~RD_DOLOAD;
  98. set_sh_linux_param((unsigned long)param + MOUNT_ROOT_RDONLY, 0x0001);
  99. set_sh_linux_param((unsigned long)param + RAMDISK_FLAGS, ramdisk_flags);
  100. set_sh_linux_param((unsigned long)param + ORIG_ROOT_DEV, 0x0200);
  101. set_sh_linux_param((unsigned long)param + LOADER_TYPE, 0x0001);
  102. set_sh_linux_param((unsigned long)param + INITRD_START,
  103. GET_INITRD_START(images->rd_start, CONFIG_SYS_SDRAM_BASE));
  104. set_sh_linux_param((unsigned long)param + INITRD_SIZE,
  105. images->rd_end - images->rd_start);
  106. }
  107. /* Boot kernel */
  108. kernel();
  109. /* does not return */
  110. return 1;
  111. }