Blame view

common/cmd_fdos.c 3.57 KB
2262cfeef   wdenk   * Patch by Daniel...
1
2
  /*
   * (C) Copyright 2002
fa82f871c   Albert ARIBAUD   Convert ISO-8859 ...
3
   * Stäubli Faverges - <www.staubli.com>
2262cfeef   wdenk   * Patch by Daniel...
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
   * Pierre AUBERT  p.aubert@staubli.com
   *
   * See file CREDITS for list of people who contributed to this
   * project.
   *
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License as
   * published by the Free Software Foundation; either version 2 of
   * the License, or (at your option) any later version.
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
   *
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
   * MA 02111-1307 USA
   */
  
  /*
   * Dos floppy support
   */
  
  #include <common.h>
  #include <config.h>
  #include <command.h>
  #include <fdc.h>
2262cfeef   wdenk   * Patch by Daniel...
33
  /*-----------------------------------------------------------------------------
8bde7f776   wdenk   * Code cleanup:
34
   * do_fdosboot --
2262cfeef   wdenk   * Patch by Daniel...
35
36
   *-----------------------------------------------------------------------------
   */
54841ab50   Wolfgang Denk   Make sure that ar...
37
  int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
2262cfeef   wdenk   * Patch by Daniel...
38
39
40
41
  {
      char *name;
      char *ep;
      int size;
fbe4b5cbd   wdenk   * Update TRAB aut...
42
      char buf [12];
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
43
      int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
8bde7f776   wdenk   * Code cleanup:
44

2262cfeef   wdenk   * Patch by Daniel...
45
46
      /* pre-set load_addr */
      if ((ep = getenv("loadaddr")) != NULL) {
8bde7f776   wdenk   * Code cleanup:
47
  	load_addr = simple_strtoul(ep, NULL, 16);
2262cfeef   wdenk   * Patch by Daniel...
48
49
50
51
      }
  
      /* pre-set Boot file name */
      if ((name = getenv("bootfile")) == NULL) {
8bde7f776   wdenk   * Code cleanup:
52
  	name = "uImage";
2262cfeef   wdenk   * Patch by Daniel...
53
54
55
56
      }
  
      switch (argc) {
      case 1:
8bde7f776   wdenk   * Code cleanup:
57
  	break;
2262cfeef   wdenk   * Patch by Daniel...
58
59
      case 2:
  	/* only one arg - accept two forms:
8bde7f776   wdenk   * Code cleanup:
60
61
62
63
64
65
66
67
68
  	 * just load address, or just boot file name.
  	 * The latter form must be written "filename" here.
  	 */
  	if (argv[1][0] == '"') {	/* just boot filename */
  	    name = argv [1];
  	} else {			/* load address	*/
  	    load_addr = simple_strtoul(argv[1], NULL, 16);
  	}
  	break;
2262cfeef   wdenk   * Patch by Daniel...
69
      case 3:
8bde7f776   wdenk   * Code cleanup:
70
71
72
  	load_addr = simple_strtoul(argv[1], NULL, 16);
  	name = argv [2];
  	break;
2262cfeef   wdenk   * Patch by Daniel...
73
      default:
4c12eeb8b   Simon Glass   Convert cmd_usage...
74
  	return CMD_RET_USAGE;
2262cfeef   wdenk   * Patch by Daniel...
75
76
77
78
      }
  
      /* Init physical layer                                                   */
      if (!fdc_fdos_init (drive)) {
8bde7f776   wdenk   * Code cleanup:
79
  	return (-1);
2262cfeef   wdenk   * Patch by Daniel...
80
      }
8bde7f776   wdenk   * Code cleanup:
81

2262cfeef   wdenk   * Patch by Daniel...
82
83
      /* Open file                                                             */
      if (dos_open (name) < 0) {
8bde7f776   wdenk   * Code cleanup:
84
85
86
  	printf ("Unable to open %s
  ", name);
  	return 1;
2262cfeef   wdenk   * Patch by Daniel...
87
88
      }
      if ((size = dos_read (load_addr)) < 0) {
8bde7f776   wdenk   * Code cleanup:
89
90
91
  	printf ("boot error
  ");
  	return 1;
2262cfeef   wdenk   * Patch by Daniel...
92
93
94
95
96
97
98
99
      }
      flush_cache (load_addr, size);
  
      sprintf(buf, "%x", size);
      setenv("filesize", buf);
  
      printf("Floppy DOS load complete: %d bytes loaded to 0x%lx
  ",
8bde7f776   wdenk   * Code cleanup:
100
  	   size, load_addr);
67d668bf9   Mike Frysinger   autostart: unify ...
101
      return bootm_maybe_autostart(cmdtp, argv[0]);
2262cfeef   wdenk   * Patch by Daniel...
102
103
104
  }
  
  /*-----------------------------------------------------------------------------
8bde7f776   wdenk   * Code cleanup:
105
   * do_fdosls --
2262cfeef   wdenk   * Patch by Daniel...
106
107
   *-----------------------------------------------------------------------------
   */
54841ab50   Wolfgang Denk   Make sure that ar...
108
  int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
2262cfeef   wdenk   * Patch by Daniel...
109
110
  {
      char *path = "";
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
111
      int drive = CONFIG_SYS_FDC_DRIVE_NUMBER;
8bde7f776   wdenk   * Code cleanup:
112

2262cfeef   wdenk   * Patch by Daniel...
113
114
      switch (argc) {
      case 1:
8bde7f776   wdenk   * Code cleanup:
115
  	break;
2262cfeef   wdenk   * Patch by Daniel...
116
      case 2:
8bde7f776   wdenk   * Code cleanup:
117
118
  	path = argv [1];
  	break;
2262cfeef   wdenk   * Patch by Daniel...
119
120
121
122
      }
  
      /* Init physical layer                                                   */
      if (!fdc_fdos_init (drive)) {
8bde7f776   wdenk   * Code cleanup:
123
  	return (-1);
2262cfeef   wdenk   * Patch by Daniel...
124
125
126
      }
      /* Open directory                                                        */
      if (dos_open (path) < 0) {
8bde7f776   wdenk   * Code cleanup:
127
128
129
  	printf ("Unable to open %s
  ", path);
  	return 1;
2262cfeef   wdenk   * Patch by Daniel...
130
131
132
      }
      return (dos_dir ());
  }
0d4983930   wdenk   Patch by Kenneth ...
133
134
  U_BOOT_CMD(
  	fdosboot,	3,	0,	do_fdosboot,
2fb2604d5   Peter Tyser   Command usage cle...
135
  	"boot from a dos floppy file",
a89c33db9   Wolfgang Denk   General help mess...
136
  	"[loadAddr] [filename]"
8bde7f776   wdenk   * Code cleanup:
137
  );
0d4983930   wdenk   Patch by Kenneth ...
138
139
  U_BOOT_CMD(
  	fdosls,	2,	0,	do_fdosls,
2fb2604d5   Peter Tyser   Command usage cle...
140
  	"list files in a directory",
a89c33db9   Wolfgang Denk   General help mess...
141
  	"[directory]"
8bde7f776   wdenk   * Code cleanup:
142
  );