This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
RedBoot et al - improve fconfig access via virtual vectors
- From: Gary Thomas <gary at mlbassoc dot com>
- To: eCos patches <ecos-patches at ecos dot sourceware dot org>
- Date: 21 Dec 2003 06:18:59 -0700
- Subject: RedBoot et al - improve fconfig access via virtual vectors
- Organization: MLB Associates
--
Gary Thomas <gary@mlbassoc.com>
MLB Associates
Index: redboot/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.174
diff -u -5 -p -r1.174 ChangeLog
--- redboot/current/ChangeLog 12 Dec 2003 19:14:03 -0000 1.174
+++ redboot/current/ChangeLog 21 Dec 2003 13:16:38 -0000
@@ -1,5 +1,17 @@
+2003-12-21 Gary Thomas <gary@mlbassoc.com>
+
+ * src/net/tcp.c (tcp_send): Add [restore] delay into TCP write
+ path. Sadly, there seems to be some issue where some ACK packets
+ get lost unless this is present (at least on some hardware).
+ n.b. a small delay here is definitely preferable to the horrendous
+ delays imposed by TCP retries if this condition occurs.
+
+ * src/fconfig.c:
+ * include/flash_config.h: New functions for get/set/enumerate
+ config data which can be used via virtual vector interface.
+
2003-12-12 Jani Monoses <jani@iv.ro>
* src/net/tcp.c: Cancel retransmission timer when SYN is acked
otherwise an open active connection which doesn't send data
eventually resends the SYN resulting in reset from the peer.
Index: redboot/current/include/flash_config.h
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/include/flash_config.h,v
retrieving revision 1.10
diff -u -5 -p -r1.10 flash_config.h
--- redboot/current/include/flash_config.h 19 Sep 2003 17:11:33 -0000 1.10
+++ redboot/current/include/flash_config.h 21 Dec 2003 12:52:21 -0000
@@ -85,13 +85,17 @@ struct config_option {
struct config_option _config_option_##_n_ \
CYG_HAL_TABLE_QUALIFIED_ENTRY(RedBoot_config_options,_n_) = \
{#_n_,_t_,_e_,_ie_,_type_,(unsigned long)_dflt_};
// Cause the in-memory configuration data to be written to flash
-void flash_write_config(void);
+void flash_write_config(bool prompt);
// Fetch a data item from flash storage, returns 'false' if not found
bool flash_get_config(char *key, void *val, int type);
+// Update a data item from flash storage, returns 'false' if not found
+bool flash_set_config(char *key, void *val, int type);
+// Enumerate keys from configuration
+bool flash_next_key(char *key, int keylen, int *type, int *offset);
// Add a new data item to configuration data base. Returns 'false'
// if no space is available.
bool flash_add_config(struct config_option *opt, bool update);
// Internal structure used to hold config data
Index: redboot/current/src/fconfig.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/fconfig.c,v
retrieving revision 1.7
diff -u -5 -p -r1.7 fconfig.c
--- redboot/current/src/fconfig.c 25 Nov 2003 11:54:41 -0000 1.7
+++ redboot/current/src/fconfig.c 21 Dec 2003 13:08:34 -0000
@@ -564,11 +564,11 @@ do_flash_config(int argc, char *argv[])
diag_printf("** entry '%s' not found\n", onlyone);
#endif
}
if (!need_update)
return;
- flash_write_config();
+ flash_write_config(true);
}
#ifdef CYGSEM_REDBOOT_FLASH_ALIASES
static cmd_fun do_alias;
@@ -679,22 +679,22 @@ flash_lookup_alias(char *alias, char *al
//
// Write the in-memory copy of the configuration data to the flash device.
//
void
-flash_write_config(void)
+flash_write_config(bool prompt)
{
#if defined(CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH)
int stat;
void *err_addr;
#endif
config->len = sizeof(struct _config);
config->key1 = CONFIG_KEY1;
config->key2 = CONFIG_KEY2;
config->cksum = cyg_crc32((unsigned char *)config, sizeof(struct _config)-sizeof(config->cksum));
- if (verify_action("Update RedBoot non-volatile configuration")) {
+ if (!prompt || verify_action("Update RedBoot non-volatile configuration")) {
#ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
#ifdef CYGSEM_REDBOOT_FLASH_COMBINED_FIS_AND_CONFIG
memcpy(fis_work_block, fis_addr, fisdir_size);
fis_update_directory();
#else // CYGSEM_REDBOOT_FLASH_COMBINED_FIS_AND_CONFIG
@@ -745,19 +745,41 @@ flash_lookup_config(char *key)
// diag_printf("Can't find config data for '%s'\n", key);
return false;
}
//
+// Enumerate the keys from the configuration
+//
+bool
+flash_next_key(char *key, int keylen, int *type, int *offset)
+{
+ unsigned char *dp;
+ int len;
+
+ if (!config_ok) return false;
+ if ((*offset < 0) || (*offset >= MAX_CONFIG_DATA)) return false;
+
+ dp = &config->config_data[*offset];
+ if ((*type = CONFIG_OBJECT_TYPE(dp)) == CONFIG_EMPTY) return false;
+ if ((len = CONFIG_OBJECT_KEYLEN(dp)) > keylen) return false;
+ memcpy(key, CONFIG_OBJECT_KEY(dp), len);
+ *offset += 4 + CONFIG_OBJECT_KEYLEN(dp) + CONFIG_OBJECT_ENABLE_KEYLEN(dp) +
+ config_length(CONFIG_OBJECT_TYPE(dp));
+ return true;
+}
+
+//
// Retrieve a data object from the data base (in memory copy)
//
bool
flash_get_config(char *key, void *val, int type)
{
unsigned char *dp;
void *val_ptr;
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK
struct _config *save_config = 0;
+ bool res;
#endif
if (!config_ok) return false;
if ((dp = flash_lookup_config(key)) != (unsigned char *)NULL) {
@@ -810,18 +832,68 @@ flash_get_config(char *key, void *val, i
config = save_config;
return false;
}
else{
diag_printf("Getting config information in READONLY mode\n");
- return flash_get_config(key, val, type);
+ res = flash_get_config(key, val, type);
+ config = save_config;
+ return res;
}
}
#endif
return false;
}
//
+// Update a data object in the data base (in memory copy & backing store)
+//
+bool
+flash_set_config(char *key, void *val, int type)
+{
+ unsigned char *dp;
+ void *val_ptr;
+
+ if (!config_ok) return false;
+
+ if ((dp = flash_lookup_config(key)) != (unsigned char *)NULL) {
+ if (CONFIG_OBJECT_TYPE(dp) == type) {
+ val_ptr = (void *)CONFIG_OBJECT_VALUE(dp);
+ switch (type) {
+ // Note: the data may be unaligned in the configuration data
+ case CONFIG_BOOL:
+ memcpy(val_ptr, val, sizeof(bool));
+ break;
+ case CONFIG_INT:
+ memcpy(val_ptr, val, sizeof(unsigned long));
+ break;
+#ifdef CYGPKG_REDBOOT_NETWORKING
+ case CONFIG_IP:
+ memcpy(val_ptr, val, sizeof(in_addr_t));
+ break;
+ case CONFIG_ESA:
+ memcpy(val_ptr, val, sizeof(enet_addr_t));
+ break;
+#endif
+#if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
+ case CONFIG_NETPORT:
+#endif
+ case CONFIG_STRING:
+ case CONFIG_SCRIPT:
+ memcpy(val_ptr, val, config_length(CONFIG_STRING));
+ break;
+ }
+ } else {
+ diag_printf("Can't set config value '%s' - wrong type\n", key);
+ return false;
+ }
+ flash_write_config(false);
+ return true;
+ }
+ return false;
+}
+
+//
// Copy data into the config area
//
static void
flash_config_insert_value(unsigned char *dp, struct config_option *opt)
{
@@ -876,11 +948,11 @@ flash_add_config(struct config_option *o
// If data item is already present, just update it
// Note: only the data value can be thusly changed
if ((dp = flash_lookup_config(opt->key)) != (unsigned char *)NULL) {
flash_config_insert_value(CONFIG_OBJECT_VALUE(dp), opt);
if (update) {
- flash_write_config();
+ flash_write_config(true);
}
return true;
}
// Add the data item
dp = &config->config_data[0];
@@ -911,11 +983,11 @@ flash_add_config(struct config_option *o
while (*kp) *dp++ += *kp++;
*dp++ = '\0';
}
flash_config_insert_value(dp, opt);
if (update) {
- flash_write_config();
+ flash_write_config(true);
}
return true;
} else {
len = 4 + CONFIG_OBJECT_KEYLEN(dp) + CONFIG_OBJECT_ENABLE_KEYLEN(dp) +
config_length(CONFIG_OBJECT_TYPE(dp));
Index: redboot/current/src/net/tcp.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/net/tcp.c,v
retrieving revision 1.10
diff -u -5 -p -r1.10 tcp.c
--- redboot/current/src/net/tcp.c 12 Dec 2003 19:14:04 -0000 1.10
+++ redboot/current/src/net/tcp.c 21 Dec 2003 13:16:40 -0000
@@ -7,10 +7,11 @@
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+// Copyright (C) 2003 Gary Thomas
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
@@ -52,10 +53,11 @@
//
//==========================================================================
#include <net/net.h>
#include <cyg/infra/diag.h>
+#include <cyg/hal/hal_if.h>
#define MAX_TCP_SEGMENT (ETH_MAX_PKTLEN - (sizeof(eth_header_t) + sizeof(ip_header_t)))
#define MAX_TCP_DATA (MAX_TCP_SEGMENT - sizeof(tcp_header_t))
@@ -158,10 +160,14 @@ tcp_send(tcp_socket_t *s, int flags, int
/* compute tcp checksum */
cksum = __sum((word *)tcp, pkt->pkt_bytes, __pseudo_sum(ip));
tcp->checksum = htons(cksum);
__ip_send(pkt, IP_PROTO_TCP, &s->his_addr);
+
+ // HACK! If this delay is not present, then if the target system sends
+ // back data (not just an ACK), then somehow we miss it :-(
+ CYGACC_CALL_IF_DELAY_US(2*1000);
BSPLOG(bsp_log("tcp_send: state[%d] flags[%s] ack[%x] data[%d].\n",
s->state, flags_to_str(tcp->flags), s->ack, s->data_bytes));
if (s->state == _TIME_WAIT) {
Index: hal/common/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/hal/common/current/ChangeLog,v
retrieving revision 1.99
diff -u -5 -p -r1.99 ChangeLog
--- hal/common/current/ChangeLog 7 Sep 2003 11:48:56 -0000 1.99
+++ hal/common/current/ChangeLog 21 Dec 2003 13:12:12 -0000
@@ -1,5 +1,11 @@
+2003-12-21 Gary Thomas <gary@mlbassoc.com>
+
+ * src/hal_if.c (flash_config_op):
+ * include/hal_if.h: New expanded functions for RedBoot 'fconfig'
+ database.
+
2003-09-04 Patrick Doyle <wpd@dtccom.com>
* include/hal_if.h:
* src/hal_if.c (flash_fis_op): Added support for the rest of the
FIS operations.
Index: hal/common/current/include/hal_if.h
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/hal/common/current/include/hal_if.h,v
retrieving revision 1.21
diff -u -5 -p -r1.21 hal_if.h
--- hal/common/current/include/hal_if.h 7 Sep 2003 11:48:57 -0000 1.21
+++ hal/common/current/include/hal_if.h 21 Dec 2003 13:12:12 -0000
@@ -10,11 +10,11 @@
//=============================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
@@ -421,16 +421,25 @@ typedef int (__call_if_dbg_syscall_t) (e
union dbg_thread_syscall_parms *p );
typedef void (__call_if_reset_t)(void);
typedef int __call_if_console_interrupt_flag_t;
typedef void (__call_if_delay_us_t)(cyg_int32 usecs);
typedef void (__call_if_install_bpt_fn_t)(void *__epc);
-typedef cyg_bool (__call_if_flash_cfg_op_fn_t)(int __oper, char *__key,
- void *__val, int __type);
typedef char *__call_if_monitor_version_t;
typedef void (__call_if_monitor_return_t)(int status);
-typedef cyg_bool (__call_if_flash_fis_op_fn_t)(int __oper, char *__name,
- void *__val);
+typedef cyg_bool (__call_if_flash_fis_op_fn_t)(int __oper, char *__name, void *__val);
+//
+// This structure is used to pass parameters to/from the fconfig routines.
+// This allows a single virtual vector interface, with widely varying functionality
+//
+struct cyg_fconfig {
+ char *key; // Datum 'key'
+ int keylen; // Length of key
+ void *val; // Pointer to data
+ int type; // Type of datum
+ int offset; // Offset within data (used by _NEXT)
+};
+typedef cyg_bool (__call_if_flash_cfg_op_fn_t)(int __oper, struct cyg_fconfig *__data);
#ifndef CYGACC_CALL_IF_DEFINED
#define __data_VV(_n_,_tt_) \
static __inline__ _tt_ \
@@ -635,16 +644,21 @@ __call_voidVV1(CYGNUM_CALL_IF_DELAY_US,
CYGACC_CALL_VV1(__call_if_install_bpt_fn_t*, CYGNUM_CALL_IF_INSTALL_BPT_FN, (_e_))
__call_voidVV1(CYGNUM_CALL_IF_INSTALL_BPT_FN, __call_if_install_bpt_fn_t, void, void *)
#define CYGACC_CALL_IF_INSTALL_BPT_FN_SET(_x_) \
hal_virtual_vector_table[CYGNUM_CALL_IF_INSTALL_BPT_FN]=(CYG_ADDRWORD)(_x_)
-#define CYGACC_CALL_IF_FLASH_CFG_OP(_o_,_k_,_d_,_t_) \
- CYGACC_CALL_VV4(__call_if_flash_cfg_op_fn_t*, CYGNUM_CALL_IF_FLASH_CFG_OP, (_o_),(_k_),(_d_),(_t_))
-__call_VV4(CYGNUM_CALL_IF_FLASH_CFG_OP, __call_if_flash_cfg_op_fn_t, cyg_bool, int, char *, void *, int)
+//
+// Access persistent data store - kept in FLASH or EEPROM by RedBoot
+//
+#define CYGNUM_CALL_IF_FLASH_CFG_GET (0) // Get a particular fconfig key
+#define CYGNUM_CALL_IF_FLASH_CFG_NEXT (1) // Enumerate keys (get the next one)
+#define CYGNUM_CALL_IF_FLASH_CFG_SET (2) // Update particular fconfig key
+#define CYGACC_CALL_IF_FLASH_CFG_OP(_o_,_d_) \
+ CYGACC_CALL_VV2(__call_if_flash_cfg_op_fn_t*, CYGNUM_CALL_IF_FLASH_CFG_OP, (_o_),(_d_))
+__call_VV2(CYGNUM_CALL_IF_FLASH_CFG_OP, __call_if_flash_cfg_op_fn_t, cyg_bool, int, struct cyg_fconfig *)
#define CYGACC_CALL_IF_FLASH_CFG_OP_SET(_x_) \
hal_virtual_vector_table[CYGNUM_CALL_IF_FLASH_CFG_OP]=(CYG_ADDRWORD)(_x_)
-#define CYGNUM_CALL_IF_FLASH_CFG_GET (0)
#define CYGACC_CALL_IF_MONITOR_RETURN(_u_) \
CYGACC_CALL_VV1(__call_if_monitor_return_t*, CYGNUM_CALL_IF_MONITOR_RETURN, (_u_))
__call_voidVV1(CYGNUM_CALL_IF_MONITOR_RETURN, __call_if_monitor_return_t, void, int)
#define CYGACC_CALL_IF_MONITOR_RETURN_SET(_x_) \
@@ -664,17 +678,17 @@ __call_VV3(CYGNUM_CALL_IF_FLASH_FIS_OP,
#define CYGNUM_CALL_IF_FLASH_FIS_GET_FILE_CKSUM (6)
// These need to be kept uptodate with the (unadorned) masters
// in RedBoot's flash_config.h:
-#define CYGNUM_FLASH_CFG_OP_CONFIG_EMPTY 0
-#define CYGNUM_FLASH_CFG_OP_CONFIG_BOOL 1
-#define CYGNUM_FLASH_CFG_OP_CONFIG_INT 2
-#define CYGNUM_FLASH_CFG_OP_CONFIG_STRING 3
-#define CYGNUM_FLASH_CFG_OP_CONFIG_SCRIPT 4
-#define CYGNUM_FLASH_CFG_OP_CONFIG_IP 5
-#define CYGNUM_FLASH_CFG_OP_CONFIG_ESA 6
+#define CYGNUM_FLASH_CFG_TYPE_CONFIG_EMPTY 0
+#define CYGNUM_FLASH_CFG_TYPE_CONFIG_BOOL 1
+#define CYGNUM_FLASH_CFG_TYPE_CONFIG_INT 2
+#define CYGNUM_FLASH_CFG_TYPE_CONFIG_STRING 3
+#define CYGNUM_FLASH_CFG_TYPE_CONFIG_SCRIPT 4
+#define CYGNUM_FLASH_CFG_TYPE_CONFIG_IP 5
+#define CYGNUM_FLASH_CFG_TYPE_CONFIG_ESA 6
#endif // CYGACC_CALL_IF_DEFINED
//--------------------------------------------------------------------------
// Diag wrappers.
Index: hal/common/current/src/hal_if.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/hal/common/current/src/hal_if.c,v
retrieving revision 1.26
diff -u -5 -p -r1.26 hal_if.c
--- hal/common/current/src/hal_if.c 7 Sep 2003 11:48:57 -0000 1.26
+++ hal/common/current/src/hal_if.c 21 Dec 2003 13:12:13 -0000
@@ -7,11 +7,11 @@
//=============================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
// Copyright (C) 2003 Nick Garnett <nickg@calivar.com>
// Copyright (C) 2003 Jonathan Larmour <jlarmour@eCosCentric.com>
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
@@ -94,19 +94,25 @@ externC void init_thread_syscall(void *
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
static __call_if_flash_cfg_op_fn_t flash_config_op;
static cyg_bool
-flash_config_op( int op, char * key, void *val, int type)
+flash_config_op(int op, struct cyg_fconfig *fc)
{
cyg_bool res = false;
CYGARC_HAL_SAVE_GP();
- switch ( op ) {
+ switch (op) {
case CYGNUM_CALL_IF_FLASH_CFG_GET:
- res = flash_get_config( key, val, type );
+ res = flash_get_config(fc->key, fc->val, fc->type);
+ break;
+ case CYGNUM_CALL_IF_FLASH_CFG_NEXT:
+ res = flash_next_key(fc->key, fc->keylen, &fc->type, &fc->offset);
+ break;
+ case CYGNUM_CALL_IF_FLASH_CFG_SET:
+ res = flash_set_config(fc->key, fc->val, fc->type);
break;
default:
// nothing else supported yet - though it is expected that "set"
// will fit the same set of arguments, potentially.
break;
Index: infra/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/infra/current/ChangeLog,v
retrieving revision 1.40
diff -u -5 -p -r1.40 ChangeLog
--- infra/current/ChangeLog 11 Oct 2003 19:50:03 -0000 1.40
+++ infra/current/ChangeLog 21 Dec 2003 13:12:38 -0000
@@ -1,5 +1,12 @@
+2003-12-21 Gary Thomas <gary@mlbassoc.com>
+
+ * tests/fc_test.c: New test/demonstration of 'fconfig' access.
+
+ * src/tcdiag.cxx (cyg_assert_msg): Interface to 'fconfig' data
+ has changed.
+
2003-10-11 Gary Thomas <gary@mlbassoc.com>
* src/tcdiag.cxx (cyg_test_exit):
* cdl/infra.cdl: New option CYGSEM_INFRA_RESET_ON_TEST_EXIT which
[if defined] indicates that "cyg_test_exit()" should reset the
Index: infra/current/src/tcdiag.cxx
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/infra/current/src/tcdiag.cxx,v
retrieving revision 1.11
diff -u -5 -p -r1.11 tcdiag.cxx
--- infra/current/src/tcdiag.cxx 11 Oct 2003 19:50:03 -0000 1.11
+++ infra/current/src/tcdiag.cxx 21 Dec 2003 12:40:42 -0000
@@ -151,20 +151,26 @@ cyg_assert_msg( const char *psz_func, co
#ifdef CYGSEM_HAL_VIRTUAL_VECTOR_SUPPORT
{
int cur_console;
int i;
+ struct cyg_fconfig fc;
+
cur_console = CYGACC_CALL_IF_SET_CONSOLE_COMM(CYGNUM_CALL_IF_SET_COMM_ID_QUERY_CURRENT);
- if ( CYGACC_CALL_IF_FLASH_CFG_OP( CYGNUM_CALL_IF_FLASH_CFG_GET,
- "info_console_force", &i,
- CYGNUM_FLASH_CFG_OP_CONFIG_BOOL ) )
- if ( i )
- if ( CYGACC_CALL_IF_FLASH_CFG_OP( CYGNUM_CALL_IF_FLASH_CFG_GET,
- "info_console_number", &i,
- CYGNUM_FLASH_CFG_OP_CONFIG_INT ) )
+ fc.key = "info_console_force";
+ fc.type = CYGNUM_FLASH_CFG_TYPE_CONFIG_BOOL;
+ fc.val = (void *)&i;
+ if (CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) {
+ if (i) {
+ fc.key = "info_console_number";
+ fc.type = CYGNUM_FLASH_CFG_TYPE_CONFIG_INT;
+ if (CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) {
// Then i is the console to force it to:
- CYGACC_CALL_IF_SET_CONSOLE_COMM( i );
+ CYGACC_CALL_IF_SET_CONSOLE_COMM(i);
+ }
+ }
+ }
#endif
diag_write_string("ASSERT FAIL: ");
write_thread_id();
diag_write_string(trim_file(psz_file));
write_lnum(linenum);
Index: infra/current/tests/fc_test.c
===================================================================
RCS file: infra/current/tests/fc_test.c
diff -N infra/current/tests/fc_test.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ infra/current/tests/fc_test.c 21 Dec 2003 13:08:59 -0000
@@ -0,0 +1,108 @@
+//==========================================================================
+//
+// fc_test.c
+//
+// Test/demonstration of using RedBoot 'fconfig' from eCos
+//
+//==========================================================================
+//####ECOSGPLCOPYRIGHTBEGIN####
+// -------------------------------------------
+// This file is part of eCos, the Embedded Configurable Operating System.
+// Copyright (C) 2003 Gary Thomas
+//
+// eCos is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 2 or (at your option) any later version.
+//
+// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with eCos; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+//
+// As a special exception, if other files instantiate templates or use macros
+// or inline functions from this file, or you compile this file and link it
+// with other works to produce a work based on this file, this file does not
+// by itself cause the resulting work to be covered by the GNU General Public
+// License. However the source code for this file must still be made available
+// in accordance with section (3) of the GNU General Public License.
+//
+// This exception does not invalidate any other reasons why a work based on
+// this file might be covered by the GNU General Public License.
+//
+// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+// at http://sources.redhat.com/ecos/ecos-license/
+// -------------------------------------------
+//####ECOSGPLCOPYRIGHTEND####
+//==========================================================================
+//#####DESCRIPTIONBEGIN####
+//
+// Author(s): gthomas
+// Contributors: gthomas
+// Date: 2003-12-22
+// Purpose:
+// Description:
+//
+//####DESCRIPTIONEND####
+//
+//==========================================================================
+
+//
+// Demonstration of how to use virtual vector interfaces to access/modify
+// persistent data stored by 'fconfig' command in RedBoot.
+//
+// Note: there is currently no support for adding new keys using this
+// mechanism. Only existing key/value pairs may be updated.
+//
+#include <pkgconf/hal.h>
+#include <cyg/hal/hal_if.h>
+#include <cyg/infra/diag.h>
+
+void
+main(void)
+{
+ struct cyg_fconfig fc;
+ char key[64];
+ int port;
+
+ diag_printf("fconfig test started\n");
+ fc.offset = 0;
+ fc.key = key;
+ fc.keylen = sizeof(key);
+ while (CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_NEXT, &fc)) {
+ diag_printf(" Offset: %d, key: '%s', type: %d\n", fc.offset, fc.key, fc.type);
+ fc.keylen = sizeof(key);
+ }
+ // Try and update a data value
+ fc.key = "gdb_port";
+ fc.val = &port;
+ fc.type = CYGNUM_FLASH_CFG_TYPE_CONFIG_INT;
+ if (CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) {
+ diag_printf("gdb_port = %d\n", port);
+ port++;
+ if (CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_SET, &fc)) {
+ if (CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_GET, &fc)) {
+ diag_printf("now = %d\n", port);
+ } else {
+ diag_printf("Can't re-fetch 'gdb_port'\n");
+ exit(1);
+ }
+ port--;
+ if (!CYGACC_CALL_IF_FLASH_CFG_OP(CYGNUM_CALL_IF_FLASH_CFG_SET, &fc)) {
+ diag_printf("Can't update 'gdb_port'\n");
+ exit(1);
+ }
+ } else {
+ diag_printf("Can't update 'gdb_port'\n");
+ exit(1);
+ }
+ } else {
+ diag_printf("Fetch 'gdb_port' failed\n");
+ exit(1);
+ }
+ diag_printf("... done\n");
+ exit(1);
+}