cmd_fdos.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #if (CONFIG_COMMANDS & CFG_CMD_FDOS)
  32. /*-----------------------------------------------------------------------------
  33. * do_fdosboot --
  34. *-----------------------------------------------------------------------------
  35. */
  36. int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  37. {
  38. char *name;
  39. char *ep;
  40. int size;
  41. int rcode = 0;
  42. char buf [10];
  43. int drive = CFG_FDC_DRIVE_NUMBER;
  44. /* pre-set load_addr */
  45. if ((ep = getenv("loadaddr")) != NULL) {
  46. load_addr = simple_strtoul(ep, NULL, 16);
  47. }
  48. /* pre-set Boot file name */
  49. if ((name = getenv("bootfile")) == NULL) {
  50. name = "pImage";
  51. }
  52. switch (argc) {
  53. case 1:
  54. break;
  55. case 2:
  56. /* only one arg - accept two forms:
  57. * just load address, or just boot file name.
  58. * The latter form must be written "filename" here.
  59. */
  60. if (argv[1][0] == '"') { /* just boot filename */
  61. name = argv [1];
  62. } else { /* load address */
  63. load_addr = simple_strtoul(argv[1], NULL, 16);
  64. }
  65. break;
  66. case 3:
  67. load_addr = simple_strtoul(argv[1], NULL, 16);
  68. name = argv [2];
  69. break;
  70. default:
  71. printf ("Usage:\n%s\n", cmdtp->usage);
  72. break;
  73. }
  74. /* Init physical layer */
  75. if (!fdc_fdos_init (drive)) {
  76. return (-1);
  77. }
  78. /* Open file */
  79. if (dos_open (name) < 0) {
  80. printf ("Unable to open %s\n", name);
  81. return 1;
  82. }
  83. if ((size = dos_read (load_addr)) < 0) {
  84. printf ("boot error\n");
  85. return 1;
  86. }
  87. flush_cache (load_addr, size);
  88. sprintf(buf, "%x", size);
  89. setenv("filesize", buf);
  90. printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n",
  91. size, load_addr);
  92. /* Check if we should attempt an auto-start */
  93. if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
  94. char *local_args[2];
  95. extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
  96. local_args[0] = argv[0];
  97. local_args[1] = NULL;
  98. printf ("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
  99. rcode = do_bootm (cmdtp, 0, 1, local_args);
  100. }
  101. return rcode;
  102. }
  103. /*-----------------------------------------------------------------------------
  104. * do_fdosls --
  105. *-----------------------------------------------------------------------------
  106. */
  107. int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  108. {
  109. char *path = "";
  110. int drive = CFG_FDC_DRIVE_NUMBER;
  111. switch (argc) {
  112. case 1:
  113. break;
  114. case 2:
  115. path = argv [1];
  116. break;
  117. }
  118. /* Init physical layer */
  119. if (!fdc_fdos_init (drive)) {
  120. return (-1);
  121. }
  122. /* Open directory */
  123. if (dos_open (path) < 0) {
  124. printf ("Unable to open %s\n", path);
  125. return 1;
  126. }
  127. return (dos_dir ());
  128. }
  129. #endif