file-loader.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * file-loader - load an elf file into SDRAM and start it
  3. *
  4. * Copyright (c) 2009 Openmoko Inc.
  5. *
  6. * Authors Christopher Hall <hsw@openmoko.com>
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. // these items correspond to the load list
  22. #define APPLICATION_TITLE "Boot WikiReader"
  23. #define APPLICATION_TITLE2 "Boot Forth"
  24. #define APPLICATION_TITLE3 "Boot Calculator"
  25. #define APPLICATION_TITLE4 "Boot Forth (alt)"
  26. #define APPLICATION_TITLE5 "Boot Test Program"
  27. #define APPLICATION_TITLE6 "FLASH MBR"
  28. #define APPLICATION_TITLE7 "FLASH Test Jig"
  29. #include "application.h"
  30. #include "elf32.h"
  31. // each file can have a title above
  32. // so that the menu program can set a start point
  33. static const struct {
  34. const char *filename;
  35. int arg;
  36. } LoadList[] = {
  37. {"kernel.elf", 0}, // status = 0
  38. {"forth.elf", 0}, // status = 1
  39. {"calc.elf", 0}, // status = 2
  40. {"forth.elf", 0}, // status = 3
  41. {"forth.elf", 1}, // only from boot menu
  42. {"flash.elf", 0}, // only from boot menu
  43. {"flash.elf", 1}, // only from boot menu
  44. };
  45. // this must be the first executable code as the loader executes from the first program address
  46. ReturnType file_loader(int block, int status)
  47. {
  48. APPLICATION_INITIALISE();
  49. // boot an elf file
  50. {
  51. unsigned int i = status;
  52. if (ARRAY_SIZE(LoadList) <= i) {
  53. i = 0;
  54. }
  55. //for (; i < ARRAY_SIZE(LoadList); ++i) {
  56. {
  57. print("load: ");
  58. print(LoadList[i].filename);
  59. print_char('\n');
  60. int error = elf32_exec(LoadList[i].filename, LoadList[i].arg);
  61. print("load '");
  62. print(LoadList[i].filename);
  63. print("' error = ");
  64. print_int(error);
  65. print_char('\n');
  66. }
  67. }
  68. APPLICATION_FINALISE(0, 0);
  69. }