cmd_fdos.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * (C) Copyright 2002
  3. * Stäubli Faverges - <www.staubli.com>
  4. * Pierre AUBERT p.aubert@staubli.com
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. /*
  9. * Dos floppy support
  10. */
  11. #include <common.h>
  12. #include <config.h>
  13. #include <command.h>
  14. #include <fdc.h>
  15. /*-----------------------------------------------------------------------------
  16. * do_fdosboot --
  17. *-----------------------------------------------------------------------------
  18. */
  19. int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  20. {
  21. char *name;
  22. char *ep;
  23. int size;
  24. int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
  25. /* pre-set load_addr */
  26. if ((ep = getenv("loadaddr")) != NULL) {
  27. load_addr = simple_strtoul(ep, NULL, 16);
  28. }
  29. /* pre-set Boot file name */
  30. if ((name = getenv("bootfile")) == NULL) {
  31. name = "uImage";
  32. }
  33. switch (argc) {
  34. case 1:
  35. break;
  36. case 2:
  37. /* only one arg - accept two forms:
  38. * just load address, or just boot file name.
  39. * The latter form must be written "filename" here.
  40. */
  41. if (argv[1][0] == '"') { /* just boot filename */
  42. name = argv [1];
  43. } else { /* load address */
  44. load_addr = simple_strtoul(argv[1], NULL, 16);
  45. }
  46. break;
  47. case 3:
  48. load_addr = simple_strtoul(argv[1], NULL, 16);
  49. name = argv [2];
  50. break;
  51. default:
  52. return CMD_RET_USAGE;
  53. }
  54. /* Init physical layer */
  55. if (!fdc_fdos_init (drive)) {
  56. return (-1);
  57. }
  58. /* Open file */
  59. if (dos_open (name) < 0) {
  60. printf ("Unable to open %s\n", name);
  61. return 1;
  62. }
  63. if ((size = dos_read (load_addr)) < 0) {
  64. printf ("boot error\n");
  65. return 1;
  66. }
  67. flush_cache (load_addr, size);
  68. setenv_hex("filesize", size);
  69. printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n",
  70. size, load_addr);
  71. return bootm_maybe_autostart(cmdtp, argv[0]);
  72. }
  73. /*-----------------------------------------------------------------------------
  74. * do_fdosls --
  75. *-----------------------------------------------------------------------------
  76. */
  77. int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  78. {
  79. char *path = "";
  80. int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
  81. switch (argc) {
  82. case 1:
  83. break;
  84. case 2:
  85. path = argv [1];
  86. break;
  87. }
  88. /* Init physical layer */
  89. if (!fdc_fdos_init (drive)) {
  90. return (-1);
  91. }
  92. /* Open directory */
  93. if (dos_open (path) < 0) {
  94. printf ("Unable to open %s\n", path);
  95. return 1;
  96. }
  97. return (dos_dir ());
  98. }
  99. U_BOOT_CMD(
  100. fdosboot, 3, 0, do_fdosboot,
  101. "boot from a dos floppy file",
  102. "[loadAddr] [filename]"
  103. );
  104. U_BOOT_CMD(
  105. fdosls, 2, 0, do_fdosls,
  106. "list files in a directory",
  107. "[directory]"
  108. );