]> git.kernelconcepts.de Git - karo-tx-redboot.git/blobdiff - packages/redboot/v2_0/src/fconfig.c
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / redboot / v2_0 / src / fconfig.c
index 92d85e6cc51f30b528a8edc38c59c68727a11b32..a66e5d99398216f9b3644bce72c1fc8c54d2da9d 100644 (file)
@@ -75,7 +75,7 @@ externC bool cyg_plf_redboot_esa_validate(unsigned char *val);
 #endif
 
 #ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
-externC bool do_flash_init(void);
+externC int do_flash_init(void);
 externC int flash_read(void *flash_base, void *ram_base, int len, void **err_address);
 #endif
 
@@ -215,7 +215,7 @@ conf_endian_fixup(void *ptr)
     while (dp < &p->config_data[sizeof(config->config_data)]) {
         len = 4 + CONFIG_OBJECT_KEYLEN(dp) + CONFIG_OBJECT_ENABLE_KEYLEN(dp) +
             config_length(CONFIG_OBJECT_TYPE(dp));
-        val_ptr = (void *)CONFIG_OBJECT_VALUE(dp);
+        val_ptr = CONFIG_OBJECT_VALUE(dp);
 
         switch (CONFIG_OBJECT_TYPE(dp)) {
             // Note: the data may be unaligned in the configuration data
@@ -271,12 +271,13 @@ get_config(unsigned char *dp, char *title, int list_opt, char *newvalue )
             return CONFIG_OK;  // Disabled field
         }
     }
-    lp = line;  *lp = '\0';
-    val_ptr = (void *)CONFIG_OBJECT_VALUE(dp);
+    lp = line;
+    *lp = '\0';
+    val_ptr = CONFIG_OBJECT_VALUE(dp);
     if (LIST_OPT_NICKNAMES & list_opt)
         diag_printf("%s: ", CONFIG_OBJECT_KEY(dp));
     if (LIST_OPT_FULLNAMES & list_opt) {
-        if (title != (char *)NULL) {
+        if (title != NULL) {
             diag_printf("%s: ", title);
         } else {
             diag_printf("%s: ", CONFIG_OBJECT_KEY(dp));
@@ -532,18 +533,18 @@ do_flash_config(int argc, char *argv[])
     }
 #endif
     memcpy(backup_config, config, sizeof(struct _config));
-    script = (unsigned char *)0;
+    script = NULL;
 
     init_opts(&opts[0], 'l', false, OPTION_ARG_TYPE_FLG, 
-              (void *)&list_only, (bool *)0, "list configuration only");
+              &list_only, NULL, "list configuration only");
     init_opts(&opts[1], 'n', false, OPTION_ARG_TYPE_FLG, 
-              (void *)&nicknames, (bool *)0, "show nicknames");
+              &nicknames, NULL, "show nicknames");
     init_opts(&opts[2], 'f', false, OPTION_ARG_TYPE_FLG, 
-              (void *)&fullnames, (bool *)0, "show full names");
+              &fullnames, NULL, "show full names");
     init_opts(&opts[3], 'i', false, OPTION_ARG_TYPE_FLG, 
-              (void *)&init, (bool *)0, "initialize configuration database");
+              &init, NULL, "initialize configuration database");
     init_opts(&opts[4], 'd', false, OPTION_ARG_TYPE_FLG, 
-              (void *)&dumbterminal, (bool *)0, "dumb terminal: no clever edits");
+              &dumbterminal, NULL, "dumb terminal: no clever edits");
 
     // First look to see if we are setting or getting a single option
     // by just quoting its nickname
@@ -578,15 +579,15 @@ do_flash_config(int argc, char *argv[])
         need_update = true;
     }
 
