board.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <command.h>
  24. #include <malloc.h>
  25. #include <devices.h>
  26. #include <version.h>
  27. #include <net.h>
  28. #include <asm/initcalls.h>
  29. #include <asm/sections.h>
  30. #ifndef CONFIG_IDENT_STRING
  31. #define CONFIG_IDENT_STRING ""
  32. #endif
  33. DECLARE_GLOBAL_DATA_PTR;
  34. const char version_string[] =
  35. U_BOOT_VERSION " (" __DATE__ " - " __TIME__ ") " CONFIG_IDENT_STRING;
  36. unsigned long monitor_flash_len;
  37. /*
  38. * Begin and end of memory area for malloc(), and current "brk"
  39. */
  40. static unsigned long mem_malloc_start = 0;
  41. static unsigned long mem_malloc_end = 0;
  42. static unsigned long mem_malloc_brk = 0;
  43. /* The malloc area is wherever the board wants it to be */
  44. static void mem_malloc_init(void)
  45. {
  46. mem_malloc_start = CFG_MALLOC_START;
  47. mem_malloc_end = CFG_MALLOC_END;
  48. mem_malloc_brk = mem_malloc_start;
  49. printf("malloc: Using memory from 0x%08lx to 0x%08lx\n",
  50. mem_malloc_start, mem_malloc_end);
  51. memset ((void *)mem_malloc_start, 0,
  52. mem_malloc_end - mem_malloc_start);
  53. }
  54. void *sbrk(ptrdiff_t increment)
  55. {
  56. unsigned long old = mem_malloc_brk;
  57. unsigned long new = old + increment;
  58. if ((new < mem_malloc_start) || (new > mem_malloc_end))
  59. return NULL;
  60. mem_malloc_brk = new;
  61. return ((void *)old);
  62. }
  63. static int init_baudrate(void)
  64. {
  65. char tmp[64];
  66. int i;
  67. i = getenv_r("baudrate", tmp, sizeof(tmp));
  68. if (i > 0) {
  69. gd->baudrate = simple_strtoul(tmp, NULL, 10);
  70. } else {
  71. gd->baudrate = CONFIG_BAUDRATE;
  72. }
  73. return 0;
  74. }
  75. static int display_banner (void)
  76. {
  77. printf ("\n\n%s\n\n", version_string);
  78. printf ("U-Boot code: %p -> %p data: %p -> %p\n",
  79. _text, _etext, _data, _end);
  80. return 0;
  81. }
  82. void hang(void)
  83. {
  84. for (;;) ;
  85. }
  86. static int display_dram_config (void)
  87. {
  88. int i;
  89. puts ("DRAM Configuration:\n");
  90. for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
  91. printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
  92. print_size (gd->bd->bi_dram[i].size, "\n");
  93. }
  94. return 0;
  95. }
  96. static void display_flash_config (void)
  97. {
  98. puts ("Flash: ");
  99. print_size(gd->bd->bi_flashsize, " ");
  100. printf("at address 0x%08lx\n", gd->bd->bi_flashstart);
  101. }
  102. void start_u_boot (void)
  103. {
  104. gd_t gd_data;
  105. /* Initialize the global data pointer */
  106. memset(&gd_data, 0, sizeof(gd_data));
  107. gd = &gd_data;
  108. monitor_flash_len = _edata - _text;
  109. /* Perform initialization sequence */
  110. cpu_init();
  111. timer_init();
  112. env_init();
  113. init_baudrate();
  114. serial_init();
  115. console_init_f();
  116. display_banner();
  117. board_init_memories();
  118. mem_malloc_init();
  119. gd->bd = malloc(sizeof(bd_t));
  120. memset(gd->bd, 0, sizeof(bd_t));
  121. gd->bd->bi_baudrate = gd->baudrate;
  122. gd->bd->bi_dram[0].start = CFG_SDRAM_BASE;
  123. gd->bd->bi_dram[0].size = gd->sdram_size;
  124. board_init_info();
  125. flash_init();
  126. if (gd->bd->bi_flashsize)
  127. display_flash_config();
  128. if (gd->bd->bi_dram[0].size)
  129. display_dram_config();
  130. gd->bd->bi_boot_params = malloc(CFG_BOOTPARAMS_LEN);
  131. if (!gd->bd->bi_boot_params)
  132. puts("WARNING: Cannot allocate space for boot parameters\n");
  133. /* initialize environment */
  134. env_relocate();
  135. devices_init();
  136. jumptable_init();
  137. console_init_r();
  138. for (;;) {
  139. main_loop();
  140. }
  141. }