cmd_fdos.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. char buf [12];
  41. int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
  42. /* pre-set load_addr */
  43. if ((ep = getenv("loadaddr")) != NULL) {
  44. load_addr = simple_strtoul(ep, NULL, 16);
  45. }
  46. /* pre-set Boot file name */
  47. if ((name = getenv("bootfile")) == NULL) {
  48. name = "uImage";
  49. }
  50. switch (argc) {
  51. case 1:
  52. break;
  53. case 2:
  54. /* only one arg - accept two forms:
  55. * just load address, or just boot file name.
  56. * The latter form must be written "filename" here.
  57. */
  58. if (argv[1][0] == '"') { /* just boot filename */
  59. name = argv [1];
  60. } else { /* load address */
  61. load_addr = simple_strtoul(argv[1], NULL, 16);
  62. }
  63. break;
  64. case 3:
  65. load_addr = simple_strtoul(argv[1], NULL, 16);
  66. name = argv [2];
  67. break;
  68. default:
  69. return CMD_RET_USAGE;
  70. }
  71. /* Init physical layer */
  72. if (!fdc_fdos_init (drive)) {
  73. return (-1);
  74. }
  75. /* Open file */
  76. if (dos_open (name) < 0) {
  77. printf ("Unable to open %s\n", name);
  78. return 1;
  79. }
  80. if ((size = dos_read (load_addr)) < 0) {
  81. printf ("boot error\n");
  82. return 1;
  83. }
  84. flush_cache (load_addr, size);
  85. sprintf(buf, "%x", size);
  86. setenv("filesize", buf);
  87. printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n",
  88. size, load_addr);
  89. return bootm_maybe_autostart(cmdtp, argv[0]);
  90. }
  91. /*-----------------------------------------------------------------------------
  92. * do_fdosls --
  93. *-----------------------------------------------------------------------------
  94. */
  95. int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  96. {
  97. char *path = "";
  98. int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
  99. switch (argc) {
  100. case 1:
  101. break;
  102. case 2:
  103. path = argv [1];
  104. break;
  105. }
  106. /* Init physical layer */
  107. if (!fdc_fdos_init (drive)) {
  108. return (-1);
  109. }
  110. /* Open directory */
  111. if (dos_open (path) < 0) {
  112. printf ("Unable to open %s\n", path);
  113. return 1;
  114. }
  115. return (dos_dir ());
  116. }
  117. U_BOOT_CMD(
  118. fdosboot, 3, 0, do_fdosboot,
  119. "boot from a dos floppy file",
  120. "[loadAddr] [filename]"
  121. );
  122. U_BOOT_CMD(
  123. fdosls, 2, 0, do_fdosls,
  124. "list files in a directory",
  125. "[directory]"
  126. );