-    dp = &config->config_data[0];
+    dp = config->config_data;
     while (dp < &config->config_data[sizeof(config->config_data)]) {
         if (CONFIG_OBJECT_TYPE(dp) == CONFIG_EMPTY) {
             break;
         }
         len = 4 + CONFIG_OBJECT_KEYLEN(dp) + CONFIG_OBJECT_ENABLE_KEYLEN(dp) + 
-            config_length(CONFIG_OBJECT_TYPE(dp));
+               config_length(CONFIG_OBJECT_TYPE(dp));
         // Provide a title for well known [i.e. builtin] objects
-        title = (char *)NULL;
+        title = NULL;
         opt = __CONFIG_options_TAB__;
         while (opt != optend) {
             if (strcmp(opt->key, CONFIG_OBJECT_KEY(dp)) == 0) {
@@ -595,7 +596,7 @@ do_flash_config(int argc, char *argv[])
             }
             opt++;
         }
-        if ( onlyone && 0 != strcmp(CONFIG_OBJECT_KEY(dp), onlyone) )
+        if (onlyone && 0 != strcmp(CONFIG_OBJECT_KEY(dp), onlyone))
             ret = CONFIG_OK; // skip this entry
         else {
             doneone = true;
@@ -613,7 +614,7 @@ do_flash_config(int argc, char *argv[])
             dp += len;
             break;
         case CONFIG_BACK:
-            dp = &config->config_data[0];
+            dp = config->config_data;
             continue;
         case CONFIG_BAD:
             // Nothing - make him do it again
@@ -676,7 +677,7 @@ do_alias(int argc, char *argv[])
         }
         make_alias(name, argv[1]);
         opt.type = CONFIG_STRING;
-        opt.enable = (char *)0;
+        opt.enable = NULL;
         opt.enable_sense = 1;
         opt.key = name;
         opt.dflt = (CYG_ADDRESS)argv[2];
@@ -711,7 +712,7 @@ flash_lookup_alias(char *alias, char *alias_buf)
     } else {
         dp = flash_lookup_config(alias);
         if (dp) {
-            val_ptr = (void *)CONFIG_OBJECT_VALUE(dp);
+            val_ptr = CONFIG_OBJECT_VALUE(dp);
             switch (type = CONFIG_OBJECT_TYPE(dp)) {
             case CONFIG_BOOL:
                 memcpy(&hold_bool_val, val_ptr, sizeof(bool));
@@ -733,14 +734,14 @@ flash_lookup_alias(char *alias, char *alias_buf)
                 break;
 #endif
             case CONFIG_SCRIPT:
-                return (char *) val_ptr;
+                return val_ptr;
                 break;
             default:
-                return (char *)NULL;
+                return NULL;
             }
             return alias_buf;
         } 
-        return (char *)NULL;
+        return NULL;
     }
 }
 
@@ -792,22 +793,22 @@ flash_write_config(bool prompt)
         fis_update_directory();
 #else 
 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL
-        // Insure [quietly] that the config page is unlocked before trying to update
-        flash_unlock((void *)cfg_base, cfg_size, (void **)&err_addr);
+        // Ensure [quietly] that the config page is unlocked before trying to update
+        flash_unlock(cfg_base, cfg_size, &err_addr);
 #endif
