]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/hal/arm/aim711/v2_0/src/redboot_eeprom.c
Initial revision
[karo-tx-redboot.git] / packages / hal / arm / aim711 / v2_0 / src / redboot_eeprom.c
1 //==========================================================================
2 //
3 //      redboot_eeprom.c
4 //
5 //      RedBoot command to read and write eeprom content of the
6 //      ARM Industrial Module AIM 711
7 //
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
14 //
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.
18 //
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
22 // for more details.
23 //
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.
27 //
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.
34 //
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.
37 //
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####
44 //
45 // Author(s):    rcassebohm
46 // Contributors: rcassebohm
47 // Date:         2003-11-10
48 // Purpose:      
49 // Description:  
50 //              
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).
54 //
55 //####DESCRIPTIONEND####
56 //
57 //==========================================================================
58
59 #include <pkgconf/hal.h>
60 #include <redboot.h>
61
62 #include <cyg/hal/hal_io.h>
63
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]",
69             do_eeprom_read
70     );
71
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>]",
76             do_eeprom_write
77     );
78
79 static void 
80 do_eeprom_read(int argc, char *argv[])
81 {
82     bool base_addr_set, offset_set, length_set, dump;
83     unsigned long base_addr, offset, length;
84     struct option_info opts[4];
85     cyg_uint8 *buf;
86     int ret;
87
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, "")) {
97         return;
98     }
99
100     if (!base_addr_set || !offset_set || !length_set)
101     {
102         diag_printf("usage: eeprom_read -b <location> -o <eeprom offset>"
103                 " -l <length> [-d dump]\n");
104         return;
105     }
106
107     buf = (cyg_uint8 *)base_addr;
108     ret = hal_aim711_eeprom_read(buf, offset, length);
109     if (ret < 0)
110     {
111         diag_printf("Error while trying to read eeprom content\n");
112         return;
113     }
114  
115     diag_printf("Read %d bytes of eeprom content\n", ret);
116
117     if (dump)
118         diag_dump_buf((void *)buf, ret);
119 }
120
121 static void 
122 do_eeprom_write(int argc, char *argv[])
123 {
124     bool base_addr_set, offset_set, length_set;
125     unsigned long base_addr, offset, length;
126     struct option_info opts[3];
127     cyg_uint8 *buf;
128     int ret;
129
130     base_addr = load_address;
131     length = load_address_end - load_address;
132
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, "")) {
140         return;
141     }
142
143     if (!offset_set)
144     {
145         diag_printf("usage: eeprom_write [-b <location>] -o <eeprom offset>"
146                 " [-l <length>]\n");
147         return;
148     }
149
150     buf = (cyg_uint8 *)base_addr;
151     ret = hal_aim711_eeprom_write(buf, offset, length);
152     if (ret < 0)
153     {
154         diag_printf("Error while trying to write eeprom content\n");
155         return;
156     }
157  
158     diag_printf("Written %d bytes of eeprom content\n", ret);
159 }
160       
161 // EOF redboot_eeprom.c