fsboot.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * (C) Copyright 2001
  3. * Wave 7 Optics, Inc.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (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, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <config.h>
  25. #include <command.h>
  26. /*
  27. * FIXME: Add code to test image and it's header.
  28. */
  29. extern int valid_elf_image (unsigned long addr);
  30. static int
  31. image_check(ulong addr)
  32. {
  33. return valid_elf_image(addr);
  34. }
  35. void
  36. init_fsboot(void)
  37. {
  38. char *envp;
  39. ulong loadaddr;
  40. ulong testaddr;
  41. ulong alt_loadaddr;
  42. char buf[9];
  43. /*
  44. * Get test image address
  45. */
  46. if ((envp = getenv("testaddr")) != NULL)
  47. testaddr = simple_strtoul(envp, NULL, 16);
  48. else
  49. testaddr = -1;
  50. /*
  51. * Are we going to test boot and image?
  52. */
  53. if ((testaddr != -1) && image_check(testaddr)) {
  54. /* Set alt_loadaddr */
  55. alt_loadaddr = testaddr;
  56. sprintf(buf, "%lX", alt_loadaddr);
  57. setenv("alt_loadaddr", buf);
  58. /* Clear test_addr */
  59. setenv("testaddr", NULL);
  60. /*
  61. * Save current environment with alt_loadaddr,
  62. * and cleared testaddr.
  63. */
  64. saveenv();
  65. /*
  66. * Setup temporary loadaddr to alt_loadaddr
  67. * XXX - DO NOT SAVE ENVIRONMENT!
  68. */
  69. loadaddr = alt_loadaddr;
  70. sprintf(buf, "%lX", loadaddr);
  71. setenv("loadaddr", buf);
  72. } else { /* Normal boot */
  73. setenv("alt_loadaddr", NULL); /* Clear alt_loadaddr */
  74. setenv("testaddr", NULL); /* Clear testaddr */
  75. saveenv();
  76. }
  77. return;
  78. }