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