eboot.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (C) 2002-2004 by egnite Software GmbH
  3. * Copyright (C) 2010 by egnite GmbH
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the name of the copyright holders nor the names of
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  27. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  28. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  30. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. * For additional information see http://www.ethernut.de/
  34. */
  35. /*
  36. * $Id: eboot.c 4115 2012-04-12 21:06:13Z olereinhardt $
  37. */
  38. #include <avr/io.h>
  39. #include <avr/pgmspace.h>
  40. #include <avr/wdt.h>
  41. #include "config.h"
  42. #include "debug.h"
  43. #include "ether.h"
  44. #include "dhcp.h"
  45. #include "tftp.h"
  46. #include "util.h"
  47. #include "eboot.h"
  48. BOOTFRAME sframe;
  49. BOOTFRAME rframe;
  50. u_long sid;
  51. /*!
  52. * \addtogroup xgEBoot
  53. */
  54. /*@{*/
  55. /*!
  56. * \brief Boot loader entry.
  57. *
  58. * This boot loader is very special. It is completely self
  59. * contained, which means that it runs without any library.
  60. * This entry point must be linked first and will be located
  61. * at byte address 0x1F000 in the program flash ROM.
  62. *
  63. * \return Never, but jumps at absolute address 0 when done.
  64. */
  65. int main(void)
  66. {
  67. #if defined(__AVR_ATmega2561__)
  68. /* unlike ATMega128 the ATMega2561 does not disbale the watchdog */
  69. /* after a reset, so we need to do this here */
  70. MCUSR = 0;
  71. wdt_disable();
  72. #endif
  73. /*
  74. * Enable external data and address bus.
  75. */
  76. MCUCR = _BV(SRE) | _BV(SRW);
  77. DEBUGINIT();
  78. DEBUG("\neboot 2.0.0\n");
  79. BootConfigRead();
  80. /*
  81. * Initialize the network interface controller hardware.
  82. */
  83. DEBUG("ETHERNET ");
  84. if (NicInit() == 0) {
  85. DEBUG("OK\n");
  86. /*
  87. * DHCP query and TFTP download.
  88. */
  89. if (DhcpQuery() == 0 && confboot.cb_image[0])
  90. TftpRecv();
  91. } else {
  92. DEBUG("No\n");
  93. }
  94. /*
  95. * Will jump to the application.
  96. */
  97. return 0;
  98. }
  99. /*@}*/