cmd_fdos.c 3.5 KB

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