cmd_fdos.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * (C) Copyright 2002
  3. * Stäubli Faverges - <www.staubli.com>
  4. * Pierre AUBERT p.aubert@staubli.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. /*
  25. * Dos floppy support
  26. */
  27. #include <common.h>
  28. #include <config.h>
  29. #include <command.h>
  30. #include <fdc.h>
  31. /*-----------------------------------------------------------------------------
  32. * do_fdosboot --
  33. *-----------------------------------------------------------------------------
  34. */
  35. int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  36. {
  37. char *name;
  38. char *ep;
  39. int size;
  40. int rcode = 0;
  41. char buf [12];
  42. int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
  43. /* pre-set load_addr */
  44. if ((ep = getenv("loadaddr")) != NULL) {
  45. load_addr = simple_strtoul(ep, NULL, 16);
  46. }
  47. /* pre-set Boot file name */
  48. if ((name = getenv("bootfile")) == NULL) {
  49. name = "uImage";
  50. }
  51. switch (argc) {
  52. case 1:
  53. break;
  54. case 2:
  55. /* only one arg - accept two forms:
  56. * just load address, or just boot file name.
  57. * The latter form must be written "filename" here.
  58. */
  59. if (argv[1][0] == '"') { /* just boot filename */
  60. name = argv [1];
  61. } else { /* load address */
  62. load_addr = simple_strtoul(argv[1], NULL, 16);
  63. }
  64. break;
  65. case 3:
  66. load_addr = simple_strtoul(argv[1], NULL, 16);
  67. name = argv [2];
  68. break;
  69. default:
  70. cmd_usage(cmdtp);
  71. break;
  72. }
  73. /* Init physical layer */
  74. if (!fdc_fdos_init (drive)) {
  75. return (-1);
  76. }
  77. /* Open file */
  78. if (dos_open (name) < 0) {
  79. printf ("Unable to open %s\n", name);
  80. return 1;
  81. }
  82. if ((size = dos_read (load_addr)) < 0) {
  83. printf ("boot error\n");
  84. return 1;
  85. }
  86. flush_cache (load_addr, size);
  87. sprintf(buf, "%x", size);
  88. setenv("filesize", buf);
  89. printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n",
  90. size, load_addr);
  91. /* Check if we should attempt an auto-start */
  92. if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
  93. char *local_args[2];
  94. extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
  95. local_args[0] = argv[0];
  96. local_args[1] = NULL;
  97. printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
  98. rcode = do_bootm (cmdtp, 0, 1, local_args);
  99. }
  100. return rcode;
  101. }
  102. /*-----------------------------------------------------------------------------
  103. * do_fdosls --
  104. *-----------------------------------------------------------------------------
  105. */
  106. int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  107. {
  108. char *path = "";
  109. int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
  110. switch (argc) {
  111. case 1:
  112. break;
  113. case 2:
  114. path = argv [1];
  115. break;
  116. }
  117. /* Init physical layer */
  118. if (!fdc_fdos_init (drive)) {
  119. return (-1);
  120. }
  121. /* Open directory */
  122. if (dos_open (path) < 0) {
  123. printf ("Unable to open %s\n", path);
  124. return 1;
  125. }
  126. return (dos_dir ());
  127. }
  128. U_BOOT_CMD(
  129. fdosboot, 3, 0, do_fdosboot,
  130. "boot from a dos floppy file",
  131. "[loadAddr] [filename]"
  132. );
  133. U_BOOT_CMD(
  134. fdosls, 2, 0, do_fdosls,
  135. "list files in a directory",
  136. "[directory]"
  137. );