1 //==========================================================================
5 // RedBoot command to read and write eeprom content of the
6 // ARM Industrial Module AIM 711
8 //==========================================================================
9 //####ECOSGPLCOPYRIGHTBEGIN####
10 // -------------------------------------------
11 // This file is part of eCos, the Embedded Configurable Operating System.
12 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
13 // Copyright (C) 2003 Gary Thomas
15 // eCos is free software; you can redistribute it and/or modify it under
16 // the terms of the GNU General Public License as published by the Free
17 // Software Foundation; either version 2 or (at your option) any later version.
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 //==========================================================================
43 //#####DESCRIPTIONBEGIN####
45 // Author(s): rcassebohm
46 // Contributors: rcassebohm
51 // RedBoot command to read and write eeprom content of the
52 // ARM Industrial Module AIM 711
53 // This code is part of RedBoot (tm).
55 //####DESCRIPTIONEND####
57 //==========================================================================
59 #include <pkgconf/hal.h>
62 #include <cyg/hal/hal_io.h>
64 // Exported CLI function(s)
65 static void do_eeprom_read(int argc, char *argv[]);
66 RedBoot_cmd("eeprom_read",
67 "Read eeprom content",
68 "-b <location> -o <eeprom offset> -l <length> [-d dump]",
72 static void do_eeprom_write(int argc, char *argv[]);
73 RedBoot_cmd("eeprom_write",
74 "Write eeprom content",
75 "[-b <location>] -o <eeprom offset> [-l <length>]",
80 do_eeprom_read(int argc, char *argv[])
82 bool base_addr_set, offset_set, length_set, dump;
83 unsigned long base_addr, offset, length;
84 struct option_info opts[4];
88 init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
89 (void **)&base_addr, (bool *)&base_addr_set, "location");
90 init_opts(&opts[1], 'o', true, OPTION_ARG_TYPE_NUM,
91 (void **)&offset, (bool *)&offset_set, "eeprom offset");
92 init_opts(&opts[2], 'l', true, OPTION_ARG_TYPE_NUM,
93 (void **)&length, (bool *)&length_set, "length");
94 init_opts(&opts[3], 'd', true, OPTION_ARG_TYPE_FLG,
95 (void **)&dump, 0, "dump data");
96 if (!scan_opts(argc, argv, 1, opts, 4, 0, 0, "")) {
100 if (!base_addr_set || !offset_set || !length_set)
102 diag_printf("usage: eeprom_read -b <location> -o <eeprom offset>"
103 " -l <length> [-d dump]\n");
107 buf = (cyg_uint8 *)base_addr;
108 ret = hal_aim711_eeprom_read(buf, offset, length);
111 diag_printf("Error while trying to read eeprom content\n");
115 diag_printf("Read %d bytes of eeprom content\n", ret);
118 diag_dump_buf((void *)buf, ret);
122 do_eeprom_write(int argc, char *argv[])
124 bool base_addr_set, offset_set, length_set;
125 unsigned long base_addr, offset, length;
126 struct option_info opts[3];
130 base_addr = load_address;
131 length = load_address_end - load_address;
133 init_opts(&opts[0], 'b', true, OPTION_ARG_TYPE_NUM,
134 (void **)&base_addr, (bool *)&base_addr_set, "location");
135 init_opts(&opts[1], 'o', true, OPTION_ARG_TYPE_NUM,
136 (void **)&offset, (bool *)&offset_set, "eeprom offset");
137 init_opts(&opts[2], 'l', true, OPTION_ARG_TYPE_NUM,
138 (void **)&length, (bool *)&length_set, "length");
139 if (!scan_opts(argc, argv, 1, opts, 3, 0, 0, "")) {
145 diag_printf("usage: eeprom_write [-b <location>] -o <eeprom offset>"
150 buf = (cyg_uint8 *)base_addr;
151 ret = hal_aim711_eeprom_write(buf, offset, length);
154 diag_printf("Error while trying to write eeprom content\n");
158 diag_printf("Written %d bytes of eeprom content\n", ret);
161 // EOF redboot_eeprom.c