annotate packages/redboot/current/src/fconfig.c @ 2863:7d8c61e6225c default tip

* Added execute permissions to files missed in conversion from CVS
author alexs
date Thu, 26 Mar 2009 20:39:18 +0000
parents e6d5126cb479
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1 //==========================================================================
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
2 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
3 // fconfig.c
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
4 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
5 // RedBoot - persistent data storage support (FLASH or EEPROM)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
6 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
7 //==========================================================================
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
8 // ####ECOSGPLCOPYRIGHTBEGIN####
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
9 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
10 // This file is part of eCos, the Embedded Configurable Operating System.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008 Free Software Foundation, Inc.
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
12 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
13 // eCos is free software; you can redistribute it and/or modify it under
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
14 // the terms of the GNU General Public License as published by the Free
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
15 // Software Foundation; either version 2 or (at your option) any later
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
16 // version.
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
17 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
18 // eCos is distributed in the hope that it will be useful, but WITHOUT
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
21 // for more details.
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
22 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
23 // You should have received a copy of the GNU General Public License
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
24 // along with eCos; if not, write to the Free Software Foundation, Inc.,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
26 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
27 // As a special exception, if other files instantiate templates or use
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
28 // macros or inline functions from this file, or you compile this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
29 // and link it with other works to produce a work based on this file,
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
30 // this file does not by itself cause the resulting work to be covered by
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
31 // the GNU General Public License. However the source code for this file
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
32 // must still be made available in accordance with section (3) of the GNU
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
33 // General Public License v2.
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
34 //
2729
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
35 // This exception does not invalidate any other reasons why a work based
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
36 // on this file might be covered by the GNU General Public License.
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
37 // -------------------------------------------
74dbf4c3f2e1 Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents: 2644
diff changeset
38 // ####ECOSGPLCOPYRIGHTEND####
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
39 //==========================================================================
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
40 //#####DESCRIPTIONBEGIN####
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
41 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
42 // Author(s): gthomas
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
43 // Contributors: gthomas, tkoeller
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
44 // Date: 2000-07-28
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
45 // Purpose:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
46 // Description:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
47 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
48 // This code is part of RedBoot (tm).
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
49 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
50 //####DESCRIPTIONEND####
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
51 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
52 //==========================================================================
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
53
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
54 #include <redboot.h>
1740
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
55 #include <cyg/io/flash.h>
1248
c6965db486b0 Honor FIS/FLASH configury
gthomas
parents: 1225
diff changeset
56 #ifdef CYGOPT_REDBOOT_FIS
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
57 #include <fis.h>
1248
c6965db486b0 Honor FIS/FLASH configury
gthomas
parents: 1225
diff changeset
58 #endif
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
59
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
60 #ifdef CYGSEM_REDBOOT_FLASH_COMBINED_FIS_AND_CONFIG
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
61 // Note horrid intertwining of functions, to save precious FLASH
1740
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
62 externC void fis_read_directory(void);
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
63 externC void fis_update_directory(void);
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
64 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
65
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
66 #ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_EEPROM
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
67 externC void write_eeprom(void *buf, int len);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
68 externC void read_eeprom(void *buf, int len);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
69 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
70
1265
734edfe6c859 Allow platform to provide routine to validate ethernet addresses
gthomas
parents: 1259
diff changeset
71 #ifdef CYGSEM_REDBOOT_PLF_ESA_VALIDATE
734edfe6c859 Allow platform to provide routine to validate ethernet addresses
gthomas
parents: 1259
diff changeset
72 externC bool cyg_plf_redboot_esa_validate(unsigned char *val);
734edfe6c859 Allow platform to provide routine to validate ethernet addresses
gthomas
parents: 1259
diff changeset
73 #endif
734edfe6c859 Allow platform to provide routine to validate ethernet addresses
gthomas
parents: 1259
diff changeset
74
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
75 #ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
2195
5c5e93c863ac Redundant FIS table support - from Alexander Neundorf
gthomas
parents: 2010
diff changeset
76 externC int do_flash_init(void);
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
77 #include <cyg/io/flash.h>
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
78 #endif
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
79
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
80 // Round a quantity up
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
81 #define _rup(n,s) ((((n)+(s-1))/s)*s)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
82
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
83 #include <flash_config.h>
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
84
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
85 // Configuration data, saved in FLASH, used to set/update RedBoot
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
86 // normal "configuration" data items.
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
87 struct _config *config, *backup_config;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
88
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
89 // Local data used by these routines
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
90 #ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
91 extern cyg_flashaddr_t flash_start, flash_end;
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
92 extern size_t flash_block_size;
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
93 extern cyg_uint32 flash_num_blocks;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
94 extern int __flash_init;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
95 #ifdef CYGOPT_REDBOOT_FIS
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
96 extern void *fis_work_block;
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
97 extern cyg_flashaddr_t fis_addr;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
98 extern int fisdir_size; // Size of FIS directory.
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
99 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
100 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
101 static struct _config *readonly_config;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
102 #endif
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
103 cyg_flashaddr_t cfg_base; // Location in Flash of config data
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
104 size_t cfg_size; // Length of config data - rounded to Flash block size
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
105 #endif // FLASH MEDIA
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
106
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
107 // Prototypes for local functions
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
108 static char *flash_lookup_config(char *key);
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
109
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
110 static bool config_ok;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
111
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
112 #define CONFIG_KEY1 0x0BADFACE
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
113 #define CONFIG_KEY2 0xDEADDEAD
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
114
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
115 #define CONFIG_DONE 0
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
116 #define CONFIG_ABORT -1
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
117 #define CONFIG_CHANGED 1
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
118 #define CONFIG_OK 2
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
119 #define CONFIG_BACK 3
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
120 #define CONFIG_BAD 4
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
121
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
122 // Note: the following options are related. If 'boot_script' is false, then
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
123 // the other values are used in the configuration. Because of the way
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
124 // that configuration tables are generated, they should have names which
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
125 // are related. The configuration options will show up lexicographically
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
126 // ordered, thus the peculiar naming.
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
127 RedBoot_config_option("Run script at boot",
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
128 boot_script,
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
129 ALWAYS_ENABLED, true,
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
130 CONFIG_BOOL,
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
131 false
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
132 );
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
133 RedBoot_config_option("Boot script",
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
134 boot_script_data,
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
135 "boot_script", true,
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
136 CONFIG_SCRIPT,
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
137 ""
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
138 );
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
139 // Some preprocessor magic for building the [constant] prompt string
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
140 #define __cat(s1,c2,s3) s1 #c2 s3
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
141 #define _cat(s1,c2,s3) __cat(s1,c2,s3)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
142 RedBoot_config_option(_cat("Boot script timeout (",
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
143 CYGNUM_REDBOOT_BOOT_SCRIPT_TIMEOUT_RESOLUTION,
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
144 "ms resolution)"),
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
145 boot_script_timeout,
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
146 "boot_script", true,
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
147 CONFIG_INT,
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
148 0
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
149 );
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
150 #undef __cat
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
151 #undef _cat
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
152
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
153 #ifdef CYGSEM_REDBOOT_VARIABLE_BAUD_RATE
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
154 RedBoot_config_option("Console baud rate",
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
155 console_baud_rate,
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
156 ALWAYS_ENABLED, true,
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
157 CONFIG_INT,
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
158 CYGNUM_HAL_VIRTUAL_VECTOR_CONSOLE_CHANNEL_BAUD
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
159 );
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
160 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
161
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
162 CYG_HAL_TABLE_BEGIN( __CONFIG_options_TAB__, RedBoot_config_options);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
163 CYG_HAL_TABLE_END( __CONFIG_options_TAB_END__, RedBoot_config_options);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
164
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
165 extern struct config_option __CONFIG_options_TAB__[], __CONFIG_options_TAB_END__[];
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
166
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
167 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
168 // Layout of config data
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
169 // Each data item is variable length, with the name, type and dependencies
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
170 // encoded into the object.
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
171 // offset contents
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
172 // 0 data type
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
173 // 1 length of name (N)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
174 // 2 enable sense
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
175 // 3 length of enable key (M)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
176 // 4 key name
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
177 // N+4 enable key
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
178 // M+N+4 data value
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
179 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
180
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
181 #define CONFIG_OBJECT_TYPE(dp) (dp)[0]
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
182 #define CONFIG_OBJECT_KEYLEN(dp) (dp)[1]
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
183 #define CONFIG_OBJECT_ENABLE_SENSE(dp) (dp)[2]
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
184 #define CONFIG_OBJECT_ENABLE_KEYLEN(dp) (dp)[3]
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
185 #define CONFIG_OBJECT_KEY(dp) ((dp)+4)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
186 #define CONFIG_OBJECT_ENABLE_KEY(dp) ((dp)+4+CONFIG_OBJECT_KEYLEN(dp))
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
187 #define CONFIG_OBJECT_VALUE(dp) ((dp)+4+CONFIG_OBJECT_KEYLEN(dp)+CONFIG_OBJECT_ENABLE_KEYLEN(dp))
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
188
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
189 #define LIST_OPT_LIST_ONLY (1)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
190 #define LIST_OPT_NICKNAMES (2)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
191 #define LIST_OPT_FULLNAMES (4)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
192 #define LIST_OPT_DUMBTERM (8)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
193
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
194 static void config_init(void);
1740
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
195 static int config_length(int type);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
196
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
197 // Change endianness of config data
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
198 void
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
199 conf_endian_fixup(void *ptr)
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
200 {
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
201 #ifdef REDBOOT_FLASH_REVERSE_BYTEORDER
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
202 struct _config *p = (struct _config *)ptr;
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
203 char *dp = p->config_data;
1740
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
204 void *val_ptr;
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
205 int len;
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
206 cyg_uint16 u16;
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
207 cyg_uint32 u32;
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
208
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
209 p->len = CYG_SWAP32(p->len);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
210 p->key1 = CYG_SWAP32(p->key1);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
211 p->key2 = CYG_SWAP32(p->key2);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
212 p->cksum = CYG_SWAP32(p->cksum);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
213
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
214 while (dp < &p->config_data[sizeof(config->config_data)]) {
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
215 len = 4 + CONFIG_OBJECT_KEYLEN(dp) + CONFIG_OBJECT_ENABLE_KEYLEN(dp) +
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
216 config_length(CONFIG_OBJECT_TYPE(dp));
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
217 val_ptr = (void *)CONFIG_OBJECT_VALUE(dp);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
218
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
219 switch (CONFIG_OBJECT_TYPE(dp)) {
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
220 // Note: the data may be unaligned in the configuration data
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
221 case CONFIG_BOOL:
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
222 if (sizeof(bool) == 2) {
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
223 memcpy(&u16, val_ptr, 2);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
224 u16 = CYG_SWAP16(u16);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
225 memcpy(val_ptr, &u16, 2);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
226 } else if (sizeof(bool) == 4) {
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
227 memcpy(&u32, val_ptr, 4);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
228 u32 = CYG_SWAP32(u32);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
229 memcpy(val_ptr, &u32, 4);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
230 }
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
231 break;
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
232 case CONFIG_INT:
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
233 if (sizeof(unsigned long) == 2) {
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
234 memcpy(&u16, val_ptr, 2);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
235 u16 = CYG_SWAP16(u16);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
236 memcpy(val_ptr, &u16, 2);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
237 } else if (sizeof(unsigned long) == 4) {
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
238 memcpy(&u32, val_ptr, 4);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
239 u32 = CYG_SWAP32(u32);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
240 memcpy(val_ptr, &u32, 4);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
241 }
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
242 break;
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
243 }
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
244
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
245 dp += len;
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
246 }
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
247 #endif
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
248 }
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
249
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
250 static int
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
251 get_config(char *dp, char *title, int list_opt, char *newvalue )
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
252 {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
253 char line[256], hold_line[256], *sp, *lp;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
254 int ret;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
255 bool hold_bool_val, new_bool_val, enable;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
256 unsigned long hold_int_val, new_int_val;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
257 #ifdef CYGPKG_REDBOOT_NETWORKING
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
258 in_addr_t hold_ip_val, new_ip_val;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
259 enet_addr_t hold_esa_val;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
260 int esa_ptr;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
261 char *esp;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
262 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
263 void *val_ptr;
2010
2379473fdc8d * src/fconfig.c: (get_config): Verify the length of the script is
asl
parents: 1822
diff changeset
264 int type, script_len;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
265
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
266 if (CONFIG_OBJECT_ENABLE_KEYLEN(dp)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
267 flash_get_config(CONFIG_OBJECT_ENABLE_KEY(dp), &enable, CONFIG_BOOL);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
268 if (((bool)CONFIG_OBJECT_ENABLE_SENSE(dp) && !enable) ||
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
269 (!(bool)CONFIG_OBJECT_ENABLE_SENSE(dp) && enable)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
270 return CONFIG_OK; // Disabled field
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
271 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
272 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
273 lp = line; *lp = '\0';
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
274 val_ptr = (void *)CONFIG_OBJECT_VALUE(dp);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
275 if (LIST_OPT_NICKNAMES & list_opt)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
276 diag_printf("%s: ", CONFIG_OBJECT_KEY(dp));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
277 if (LIST_OPT_FULLNAMES & list_opt) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
278 if (title != (char *)NULL) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
279 diag_printf("%s: ", title);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
280 } else {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
281 diag_printf("%s: ", CONFIG_OBJECT_KEY(dp));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
282 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
283 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
284 switch (type = CONFIG_OBJECT_TYPE(dp)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
285 case CONFIG_BOOL:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
286 memcpy(&hold_bool_val, val_ptr, sizeof(bool));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
287 lp += diag_sprintf(lp, "%s", hold_bool_val ? "true" : "false");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
288 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
289 case CONFIG_INT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
290 memcpy(&hold_int_val, val_ptr, sizeof(unsigned long));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
291 lp += diag_sprintf(lp, "%ld", hold_int_val);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
292 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
293 #ifdef CYGPKG_REDBOOT_NETWORKING
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
294 case CONFIG_IP:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
295 lp += diag_sprintf(lp, "%s", inet_ntoa((in_addr_t *)val_ptr));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
296 if (0 == strcmp("0.0.0.0", line) && !(LIST_OPT_LIST_ONLY & list_opt)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
297 // then we have a deeply unhelpful starting text - kill it off
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
298 // (unless we are just listing all values)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
299 lp = line; *lp = '\0';
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
300 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
301 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
302 case CONFIG_ESA:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
303 for (esa_ptr = 0; esa_ptr < sizeof(enet_addr_t); esa_ptr++) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
304 lp += diag_sprintf(lp, "0x%02X", ((unsigned char *)val_ptr)[esa_ptr]);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
305 if (esa_ptr < (sizeof(enet_addr_t)-1)) lp += diag_sprintf(lp, ":");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
306 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
307 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
308 #if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
309 case CONFIG_NETPORT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
310 lp += diag_sprintf(lp, "%s", (unsigned char *)val_ptr);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
311 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
312 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
313 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
314 case CONFIG_STRING:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
315 lp += diag_sprintf(lp, "%s", (unsigned char *)val_ptr);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
316 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
317 case CONFIG_SCRIPT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
318 diag_printf("\n");
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
319 sp = lp = (char *)val_ptr;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
320 while (*sp) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
321 while (*lp != '\n') lp++;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
322 *lp = '\0';
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
323 diag_printf(".. %s\n", sp);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
324 *lp++ = '\n';
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
325 sp = lp;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
326 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
327 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
328 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
329 if (LIST_OPT_LIST_ONLY & list_opt) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
330 diag_printf("%s\n", line);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
331 return CONFIG_OK;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
332 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
333 if (type != CONFIG_SCRIPT) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
334 if (NULL != newvalue) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
335 ret = strlen(newvalue);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
336 if (ret > sizeof(line))
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
337 return CONFIG_BAD;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
338 strcpy(hold_line, line); // Hold the old value for comparison
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
339 strcpy(line, newvalue);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
340 diag_printf("Setting to %s\n", newvalue);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
341 } else {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
342 // read from terminal
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
343 strcpy(hold_line, line);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
344 if (LIST_OPT_DUMBTERM & list_opt) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
345 diag_printf( (CONFIG_STRING == type ?
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
346 "%s > " :
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
347 "%s ? " ), line);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
348 *line = '\0';
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
349 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
350 ret = _rb_gets_preloaded(line, sizeof(line), 0);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
351 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
352 if (ret < 0) return CONFIG_ABORT;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
353 // empty input - leave value untouched (else DNS goes away for a
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
354 // minute to try to look it up) but we must accept empty value for strings.
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
355 if (0 == line[0] && CONFIG_STRING != type) return CONFIG_OK;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
356 if (strcmp(line, hold_line) == 0) return CONFIG_OK; // Just a CR - leave value untouched
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
357 lp = &line[strlen(line)-1];
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
358 if (*lp == '.') return CONFIG_DONE;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
359 if (*lp == '^') return CONFIG_BACK;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
360 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
361 switch (type) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
362 case CONFIG_BOOL:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
363 memcpy(&hold_bool_val, val_ptr, sizeof(bool));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
364 if (!parse_bool(line, &new_bool_val)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
365 return CONFIG_BAD;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
366 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
367 if (hold_bool_val != new_bool_val) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
368 memcpy(val_ptr, &new_bool_val, sizeof(bool));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
369 return CONFIG_CHANGED;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
370 } else {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
371 return CONFIG_OK;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
372 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
373 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
374 case CONFIG_INT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
375 memcpy(&hold_int_val, val_ptr, sizeof(unsigned long));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
376 if (!parse_num(line, &new_int_val, 0, 0)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
377 return CONFIG_BAD;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
378 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
379 if (hold_int_val != new_int_val) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
380 memcpy(val_ptr, &new_int_val, sizeof(unsigned long));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
381 return CONFIG_CHANGED;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
382 } else {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
383 return CONFIG_OK;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
384 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
385 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
386 #ifdef CYGPKG_REDBOOT_NETWORKING
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
387 case CONFIG_IP:
2843
e6d5126cb479 Work around GCC 4.3 problem - simplify memcpy() call - reported by Jose Vasconcellos
gthomas
parents: 2729
diff changeset
388 memcpy(&hold_ip_val, val_ptr, sizeof(in_addr_t));
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
389 if (!_gethostbyname(line, &new_ip_val)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
390 return CONFIG_BAD;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
391 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
392 if (hold_ip_val.s_addr != new_ip_val.s_addr) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
393 memcpy(val_ptr, &new_ip_val, sizeof(in_addr_t));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
394 return CONFIG_CHANGED;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
395 } else {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
396 return CONFIG_OK;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
397 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
398 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
399 case CONFIG_ESA:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
400 memcpy(&hold_esa_val, val_ptr, sizeof(enet_addr_t));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
401 esp = line;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
402 for (esa_ptr = 0; esa_ptr < sizeof(enet_addr_t); esa_ptr++) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
403 unsigned long esa_byte;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
404 if (!parse_num(esp, &esa_byte, &esp, ":")) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
405 memcpy(val_ptr, &hold_esa_val, sizeof(enet_addr_t));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
406 return CONFIG_BAD;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
407 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
408 ((unsigned char *)val_ptr)[esa_ptr] = esa_byte;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
409 }
1265
734edfe6c859 Allow platform to provide routine to validate ethernet addresses
gthomas
parents: 1259
diff changeset
410 #ifdef CYGSEM_REDBOOT_PLF_ESA_VALIDATE
734edfe6c859 Allow platform to provide routine to validate ethernet addresses
gthomas
parents: 1259
diff changeset
411 if (!cyg_plf_redboot_esa_validate(val_ptr)) {
734edfe6c859 Allow platform to provide routine to validate ethernet addresses
gthomas
parents: 1259
diff changeset
412 memcpy(val_ptr, &hold_esa_val, sizeof(enet_addr_t));
734edfe6c859 Allow platform to provide routine to validate ethernet addresses
gthomas
parents: 1259
diff changeset
413 return CONFIG_BAD;
734edfe6c859 Allow platform to provide routine to validate ethernet addresses
gthomas
parents: 1259
diff changeset
414 }
734edfe6c859 Allow platform to provide routine to validate ethernet addresses
gthomas
parents: 1259
diff changeset
415 #endif
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
416 return CONFIG_CHANGED;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
417 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
418 #if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
419 case CONFIG_NETPORT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
420 if (strlen(line) >= MAX_STRING_LENGTH || net_devindex(line) < 0) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
421 int index;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
422 const char *name;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
423 diag_printf("Sorry, Port name must be one of:\n");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
424 for (index = 0; (name = net_devname(index)) != NULL; index++)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
425 diag_printf(" %s\n", name);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
426 return CONFIG_BAD;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
427 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
428 strcpy((unsigned char *)val_ptr, line);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
429 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
430 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
431 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
432 case CONFIG_SCRIPT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
433 // Assume it always changes
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
434 sp = (char *)val_ptr;
2010
2379473fdc8d * src/fconfig.c: (get_config): Verify the length of the script is
asl
parents: 1822
diff changeset
435 script_len = 0;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
436 diag_printf("Enter script, terminate with empty line\n");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
437 while (true) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
438 *sp = '\0';
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
439 diag_printf(">> ");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
440 ret = _rb_gets(line, sizeof(line), 0);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
441 if (ret < 0) return CONFIG_ABORT;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
442 if (strlen(line) == 0) break;
2010
2379473fdc8d * src/fconfig.c: (get_config): Verify the length of the script is
asl
parents: 1822
diff changeset
443 script_len += strlen(line) + 1;
2379473fdc8d * src/fconfig.c: (get_config): Verify the length of the script is
asl
parents: 1822
diff changeset
444 if (script_len > config_length(CONFIG_SCRIPT)) {
2379473fdc8d * src/fconfig.c: (get_config): Verify the length of the script is
asl
parents: 1822
diff changeset
445 diag_printf("script longer than %d not allowed!\n",
2379473fdc8d * src/fconfig.c: (get_config): Verify the length of the script is
asl
parents: 1822
diff changeset
446 config_length(CONFIG_SCRIPT));
2379473fdc8d * src/fconfig.c: (get_config): Verify the length of the script is
asl
parents: 1822
diff changeset
447 return CONFIG_ABORT;
2379473fdc8d * src/fconfig.c: (get_config): Verify the length of the script is
asl
parents: 1822
diff changeset
448 }
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
449 lp = line;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
450 while (*lp) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
451 *sp++ = *lp++;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
452 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
453 *sp++ = '\n';
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
454 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
455 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
456 case CONFIG_STRING:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
457 if (strlen(line) >= MAX_STRING_LENGTH) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
458 diag_printf("Sorry, value is too long\n");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
459 return CONFIG_BAD;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
460 }
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
461 strcpy((char *)val_ptr, line);
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
462 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
463 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
464 return CONFIG_CHANGED;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
465 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
466
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
467 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
468 // Manage configuration information with the FLASH
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
469 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
470
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
471 static int
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
472 config_length(int type)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
473 {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
474 switch (type) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
475 case CONFIG_BOOL:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
476 return sizeof(bool);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
477 case CONFIG_INT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
478 return sizeof(unsigned long);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
479 #ifdef CYGPKG_REDBOOT_NETWORKING
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
480 case CONFIG_IP:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
481 return sizeof(in_addr_t);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
482 case CONFIG_ESA:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
483 // Would like this to be sizeof(enet_addr_t), but that causes much
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
484 // pain since it fouls the alignment of data which follows.
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
485 return 8;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
486 #if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
487 case CONFIG_NETPORT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
488 return MAX_STRING_LENGTH;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
489 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
490 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
491 case CONFIG_STRING:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
492 return MAX_STRING_LENGTH;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
493 case CONFIG_SCRIPT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
494 return MAX_SCRIPT_LENGTH;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
495 default:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
496 return 0;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
497 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
498 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
499
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
500 static cmd_fun do_flash_config;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
501 RedBoot_cmd("fconfig",
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
502 "Manage configuration kept in FLASH memory",
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
503 "[-i] [-l] [-n] [-f] [-d] | [-d] nickname [value]",
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
504 do_flash_config
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
505 );
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
506
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
507 static void
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
508 do_flash_config(int argc, char *argv[])
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
509 {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
510 bool need_update = false;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
511 struct config_option *optend = __CONFIG_options_TAB_END__;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
512 struct config_option *opt = __CONFIG_options_TAB__;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
513 struct option_info opts[5];
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
514 bool list_only;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
515 bool nicknames;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
516 bool fullnames;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
517 bool dumbterminal;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
518 int list_opt = 0;
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
519 char *dp;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
520 int len, ret;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
521 char *title;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
522 char *onlyone = NULL;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
523 char *onevalue = NULL;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
524 bool doneone = false;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
525 bool init = false;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
526
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
527 #ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
528 if (!__flash_init) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
529 diag_printf("Sorry, no FLASH memory is available\n");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
530 return;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
531 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
532 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
533 memcpy(backup_config, config, sizeof(struct _config));
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
534 script = NULL;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
535
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
536 init_opts(&opts[0], 'l', false, OPTION_ARG_TYPE_FLG,
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
537 (void *)&list_only, (bool *)0, "list configuration only");
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
538 init_opts(&opts[1], 'n', false, OPTION_ARG_TYPE_FLG,
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
539 (void *)&nicknames, (bool *)0, "show nicknames");
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
540 init_opts(&opts[2], 'f', false, OPTION_ARG_TYPE_FLG,
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
541 (void *)&fullnames, (bool *)0, "show full names");
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
542 init_opts(&opts[3], 'i', false, OPTION_ARG_TYPE_FLG,
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
543 (void *)&init, (bool *)0, "initialize configuration database");
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
544 init_opts(&opts[4], 'd', false, OPTION_ARG_TYPE_FLG,
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
545 (void *)&dumbterminal, (bool *)0, "dumb terminal: no clever edits");
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
546
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
547 // First look to see if we are setting or getting a single option
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
548 // by just quoting its nickname
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
549 if ( (2 == argc && '-' != argv[1][0]) ||
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
550 (3 == argc && '-' != argv[1][0] && '-' != argv[2][0])) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
551 // then the command was "fconfig foo [value]"
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
552 onlyone = argv[1];
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
553 onevalue = (3 == argc) ? argv[2] : NULL;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
554 list_opt = LIST_OPT_NICKNAMES;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
555 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
556 // Next see if we are setting or getting a single option with a dumb
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
557 // terminal invoked, ie. no line editing.
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
558 else if (3 == argc &&
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
559 '-' == argv[1][0] && 'd' == argv[1][1] && 0 == argv[1][2] &&
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
560 '-' != argv[2][0]) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
561 // then the command was "fconfig -d foo"
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
562 onlyone = argv[2];
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
563 onevalue = NULL;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
564 list_opt = LIST_OPT_NICKNAMES | LIST_OPT_DUMBTERM;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
565 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
566 else {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
567 if (!scan_opts(argc, argv, 1, opts, 5, 0, 0, ""))
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
568 return;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
569 list_opt |= list_only ? LIST_OPT_LIST_ONLY : 0;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
570 list_opt |= nicknames ? LIST_OPT_NICKNAMES : LIST_OPT_FULLNAMES;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
571 list_opt |= fullnames ? LIST_OPT_FULLNAMES : 0;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
572 list_opt |= dumbterminal ? LIST_OPT_DUMBTERM : 0;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
573 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
574
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
575 if (init && verify_action("Initialize non-volatile configuration")) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
576 config_init();
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
577 need_update = true;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
578 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
579
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
580 dp = &config->config_data[0];
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
581 while (dp < &config->config_data[sizeof(config->config_data)]) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
582 if (CONFIG_OBJECT_TYPE(dp) == CONFIG_EMPTY) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
583 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
584 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
585 len = 4 + CONFIG_OBJECT_KEYLEN(dp) + CONFIG_OBJECT_ENABLE_KEYLEN(dp) +
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
586 config_length(CONFIG_OBJECT_TYPE(dp));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
587 // Provide a title for well known [i.e. builtin] objects
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
588 title = (char *)NULL;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
589 opt = __CONFIG_options_TAB__;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
590 while (opt != optend) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
591 if (strcmp(opt->key, CONFIG_OBJECT_KEY(dp)) == 0) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
592 title = opt->title;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
593 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
594 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
595 opt++;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
596 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
597 if ( onlyone && 0 != strcmp(CONFIG_OBJECT_KEY(dp), onlyone) )
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
598 ret = CONFIG_OK; // skip this entry
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
599 else {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
600 doneone = true;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
601 ret = get_config(dp, title, list_opt, onevalue); // do this opt
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
602 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
603 switch (ret) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
604 case CONFIG_DONE:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
605 goto done;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
606 case CONFIG_ABORT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
607 memcpy(config, backup_config, sizeof(struct _config));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
608 return;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
609 case CONFIG_CHANGED:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
610 need_update = true;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
611 case CONFIG_OK:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
612 dp += len;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
613 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
614 case CONFIG_BACK:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
615 dp = &config->config_data[0];
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
616 continue;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
617 case CONFIG_BAD:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
618 // Nothing - make him do it again
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
619 diag_printf ("** invalid entry\n");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
620 onevalue = NULL; // request a good value be typed in - or abort/whatever
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
621 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
622 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
623
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
624 done:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
625 if (NULL != onlyone && !doneone) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
626 #ifdef CYGSEM_REDBOOT_ALLOW_DYNAMIC_FLASH_CONFIG_DATA
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
627 if (verify_action("** entry '%s' not found - add", onlyone)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
628 struct config_option opt;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
629 diag_printf("Trying to add value\n");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
630 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
631 #else
1259
13ba50dd5a8e Some cleanups from David Vrable
gthomas
parents: 1248
diff changeset
632 diag_printf("** entry '%s' not found\n", onlyone);
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
633 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
634 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
635 if (!need_update)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
636 return;
1451
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
637 flash_write_config(true);
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
638 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
639
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
640
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
641 #ifdef CYGSEM_REDBOOT_FLASH_ALIASES
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
642 static cmd_fun do_alias;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
643 RedBoot_cmd("alias",
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
644 "Manage aliases kept in FLASH memory",
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
645 "name [value]",
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
646 do_alias
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
647 );
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
648
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
649 static void
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
650 make_alias(char *alias, char *name)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
651 {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
652 diag_sprintf(alias, "alias/%s", name);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
653 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
654
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
655 static void
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
656 do_alias(int argc, char *argv[])
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
657 {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
658 char name[80];
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
659 char *val;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
660 struct config_option opt;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
661
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
662 switch (argc) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
663 case 2:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
664 make_alias(name, argv[1]);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
665 if (flash_get_config(name, &val, CONFIG_STRING)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
666 diag_printf("'%s' = '%s'\n", argv[1], val);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
667 } else {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
668 diag_printf("'%s' not found\n", argv[1]);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
669 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
670 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
671 case 3:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
672 if (strlen(argv[2]) >= MAX_STRING_LENGTH) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
673 diag_printf("Sorry, value is too long\n");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
674 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
675 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
676 make_alias(name, argv[1]);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
677 opt.type = CONFIG_STRING;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
678 opt.enable = (char *)0;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
679 opt.enable_sense = 1;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
680 opt.key = name;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
681 opt.dflt = (CYG_ADDRESS)argv[2];
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
682 flash_add_config(&opt, true);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
683 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
684 default:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
685 diag_printf("usage: alias name [value]\n");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
686 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
687 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
688
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
689 // Lookup an alias. First try plain string aliases. If that fails try
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
690 // other types so allowing access to all configured values. This allows
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
691 // for alias (macro) expansion of normal 'fconfig' data, such as the
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
692 // board IP address.
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
693 char *
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
694 flash_lookup_alias(char *alias, char *alias_buf)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
695 {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
696 char name[80];
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
697 char *val;
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
698 char * dp;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
699 void *val_ptr;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
700 int type;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
701 bool hold_bool_val;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
702 long hold_long_val;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
703 #ifdef CYGPKG_REDBOOT_NETWORKING
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
704 int esa_ptr;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
705 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
706
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
707 make_alias(name, alias);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
708 if (flash_get_config(name, &val, CONFIG_STRING)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
709 return val;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
710 } else {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
711 dp = flash_lookup_config(alias);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
712 if (dp) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
713 val_ptr = (void *)CONFIG_OBJECT_VALUE(dp);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
714 switch (type = CONFIG_OBJECT_TYPE(dp)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
715 case CONFIG_BOOL:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
716 memcpy(&hold_bool_val, val_ptr, sizeof(bool));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
717 diag_sprintf(alias_buf, "%s", hold_bool_val ? "true" : "false");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
718 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
719 case CONFIG_INT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
720 memcpy(&hold_long_val, val_ptr, sizeof(unsigned long));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
721 diag_sprintf(alias_buf,"%ld", hold_long_val);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
722 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
723 #ifdef CYGPKG_REDBOOT_NETWORKING
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
724 case CONFIG_IP:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
725 diag_sprintf(alias_buf,"%s", inet_ntoa((in_addr_t *)val_ptr));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
726 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
727 case CONFIG_ESA:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
728 for (esa_ptr = 0; esa_ptr < sizeof(enet_addr_t); esa_ptr++) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
729 diag_sprintf(alias_buf+(3*esa_ptr), "0x%02X", ((unsigned char *)val_ptr)[esa_ptr]);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
730 if (esa_ptr < (sizeof(enet_addr_t)-1)) diag_printf(":");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
731 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
732 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
733 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
734 case CONFIG_SCRIPT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
735 return (char *) val_ptr;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
736 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
737 default:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
738 return (char *)NULL;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
739 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
740 return alias_buf;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
741 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
742 return (char *)NULL;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
743 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
744 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
745
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
746 #endif // CYGSEM_REDBOOT_FLASH_ALIASES
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
747
1740
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
748 cyg_uint32
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
749 flash_crc(struct _config *conf)
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
750 {
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
751 cyg_uint32 crc;
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
752 #ifdef REDBOOT_FLASH_REVERSE_BYTEORDER
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
753 int swabbed = 0;
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
754
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
755 if (conf->key1 == CONFIG_KEY1 && conf->key2 == CONFIG_KEY2) {
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
756 swabbed = 1;
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
757 conf_endian_fixup(conf);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
758 }
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
759 #endif
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
760
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
761 crc = cyg_crc32((unsigned char *)conf, sizeof(*conf)-sizeof(conf->cksum));
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
762
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
763 #ifdef REDBOOT_FLASH_REVERSE_BYTEORDER
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
764 if (swabbed)
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
765 conf_endian_fixup(conf);
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
766 #endif
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
767 return crc;
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
768 }
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
769
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
770 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
771 // Write the in-memory copy of the configuration data to the flash device.
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
772 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
773 void
1451
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
774 flash_write_config(bool prompt)
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
775 {
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
776 #if defined(CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH)
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
777 #if !defined(CYGSEM_REDBOOT_FLASH_COMBINED_FIS_AND_CONFIG)
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
778 cyg_flashaddr_t err_addr;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
779 int stat;
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
780 #endif
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
781 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
782
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
783 config->len = sizeof(struct _config);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
784 config->key1 = CONFIG_KEY1;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
785 config->key2 = CONFIG_KEY2;
1740
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
786 config->cksum = flash_crc(config);
1451
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
787 if (!prompt || verify_action("Update RedBoot non-volatile configuration")) {
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
788 #ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
789 #ifdef CYGSEM_REDBOOT_FLASH_COMBINED_FIS_AND_CONFIG
1740
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
790 fis_read_directory();
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
791 fis_update_directory();
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
792 #else
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
793 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
794 // Insure [quietly] that the config page is unlocked before trying to update
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
795 cyg_flash_unlock(cfg_base, cfg_size, &err_addr);
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
796 #endif
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
797 if ((stat = cyg_flash_erase(cfg_base, cfg_size, &err_addr)) != 0) {
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
798 diag_printf(" initialization failed at %p: %s\n", (void*)err_addr,
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
799 cyg_flash_errmsg(stat));
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
800 } else {
1740
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
801 conf_endian_fixup(config);
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
802 if ((stat = cyg_flash_program(cfg_base, (void *)config, sizeof(struct _config),
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
803 &err_addr)) != 0) {
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
804 diag_printf("Error writing config data at %p: %s\n",
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
805 (void*)err_addr, cyg_flash_errmsg(stat));
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
806 }
1740
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
807 conf_endian_fixup(config);
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
808 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
809 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
810 // Insure [quietly] that the config data is locked after the update
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
811 cyg_flash_lock(cfg_base, cfg_size, &err_addr);
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
812 #endif
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
813 #endif // CYGSEM_REDBOOT_FLASH_COMBINED_FIS_AND_CONFIG
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
814 #else // CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
815 write_eeprom(config, sizeof(struct _config)); // into 'config'
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
816 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
817 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
818 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
819
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
820 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
821 // Find the configuration entry for a particular key
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
822 //
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
823 static char *
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
824 flash_lookup_config(char *key)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
825 {
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
826 char *dp;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
827 int len;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
828
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
829 if (!config_ok) return NULL;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
830
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
831 dp = &config->config_data[0];
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
832 while (dp < &config->config_data[sizeof(config->config_data)]) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
833 len = 4 + CONFIG_OBJECT_KEYLEN(dp) + CONFIG_OBJECT_ENABLE_KEYLEN(dp) +
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
834 config_length(CONFIG_OBJECT_TYPE(dp));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
835 if (strcmp(key, CONFIG_OBJECT_KEY(dp)) == 0) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
836 return dp;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
837 }
2644
80c8675af39a Stop RedBoot going into an infinite loop when there is something dodgy
bartv
parents: 2631
diff changeset
838 // Sanity check to prevent RedBoot going into an infinite loop when
80c8675af39a Stop RedBoot going into an infinite loop when there is something dodgy
bartv
parents: 2631
diff changeset
839 // there is something dodgy in the fconfig area.
80c8675af39a Stop RedBoot going into an infinite loop when there is something dodgy
bartv
parents: 2631
diff changeset
840 if (len <= 0) {
80c8675af39a Stop RedBoot going into an infinite loop when there is something dodgy
bartv
parents: 2631
diff changeset
841 break;
80c8675af39a Stop RedBoot going into an infinite loop when there is something dodgy
bartv
parents: 2631
diff changeset
842 }
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
843 dp += len;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
844 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
845 // diag_printf("Can't find config data for '%s'\n", key);
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
846 return NULL;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
847 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
848
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
849 //
1451
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
850 // Enumerate the keys from the configuration
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
851 //
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
852 bool
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
853 flash_next_key(char *key, int keylen, int *type, int *offset)
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
854 {
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
855 char *dp;
1451
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
856 int len;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
857
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
858 if (!config_ok) return false;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
859 if ((*offset < 0) || (*offset >= MAX_CONFIG_DATA)) return false;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
860
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
861 dp = &config->config_data[*offset];
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
862 if ((*type = CONFIG_OBJECT_TYPE(dp)) == CONFIG_EMPTY) return false;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
863 if ((len = CONFIG_OBJECT_KEYLEN(dp)) > keylen) return false;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
864 memcpy(key, CONFIG_OBJECT_KEY(dp), len);
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
865 *offset += 4 + CONFIG_OBJECT_KEYLEN(dp) + CONFIG_OBJECT_ENABLE_KEYLEN(dp) +
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
866 config_length(CONFIG_OBJECT_TYPE(dp));
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
867 return true;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
868 }
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
869
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
870 //
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
871 // Retrieve a data object from the data base (in memory copy)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
872 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
873 bool
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
874 flash_get_config(char *key, void *val, int type)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
875 {
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
876 char *dp;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
877 void *val_ptr;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
878 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
879 struct _config *save_config = 0;
1451
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
880 bool res;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
881 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
882
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
883 if (!config_ok) return false;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
884
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
885 if ((dp = flash_lookup_config(key)) != NULL) {
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
886 if (CONFIG_OBJECT_TYPE(dp) == type) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
887 val_ptr = (void *)CONFIG_OBJECT_VALUE(dp);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
888 switch (type) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
889 // Note: the data may be unaligned in the configuration data
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
890 case CONFIG_BOOL:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
891 memcpy(val, val_ptr, sizeof(bool));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
892 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
893 case CONFIG_INT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
894 memcpy(val, val_ptr, sizeof(unsigned long));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
895 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
896 #ifdef CYGPKG_REDBOOT_NETWORKING
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
897 case CONFIG_IP:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
898 memcpy(val, val_ptr, sizeof(in_addr_t));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
899 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
900 case CONFIG_ESA:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
901 memcpy(val, val_ptr, sizeof(enet_addr_t));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
902 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
903 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
904 #if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
905 case CONFIG_NETPORT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
906 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
907 case CONFIG_STRING:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
908 case CONFIG_SCRIPT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
909 // Just return a pointer to the script/line
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
910 *(unsigned char **)val = (unsigned char *)val_ptr;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
911 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
912 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
913 } else {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
914 diag_printf("Request for config value '%s' - wrong type\n", key);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
915 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
916 return true;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
917 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
918 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
919 // Did not find key. Is configuration data valid?
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
920 // Check to see if the config data is valid, if not, revert to
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
921 // readonly mode, by setting config to readonly_config. We
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
922 // will set it back before we leave this function.
1740
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
923 if ( (config != readonly_config) && ((flash_crc(config) != config->cksum) ||
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
924 (config->key1 != CONFIG_KEY1)|| (config->key2 != CONFIG_KEY2))) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
925 save_config = config;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
926 config = readonly_config;
1740
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
927 if ((flash_crc(config) != config->cksum) ||
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
928 (config->key1 != CONFIG_KEY1)|| (config->key2 != CONFIG_KEY2)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
929 diag_printf("FLASH configuration checksum error or invalid key\n");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
930 config = save_config;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
931 return false;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
932 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
933 else{
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
934 diag_printf("Getting config information in READONLY mode\n");
1451
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
935 res = flash_get_config(key, val, type);
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
936 config = save_config;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
937 return res;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
938 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
939 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
940 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
941 return false;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
942 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
943
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
944 //
1451
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
945 // Update a data object in the data base (in memory copy & backing store)
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
946 //
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
947 bool
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
948 flash_set_config(char *key, void *val, int type)
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
949 {
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
950 char *dp;
1451
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
951 void *val_ptr;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
952
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
953 if (!config_ok) return false;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
954
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
955 if ((dp = flash_lookup_config(key)) != NULL) {
1451
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
956 if (CONFIG_OBJECT_TYPE(dp) == type) {
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
957 val_ptr = (void *)CONFIG_OBJECT_VALUE(dp);
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
958 switch (type) {
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
959 // Note: the data may be unaligned in the configuration data
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
960 case CONFIG_BOOL:
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
961 memcpy(val_ptr, val, sizeof(bool));
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
962 break;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
963 case CONFIG_INT:
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
964 memcpy(val_ptr, val, sizeof(unsigned long));
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
965 break;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
966 #ifdef CYGPKG_REDBOOT_NETWORKING
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
967 case CONFIG_IP:
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
968 memcpy(val_ptr, val, sizeof(in_addr_t));
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
969 break;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
970 case CONFIG_ESA:
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
971 memcpy(val_ptr, val, sizeof(enet_addr_t));
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
972 break;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
973 #endif
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
974 #if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
975 case CONFIG_NETPORT:
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
976 #endif
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
977 case CONFIG_STRING:
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
978 case CONFIG_SCRIPT:
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
979 memcpy(val_ptr, val, config_length(CONFIG_STRING));
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
980 break;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
981 }
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
982 } else {
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
983 diag_printf("Can't set config value '%s' - wrong type\n", key);
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
984 return false;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
985 }
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
986 flash_write_config(false);
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
987 return true;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
988 }
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
989 return false;
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
990 }
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
991
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
992 //
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
993 // Copy data into the config area
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
994 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
995 static void
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
996 flash_config_insert_value(char *dp, struct config_option *opt)
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
997 {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
998 switch (opt->type) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
999 // Note: the data may be unaligned in the configuration data
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1000 case CONFIG_BOOL:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1001 memcpy(dp, (void *)&opt->dflt, sizeof(bool));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1002 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1003 case CONFIG_INT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1004 memcpy(dp, (void *)&opt->dflt, sizeof(unsigned long));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1005 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1006 #ifdef CYGPKG_REDBOOT_NETWORKING
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1007 case CONFIG_IP:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1008 memcpy(dp, (void *)&opt->dflt, sizeof(in_addr_t));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1009 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1010 case CONFIG_ESA:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1011 memcpy(dp, (void *)opt->dflt, sizeof(enet_addr_t));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1012 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1013 #if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1014 case CONFIG_NETPORT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1015 // validate dflt and if not acceptable use first port
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1016 {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1017 int index;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1018 const char *name;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1019 for (index = 0; (name = net_devname(index)) != NULL; index++)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1020 if (!strcmp((char *)opt->dflt, name))
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1021 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1022 if (name == NULL)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1023 name = net_devname(0);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1024 memcpy(dp, name, strlen(name) + 1);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1025 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1026 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1027 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1028 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1029 case CONFIG_STRING:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1030 memcpy(dp, (void *)opt->dflt, config_length(CONFIG_STRING));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1031 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1032 case CONFIG_SCRIPT:
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1033 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1034 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1035 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1036
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1037 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1038 // Add a new option to the database
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1039 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1040 bool
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1041 flash_add_config(struct config_option *opt, bool update)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1042 {
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
1043 char *dp, *kp;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1044 int len, elen, size;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1045
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1046 // If data item is already present, just update it
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1047 // Note: only the data value can be thusly changed
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
1048 if ((dp = flash_lookup_config(opt->key)) != NULL) {
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1049 flash_config_insert_value(CONFIG_OBJECT_VALUE(dp), opt);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1050 if (update) {
1451
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
1051 flash_write_config(true);
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1052 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1053 return true;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1054 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1055 // Add the data item
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1056 dp = &config->config_data[0];
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1057 size = 0;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1058 while (size < sizeof(config->config_data)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1059 if (CONFIG_OBJECT_TYPE(dp) == CONFIG_EMPTY) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1060 kp = opt->key;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1061 len = strlen(kp) + 1;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1062 size += len + 2 + 2 + config_length(opt->type);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1063 if (opt->enable) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1064 elen = strlen(opt->enable) + 1;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1065 size += elen;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1066 } else {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1067 elen = 0;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1068 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1069 if (size > sizeof(config->config_data)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1070 break;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1071 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1072 CONFIG_OBJECT_TYPE(dp) = opt->type;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1073 CONFIG_OBJECT_KEYLEN(dp) = len;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1074 CONFIG_OBJECT_ENABLE_SENSE(dp) = opt->enable_sense;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1075 CONFIG_OBJECT_ENABLE_KEYLEN(dp) = elen;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1076 dp = CONFIG_OBJECT_KEY(dp);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1077 while (*kp) *dp++ += *kp++;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1078 *dp++ = '\0';
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1079 if (elen) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1080 kp = opt->enable;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1081 while (*kp) *dp++ += *kp++;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1082 *dp++ = '\0';
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1083 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1084 flash_config_insert_value(dp, opt);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1085 if (update) {
1451
077fd39935a2 Expand fconfig access via virtual vectors. Work around a TCP timing issue.
gthomas
parents: 1401
diff changeset
1086 flash_write_config(true);
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1087 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1088 return true;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1089 } else {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1090 len = 4 + CONFIG_OBJECT_KEYLEN(dp) + CONFIG_OBJECT_ENABLE_KEYLEN(dp) +
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1091 config_length(CONFIG_OBJECT_TYPE(dp));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1092 dp += len;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1093 size += len;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1094 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1095 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1096 diag_printf("No space to add '%s'\n", opt->key);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1097 return false;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1098 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1099
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1100 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1101 // Reset/initialize configuration data - used only when starting from scratch
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1102 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1103 static void
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1104 config_init(void)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1105 {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1106 // Well known option strings
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1107 struct config_option *optend = __CONFIG_options_TAB_END__;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1108 struct config_option *opt = __CONFIG_options_TAB__;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1109
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1110 memset(config, 0, sizeof(struct _config));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1111 while (opt != optend) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1112 if (!flash_add_config(opt, false)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1113 return;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1114 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1115 opt++;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1116 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1117 config_ok = true;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1118 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1119
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1120 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1121 // Attempt to get configuration information from the FLASH.
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1122 // If available (i.e. good checksum, etc), initialize "known"
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1123 // values for later use.
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1124 //
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1125 static void
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1126 load_flash_config(void)
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1127 {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1128 bool use_boot_script;
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
1129 unsigned char *cfg_temp = (unsigned char *)workspace_end;
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
1130 #ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
1131 cyg_flashaddr_t err_addr;
1513
c4355f101bf6 Cleanups to remove warnings
gthomas
parents: 1451
diff changeset
1132 #endif
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1133
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1134 config_ok = false;
2614
6cbecf3cc2e4 * src/fconfig.c, src/flash.c, src/io.c, src/load.c, src/main.c,
jlarmour
parents: 2195
diff changeset
1135 script = NULL;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1136 cfg_temp -= sizeof(struct _config); // Space for primary config data
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1137 config = (struct _config *)cfg_temp;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1138 cfg_temp -= sizeof(struct _config); // Space for backup config data
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1139 backup_config = (struct _config *)cfg_temp;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1140 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1141 cfg_temp -= sizeof(struct _config); // Space for readonly copy of config data
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1142 readonly_config = (struct _config *)cfg_temp;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1143 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1144 workspace_end = cfg_temp;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1145 #ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
2195
5c5e93c863ac Redundant FIS table support - from Alexander Neundorf
gthomas
parents: 2010
diff changeset
1146 if (do_flash_init()<0) return;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1147 #ifdef CYGSEM_REDBOOT_FLASH_COMBINED_FIS_AND_CONFIG
1312
08edfb52f9cd Improve FIS directory handling - should work with small block size devices
gthomas
parents: 1265
diff changeset
1148 cfg_size = _rup(sizeof(struct _config), sizeof(struct fis_image_desc));
08edfb52f9cd Improve FIS directory handling - should work with small block size devices
gthomas
parents: 1265
diff changeset
1149 if ((fisdir_size-cfg_size) < (CYGNUM_REDBOOT_FIS_DIRECTORY_ENTRY_COUNT *
08edfb52f9cd Improve FIS directory handling - should work with small block size devices
gthomas
parents: 1265
diff changeset
1150 CYGNUM_REDBOOT_FIS_DIRECTORY_ENTRY_SIZE)) {
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1151 // Too bad this can't be checked at compile/build time
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1152 diag_printf("Sorry, FLASH config exceeds available space in FIS directory\n");
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1153 return;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1154 }
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
1155 cfg_base = (((CYG_ADDRESS)fis_addr + fisdir_size) - cfg_size);
1312
08edfb52f9cd Improve FIS directory handling - should work with small block size devices
gthomas
parents: 1265
diff changeset
1156 fisdir_size -= cfg_size;
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1157 #else
1312
08edfb52f9cd Improve FIS directory handling - should work with small block size devices
gthomas
parents: 1265
diff changeset
1158 cfg_size = (flash_block_size > sizeof(struct _config)) ?
08edfb52f9cd Improve FIS directory handling - should work with small block size devices
gthomas
parents: 1265
diff changeset
1159 sizeof(struct _config) :
08edfb52f9cd Improve FIS directory handling - should work with small block size devices
gthomas
parents: 1265
diff changeset
1160 _rup(sizeof(struct _config), flash_block_size);
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1161 if (CYGNUM_REDBOOT_FLASH_CONFIG_BLOCK < 0) {
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
1162 cfg_base = ((CYG_ADDRESS)flash_end + 1 -
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1163 _rup(_rup((-CYGNUM_REDBOOT_FLASH_CONFIG_BLOCK*flash_block_size), cfg_size), flash_block_size));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1164 } else {
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
1165 cfg_base = ((CYG_ADDRESS)flash_start +
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1166 _rup(_rup((CYGNUM_REDBOOT_FLASH_CONFIG_BLOCK*flash_block_size), cfg_size), flash_block_size));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1167 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1168 #endif
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
1169 cyg_flash_read(cfg_base, (void *)config, sizeof(struct _config), &err_addr);
1740
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
1170 conf_endian_fixup(config);
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1171 #else
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1172 read_eeprom(config, sizeof(struct _config)); // into 'config'
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1173 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1174 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1175 memcpy(readonly_config, config, sizeof(struct _config));
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1176 #endif
1740
0031b615f51c Add support for reverse endianess of fis and config data
msalter
parents: 1513
diff changeset
1177 if ((flash_crc(config) != config->cksum) ||
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1178 (config->key1 != CONFIG_KEY1)|| (config->key2 != CONFIG_KEY2)) {
1312
08edfb52f9cd Improve FIS directory handling - should work with small block size devices
gthomas
parents: 1265
diff changeset
1179 diag_printf("**Warning** FLASH configuration checksum error or invalid key\n");
1401
08e1358c3718 * src/fconfig.c: Fix typo in output string.
jld
parents: 1312
diff changeset
1180 diag_printf("Use 'fconfig -i' to [re]initialize database\n");
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1181 config_init();
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1182 return;
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1183 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1184 config_ok = true;
2631
13376f3cfc60 Merge flashv2 branch to trunk, with eCosCentric additions
jlarmour
parents: 2614
diff changeset
1185
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1186 flash_get_config("boot_script", &use_boot_script, CONFIG_BOOL);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1187 if (use_boot_script) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1188 flash_get_config("boot_script_data", &script, CONFIG_SCRIPT);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1189 flash_get_config("boot_script_timeout", &script_timeout, CONFIG_INT);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1190 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1191 #ifdef CYGSEM_REDBOOT_VARIABLE_BAUD_RATE
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1192 if (flash_get_config("console_baud_rate", &console_baud_rate, CONFIG_INT)) {
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1193 extern int set_console_baud_rate(int);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1194 set_console_baud_rate(console_baud_rate);
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1195 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1196 #endif
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1197 }
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1198
1312
08edfb52f9cd Improve FIS directory handling - should work with small block size devices
gthomas
parents: 1265
diff changeset
1199 RedBoot_init(load_flash_config, RedBoot_INIT_SECOND);
1223
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1200
dbcfe4e0dbd2 New platform - TAMS MOAB - and generic changes to support it
gthomas
parents:
diff changeset
1201 // EOF fconfig.c