-        if ((stat = flash_erase(cfg_base, cfg_size, (void **)&err_addr)) != 0) {
+        if ((stat = flash_erase(cfg_base, cfg_size, &err_addr)) != 0) {
             diag_printf("   initialization failed at %p: %s\n", err_addr, flash_errmsg(stat));
         } else {
             conf_endian_fixup(config);
-            if ((stat = FLASH_PROGRAM(cfg_base, config, sizeof(struct _config), (void **)&err_addr)) != 0) {
+            if ((stat = FLASH_PROGRAM(cfg_base, config, sizeof(struct _config), &err_addr)) != 0) {
                 diag_printf("Error writing config data at %p: %s\n", 
                             err_addr, flash_errmsg(stat));
             }
             conf_endian_fixup(config);
         }
 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL
-        // Insure [quietly] that the config data is locked after the update
-        flash_lock((void *)cfg_base, cfg_size, (void **)&err_addr);
+        // Ensure [quietly] that the config data is locked after the update
+        flash_lock(cfg_base, cfg_size, &err_addr);
 #endif
 #endif // CYGSEM_REDBOOT_FLASH_COMBINED_FIS_AND_CONFIG
 #else  // CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
@@ -825,9 +826,9 @@ flash_lookup_config(char *key)
     unsigned char *dp;
     int len;
 
-    if (!config_ok) return (unsigned char *)NULL;
+    if (!config_ok) return NULL;
 
-    dp = &config->config_data[0];
+    dp = config->config_data;
     while (dp < &config->config_data[sizeof(config->config_data)]) {
         len = 4 + CONFIG_OBJECT_KEYLEN(dp) + CONFIG_OBJECT_ENABLE_KEYLEN(dp) +
             config_length(CONFIG_OBJECT_TYPE(dp));
@@ -876,9 +877,9 @@ flash_get_config(char *key, void *val, int type)
 
     if (!config_ok) return false;
 
-    if ((dp = flash_lookup_config(key)) != (unsigned char *)NULL) {
+    if ((dp = flash_lookup_config(key)) != NULL) {
         if (CONFIG_OBJECT_TYPE(dp) == type) {
-            val_ptr = (void *)CONFIG_OBJECT_VALUE(dp);
+            val_ptr = CONFIG_OBJECT_VALUE(dp);
             switch (type) {
                 // Note: the data may be unaligned in the configuration data
             case CONFIG_BOOL:
@@ -946,9 +947,9 @@ flash_set_config(char *key, void *val, int type)
 
     if (!config_ok) return false;
 
-    if ((dp = flash_lookup_config(key)) != (unsigned char *)NULL) {
+    if ((dp = flash_lookup_config(key)) != NULL) {
         if (CONFIG_OBJECT_TYPE(dp) == type) {
-            val_ptr = (void *)CONFIG_OBJECT_VALUE(dp);
+            val_ptr = CONFIG_OBJECT_VALUE(dp);
             switch (type) {
                 // Note: the data may be unaligned in the configuration data
             case CONFIG_BOOL:
@@ -992,14 +993,14 @@ flash_config_insert_value(unsigned char *dp, struct config_option *opt)
     switch (opt->type) {
         // Note: the data may be unaligned in the configuration data
     case CONFIG_BOOL:
-        memcpy(dp, (void *)&opt->dflt, sizeof(bool));
+        memcpy(dp, &opt->dflt, sizeof(bool));
         break;
     case CONFIG_INT:
-        memcpy(dp, (void *)&opt->dflt, sizeof(unsigned long));
+        memcpy(dp, &opt->dflt, sizeof(unsigned long));
         break;
 #ifdef CYGPKG_REDBOOT_NETWORKING
     case CONFIG_IP:
-        memcpy(dp, (void *)&opt->dflt, sizeof(in_addr_t));
+        memcpy(dp, &opt->dflt, sizeof(in_addr_t));
         break;
     case CONFIG_ESA:
         memcpy(dp, (void *)opt->dflt, sizeof(enet_addr_t));
@@ -1039,7 +1040,7 @@ flash_add_config(struct config_option *opt, bool update)
 
     // 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) {
+    if ((dp = flash_lookup_config(opt->key)) != NULL) {
         flash_config_insert_value(CONFIG_OBJECT_VALUE(dp), opt);
         if (update) {
             flash_write_config(true);
@@ -1047,7 +1048,7 @@ flash_add_config(struct config_option *opt, bool update)
         return true;
     }
     // Add the data item
-    dp = &config->config_data[0];
+    dp = config->config_data;
     size = 0;
     while (size < sizeof(config->config_data)) {
         if (CONFIG_OBJECT_TYPE(dp) == CONFIG_EMPTY) {
@@ -1120,13 +1121,13 @@ static void
 load_flash_config(void)
 {
     bool use_boot_script;
-    unsigned char *cfg_temp = (unsigned char *)workspace_end;
+    unsigned char *cfg_temp = workspace_end;
 #ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
     void *err_addr;
 #endif
 
     config_ok = false;
-    script = (unsigned char *)0;
+    script = NULL;
     cfg_temp -= sizeof(struct _config);  // Space for primary config data
     config = (struct _config *)cfg_temp;
     cfg_temp -= sizeof(struct _config);  // Space for backup config data
@@ -1137,7 +1138,7 @@ load_flash_config(void)
 #endif
     workspace_end = cfg_temp;
 #ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
-    if (!do_flash_init()) return;
+    if (do_flash_init()<0) return;
 #ifdef CYGSEM_REDBOOT_FLASH_COMBINED_FIS_AND_CONFIG
     cfg_size = _rup(sizeof(struct _config), sizeof(struct fis_image_desc));
     if ((fisdir_size-cfg_size) < (CYGNUM_REDBOOT_FIS_DIRECTORY_ENTRY_COUNT *
@@ -1154,10 +1155,12 @@ load_flash_config(void)
         _rup(sizeof(struct _config), flash_block_size);
     if (CYGNUM_REDBOOT_FLASH_CONFIG_BLOCK < 0) {
         cfg_base = (void *)((CYG_ADDRESS)flash_end + 1 -
-           _rup(_rup((-CYGNUM_REDBOOT_FLASH_CONFIG_BLOCK*flash_block_size), cfg_size), flash_block_size));
+           _rup(_rup((-CYGNUM_REDBOOT_FLASH_CONFIG_BLOCK * flash_block_size), cfg_size),
+               flash_block_size));
     } else {
         cfg_base = (void *)((CYG_ADDRESS)flash_start + 
-           _rup(_rup((CYGNUM_REDBOOT_FLASH_CONFIG_BLOCK*flash_block_size), cfg_size), flash_block_size));
+           _rup(_rup((CYGNUM_REDBOOT_FLASH_CONFIG_BLOCK * flash_block_size), cfg_size),
+               flash_block_size));
     }
 #endif
     FLASH_READ(cfg_base, config, sizeof(struct _config), &err_addr);