wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
Albert ARIBAUD | fa82f87 | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 3 | * Stäubli Faverges - <www.staubli.com> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 4 | * Pierre AUBERT p.aubert@staubli.com |
| 5 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 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 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 18 | /*----------------------------------------------------------------------------- |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 19 | * do_fdosboot -- |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 20 | *----------------------------------------------------------------------------- |
| 21 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 22 | int do_fdosboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 23 | { |
| 24 | char *name; |
| 25 | char *ep; |
| 26 | int size; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 27 | int drive = CONFIG_SYS_FDC_DRIVE_NUMBER; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 28 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 29 | /* pre-set load_addr */ |
| 30 | if ((ep = getenv("loadaddr")) != NULL) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 31 | load_addr = simple_strtoul(ep, NULL, 16); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | /* pre-set Boot file name */ |
| 35 | if ((name = getenv("bootfile")) == NULL) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 36 | name = "uImage"; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | switch (argc) { |
| 40 | case 1: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 41 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 42 | case 2: |
| 43 | /* only one arg - accept two forms: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 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; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 53 | case 3: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 54 | load_addr = simple_strtoul(argv[1], NULL, 16); |
| 55 | name = argv [2]; |
| 56 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 57 | default: |
Simon Glass | 4c12eeb | 2011-12-10 08:44:01 +0000 | [diff] [blame] | 58 | return CMD_RET_USAGE; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* Init physical layer */ |
| 62 | if (!fdc_fdos_init (drive)) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 63 | return (-1); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 64 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 65 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 66 | /* Open file */ |
| 67 | if (dos_open (name) < 0) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 68 | printf ("Unable to open %s\n", name); |
| 69 | return 1; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 70 | } |
| 71 | if ((size = dos_read (load_addr)) < 0) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 72 | printf ("boot error\n"); |
| 73 | return 1; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 74 | } |
| 75 | flush_cache (load_addr, size); |
| 76 | |
Simon Glass | 41ef372 | 2013-02-24 17:33:22 +0000 | [diff] [blame] | 77 | setenv_hex("filesize", size); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 78 | |
| 79 | printf("Floppy DOS load complete: %d bytes loaded to 0x%lx\n", |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 80 | size, load_addr); |
| 81 | |
Mike Frysinger | 67d668b | 2011-06-05 13:43:02 +0000 | [diff] [blame] | 82 | return bootm_maybe_autostart(cmdtp, argv[0]); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /*----------------------------------------------------------------------------- |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 86 | * do_fdosls -- |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 87 | *----------------------------------------------------------------------------- |
| 88 | */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 89 | int do_fdosls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 90 | { |
| 91 | char *path = ""; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 92 | int drive = CONFIG_SYS_FDC_DRIVE_NUMBER; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 93 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 94 | switch (argc) { |
| 95 | case 1: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 96 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 97 | case 2: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 98 | path = argv [1]; |
| 99 | break; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /* Init physical layer */ |
| 103 | if (!fdc_fdos_init (drive)) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 104 | return (-1); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 105 | } |
| 106 | /* Open directory */ |
| 107 | if (dos_open (path) < 0) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 108 | printf ("Unable to open %s\n", path); |
| 109 | return 1; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 110 | } |
| 111 | return (dos_dir ()); |
| 112 | } |
| 113 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 114 | U_BOOT_CMD( |
| 115 | fdosboot, 3, 0, do_fdosboot, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 116 | "boot from a dos floppy file", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 117 | "[loadAddr] [filename]" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 118 | ); |
| 119 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 120 | U_BOOT_CMD( |
| 121 | fdosls, 2, 0, do_fdosls, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 122 | "list files in a directory", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 123 | "[directory]" |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 124 | ); |