board.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * (C) Copyright 2004 Atmark Techno, Inc.
  3. *
  4. * Yasushi SHOJI <yashi@atmark-techno.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <command.h>
  26. #include <malloc.h>
  27. #include <version.h>
  28. #include <watchdog.h>
  29. const char version_string[] =
  30. U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")";
  31. /*
  32. * Begin and End of memory area for malloc(), and current "brk"
  33. */
  34. static ulong mem_malloc_start;
  35. static ulong mem_malloc_end;
  36. static ulong mem_malloc_brk;
  37. void *sbrk (ptrdiff_t increment)
  38. {
  39. ulong old = mem_malloc_brk;
  40. ulong new = old + increment;
  41. if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
  42. return (NULL);
  43. }
  44. mem_malloc_brk = new;
  45. return ((void *) old);
  46. }
  47. /*
  48. * All attempts to come up with a "common" initialization sequence
  49. * that works for all boards and architectures failed: some of the
  50. * requirements are just _too_ different. To get rid of the resulting
  51. * mess of board dependend #ifdef'ed code we now make the whole
  52. * initialization sequence configurable to the user.
  53. *
  54. * The requirements for any new initalization function is simple: it
  55. * receives a pointer to the "global data" structure as it's only
  56. * argument, and returns an integer return code, where 0 means
  57. * "continue" and != 0 means "fatal error, hang the system".
  58. */
  59. typedef int (init_fnc_t) (void);
  60. init_fnc_t *init_sequence[] = {
  61. serial_init, /* serial communications setup */
  62. NULL,
  63. };
  64. void board_init(void)
  65. {
  66. DECLARE_GLOBAL_DATA_PTR;
  67. bd_t *bd;
  68. init_fnc_t **init_fnc_ptr;
  69. /* Pointer is writable since we allocated a register for it. */
  70. gd = (gd_t *)CFG_GBL_DATA_OFFSET;
  71. memset((void *)gd, 0, CFG_GBL_DATA_SIZE);
  72. gd->bd = (bd_t *)(gd+1); /* At end of global data */
  73. gd->baudrate = CONFIG_BAUDRATE;
  74. bd = gd->bd;
  75. bd->bi_baudrate = CONFIG_BAUDRATE;
  76. for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
  77. WATCHDOG_RESET ();
  78. if ((*init_fnc_ptr) () != 0) {
  79. hang ();
  80. }
  81. }
  82. /* main_loop */
  83. for (;;) {
  84. WATCHDOG_RESET ();
  85. main_loop ();
  86. }
  87. }
  88. void hang (void)
  89. {
  90. puts ("### ERROR ### Please RESET the board ###\n");
  91. for (;;);
  92. }