cmd_fdos.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 * const 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. return cmd_usage(cmdtp);
  71. }
  72. /* Init physical layer */
  73. if (!fdc_fdos_init (drive)) {
  74. return (-1);
  75. }
  76. /* Open file */
  77. if (dos_open (name) < 0) {
  78. printf ("Unable to open %s\n", name);
  79. return 1;
  80. }
  81. if ((size = dos_read (load_addr)) < 0) {
  82. printf ("boot error\n");
  83. return 1;
  84. }
  85. flush_cache (load_addr, size);
  86. sprintf(buf, "%x", size);
  87. setenv("filesize", buf);
  88. printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n",
  89. size, load_addr);
  90. /* Check if we should attempt an auto-start */
  91. if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
  92. char *local_args[2];
  93. local_args[0] = argv[0];
  94. local_args[1] = NULL;
  95. printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
  96. rcode = do_bootm (cmdtp, 0, 1, local_args);
  97. }
  98. return rcode;
  99. }
  100. /*-----------------------------------------------------------------------------
  101. * do_fdosls --
  102. *-----------------------------------------------------------------------------
  103. */
  104. int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  105. {
  106. char *path = "";
  107. int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
  108. switch (argc) {
  109. case 1:
  110. break;
  111. case 2:
  112. path = argv [1];
  113. break;
  114. }
  115. /* Init physical layer */
  116. if (!fdc_fdos_init (drive)) {
  117. return (-1);
  118. }
  119. /* Open directory */
  120. if (dos_open (path) < 0) {
  121. printf ("Unable to open %s\n", path);
  122. return 1;
  123. }
  124. return (dos_dir ());
  125. }
  126. U_BOOT_CMD(
  127. fdosboot, 3, 0, do_fdosboot,
  128. "boot from a dos floppy file",
  129. "[loadAddr] [filename]"
  130. );
  131. U_BOOT_CMD(
  132. fdosls, 2, 0, do_fdosls,
  133. "list files in a directory",
  134. "[directory]"
  135. );