comparison packages/redboot/current/src/flash.c @ 157:b65ec671dd4c

Merge from eCos master repository on 2001-04-06-18:28:36-BST
author jlarmour
date Fri, 06 Apr 2001 19:06:06 +0000
parents b939e9cada46
children 511f4dc167f6
comparison
equal deleted inserted replaced
156:b939e9cada46 157:b65ec671dd4c
54 do_fis 54 do_fis
55 ); 55 );
56 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG 56 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG
57 RedBoot_cmd("fconfig", 57 RedBoot_cmd("fconfig",
58 "Manage configuration kept in FLASH memory", 58 "Manage configuration kept in FLASH memory",
59 "[-l]", 59 "[-l] [-n] [-f] | nickname [value]",
60 do_flash_config 60 do_flash_config
61 ); 61 );
62 #endif 62 #endif
63 63
64 // Internal commands 64 // Internal commands
66 "Initialize FLASH Image System [FIS]", 66 "Initialize FLASH Image System [FIS]",
67 "[-f]", 67 "[-f]",
68 fis_init, 68 fis_init,
69 FIS_cmds 69 FIS_cmds
70 ); 70 );
71
72
73 #ifdef CYGSEM_REDBOOT_FIS_CRC_CHECK
74 # define FIS_LIST_OPTS "[-c] [-d]"
75 #else
76 # define FIS_LIST_OPTS "[-d]"
77 #endif
78
71 local_cmd_entry("list", 79 local_cmd_entry("list",
72 "Display contents of FLASH Image System [FIS]", 80 "Display contents of FLASH Image System [FIS]",
73 "[-c] [-d]", 81 FIS_LIST_OPTS,
74 fis_list, 82 fis_list,
75 FIS_cmds 83 FIS_cmds
76 ); 84 );
77 local_cmd_entry("free", 85 local_cmd_entry("free",
78 "Display free [available] locations within FLASH Image System [FIS]", 86 "Display free [available] locations within FLASH Image System [FIS]",
322 int i; 330 int i;
323 bool show_cksums = false; 331 bool show_cksums = false;
324 bool show_datalen = false; 332 bool show_datalen = false;
325 struct option_info opts[2]; 333 struct option_info opts[2];
326 334
327 init_opts(&opts[0], 'c', false, OPTION_ARG_TYPE_FLG, 335 init_opts(&opts[0], 'd', false, OPTION_ARG_TYPE_FLG,
336 (void **)&show_datalen, (bool *)0, "display data length");
337 #ifdef CYGSEM_REDBOOT_FIS_CRC_CHECK
338 init_opts(&opts[1], 'c', false, OPTION_ARG_TYPE_FLG,
328 (void **)&show_cksums, (bool *)0, "display checksums"); 339 (void **)&show_cksums, (bool *)0, "display checksums");
329 init_opts(&opts[1], 'd', false, OPTION_ARG_TYPE_FLG, 340 i = 2;
330 (void **)&show_datalen, (bool *)0, "display data length"); 341 #else
331 if (!scan_opts(argc, argv, 2, opts, 2, 0, 0, "")) 342 i = 1;
343 #endif
344 if (!scan_opts(argc, argv, 2, opts, i, 0, 0, ""))
332 { 345 {
333 return; 346 return;
334 } 347 }
335 348
336 img = (struct fis_image_desc *)((unsigned long)flash_end - block_size); 349 img = (struct fis_image_desc *)((unsigned long)flash_end - block_size);
343 "Entry point" ); 356 "Entry point" );
344 for (i = 0; i < block_size/sizeof(*img); i++, img++) { 357 for (i = 0; i < block_size/sizeof(*img); i++, img++) {
345 if (img->name[0] != (unsigned char)0xFF) { 358 if (img->name[0] != (unsigned char)0xFF) {
346 printf("%-16s 0x%08lX 0x%08lX 0x%08lX 0x%08lX\n", img->name, 359 printf("%-16s 0x%08lX 0x%08lX 0x%08lX 0x%08lX\n", img->name,
347 img->flash_base, 360 img->flash_base,
361 #ifdef CYGSEM_REDBOOT_FIS_CRC_CHECK
348 show_cksums ? img->file_cksum : img->mem_base, 362 show_cksums ? img->file_cksum : img->mem_base,
349 show_datalen ? img->data_length : img->size, 363 show_datalen ? img->data_length : img->size,
364 #else
365 img->mem_base,
366 img->size,
367 #endif
350 img->entry_point); 368 img->entry_point);
351 } 369 }
352 } 370 }
353 } 371 }
354 372
612 img->flash_base = flash_addr; 630 img->flash_base = flash_addr;
613 img->mem_base = exec_addr_set ? exec_addr : (flash_addr_set ? flash_addr : mem_addr); 631 img->mem_base = exec_addr_set ? exec_addr : (flash_addr_set ? flash_addr : mem_addr);
614 img->entry_point = entry_addr_set ? entry_addr : (unsigned long)entry_address; // Hope it's been set 632 img->entry_point = entry_addr_set ? entry_addr : (unsigned long)entry_address; // Hope it's been set
615 img->size = length; 633 img->size = length;
616 img->data_length = img_size; 634 img->data_length = img_size;
635 #ifdef CYGSEM_REDBOOT_FIS_CRC_CHECK
617 img->file_cksum = crc32((unsigned char *)flash_addr, img_size); 636 img->file_cksum = crc32((unsigned char *)flash_addr, img_size);
637 #endif
618 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL 638 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL
619 // Insure [quietly] that the directory is unlocked before trying to update 639 // Insure [quietly] that the directory is unlocked before trying to update
620 flash_unlock((void *)fis_addr, block_size, (void **)&err_addr); 640 flash_unlock((void *)fis_addr, block_size, (void **)&err_addr);
621 #endif 641 #endif
622 if ((stat = flash_erase((void *)fis_addr, block_size, (void **)&err_addr)) != 0) { 642 if ((stat = flash_erase((void *)fis_addr, block_size, (void **)&err_addr)) != 0) {
967 #endif 987 #endif
968 { 988 {
969 memcpy((void *)mem_addr, (void *)img->flash_base, img->data_length); 989 memcpy((void *)mem_addr, (void *)img->flash_base, img->data_length);
970 } 990 }
971 entry_address = (unsigned long *)img->entry_point; 991 entry_address = (unsigned long *)img->entry_point;
992 #ifdef CYGPKG_REDBOOT_FIS_CRC_CHECK
972 cksum = crc32((unsigned char *)mem_addr, img->data_length); 993 cksum = crc32((unsigned char *)mem_addr, img->data_length);
973 if (show_cksum) { 994 if (show_cksum) {
974 printf("Checksum: 0x%08lx\n", cksum); 995 printf("Checksum: 0x%08lx\n", cksum);
975 } 996 }
976 // When decompressing, leave CRC checking to decompressor 997 // When decompressing, leave CRC checking to decompressor
978 if (cksum != img->file_cksum) { 999 if (cksum != img->file_cksum) {
979 printf("** Warning - checksum failure. stored: 0x%08lx, computed: 0x%08lx\n", 1000 printf("** Warning - checksum failure. stored: 0x%08lx, computed: 0x%08lx\n",
980 img->file_cksum, cksum); 1001 img->file_cksum, cksum);
981 } 1002 }
982 } 1003 }
1004 #endif
983 } 1005 }
984 1006
985 static bool 1007 static bool
986 do_flash_init(void) 1008 do_flash_init(void)
987 { 1009 {
1103 #define CONFIG_OBJECT_ENABLE_KEYLEN(dp) (dp)[3] 1125 #define CONFIG_OBJECT_ENABLE_KEYLEN(dp) (dp)[3]
1104 #define CONFIG_OBJECT_KEY(dp) ((dp)+4) 1126 #define CONFIG_OBJECT_KEY(dp) ((dp)+4)
1105 #define CONFIG_OBJECT_ENABLE_KEY(dp) ((dp)+4+CONFIG_OBJECT_KEYLEN(dp)) 1127 #define CONFIG_OBJECT_ENABLE_KEY(dp) ((dp)+4+CONFIG_OBJECT_KEYLEN(dp))
1106 #define CONFIG_OBJECT_VALUE(dp) ((dp)+4+CONFIG_OBJECT_KEYLEN(dp)+CONFIG_OBJECT_ENABLE_KEYLEN(dp)) 1128 #define CONFIG_OBJECT_VALUE(dp) ((dp)+4+CONFIG_OBJECT_KEYLEN(dp)+CONFIG_OBJECT_ENABLE_KEYLEN(dp))
1107 1129
1130 #define LIST_OPT_LIST_ONLY (1)
1131 #define LIST_OPT_NICKNAMES (2)
1132 #define LIST_OPT_FULLNAMES (4)
1133
1108 static int 1134 static int
1109 get_config(unsigned char *dp, char *title, bool list_only) 1135 get_config(unsigned char *dp, char *title, int list_opt, char *newvalue )
1110 { 1136 {
1111 char line[256], *sp, *lp; 1137 char line[256], *sp, *lp;
1112 int ret; 1138 int ret;
1113 bool hold_bool_val, new_bool_val, enable; 1139 bool hold_bool_val, new_bool_val, enable;
1114 unsigned long hold_int_val, new_int_val; 1140 unsigned long hold_int_val, new_int_val;
1127 (!(bool)CONFIG_OBJECT_ENABLE_SENSE(dp) && enable)) { 1153 (!(bool)CONFIG_OBJECT_ENABLE_SENSE(dp) && enable)) {
1128 return CONFIG_OK; // Disabled field 1154 return CONFIG_OK; // Disabled field
1129 } 1155 }
1130 } 1156 }
1131 val_ptr = (void *)CONFIG_OBJECT_VALUE(dp); 1157 val_ptr = (void *)CONFIG_OBJECT_VALUE(dp);
1132 if (title != (char *)NULL) { 1158 if (LIST_OPT_NICKNAMES & list_opt)
1133 printf("%s: ", title);
1134 } else {
1135 printf("%s: ", CONFIG_OBJECT_KEY(dp)); 1159 printf("%s: ", CONFIG_OBJECT_KEY(dp));
1160 if (LIST_OPT_FULLNAMES & list_opt) {
1161 if (title != (char *)NULL) {
1162 printf("%s: ", title);
1163 } else {
1164 printf("%s: ", CONFIG_OBJECT_KEY(dp));
1165 }
1136 } 1166 }
1137 switch (type = CONFIG_OBJECT_TYPE(dp)) { 1167 switch (type = CONFIG_OBJECT_TYPE(dp)) {
1138 case CONFIG_BOOL: 1168 case CONFIG_BOOL:
1139 memcpy(&hold_bool_val, val_ptr, sizeof(bool)); 1169 memcpy(&hold_bool_val, val_ptr, sizeof(bool));
1140 printf("%s ", hold_bool_val ? "true" : "false"); 1170 printf("%s ", hold_bool_val ? "true" : "false");
1168 *lp++ = '\n'; 1198 *lp++ = '\n';
1169 sp = lp; 1199 sp = lp;
1170 } 1200 }
1171 break; 1201 break;
1172 } 1202 }
1173 if (list_only) { 1203 if (LIST_OPT_LIST_ONLY & list_opt) {
1174 printf("\n"); 1204 printf("\n");
1175 return CONFIG_OK; 1205 return CONFIG_OK;
1176 } 1206 }
1177 if (type != CONFIG_SCRIPT) { 1207 if (type != CONFIG_SCRIPT) {
1178 ret = gets(line, sizeof(line), 0); 1208 if (NULL != newvalue) {
1209 ret = strlen(newvalue);
1210 if (ret > sizeof(line))
1211 return CONFIG_BAD;
1212 strcpy(line, newvalue);
1213 printf("Setting to %s\n", newvalue);
1214 }
1215 else // read from terminal
1216 ret = gets(line, sizeof(line), 0);
1179 if (ret < 0) return CONFIG_ABORT; 1217 if (ret < 0) return CONFIG_ABORT;
1180 if (strlen(line) == 0) return CONFIG_OK; // Just a CR - leave value untouched 1218 if (strlen(line) == 0) return CONFIG_OK; // Just a CR - leave value untouched
1181 if (line[0] == '.') return CONFIG_DONE; 1219 if (line[0] == '.') return CONFIG_DONE;
1182 if (line[0] == '^') return CONFIG_BACK; 1220 if (line[0] == '^') return CONFIG_BACK;
1183 } 1221 }
1290 { 1328 {
1291 bool need_update = false; 1329 bool need_update = false;
1292 struct config_option *optend = __CONFIG_options_TAB_END__; 1330 struct config_option *optend = __CONFIG_options_TAB_END__;
1293 struct config_option *opt = __CONFIG_options_TAB__; 1331 struct config_option *opt = __CONFIG_options_TAB__;
1294 struct _config hold_config; 1332 struct _config hold_config;
1295 struct option_info opts[1]; 1333 struct option_info opts[3];
1296 bool list_only; 1334 bool list_only;
1335 bool nicknames;
1336 bool fullnames;
1337 int list_opt = 0;
1297 unsigned char *dp; 1338 unsigned char *dp;
1298 int len, ret; 1339 int len, ret;
1299 char *title; 1340 char *title;
1341 char *onlyone = NULL;
1342 char *onevalue = NULL;
1343 bool doneone = false;
1300 1344
1301 if (!do_flash_init()) return; 1345 if (!do_flash_init()) return;
1302 memcpy(&hold_config, &config, sizeof(config)); 1346 memcpy(&hold_config, &config, sizeof(config));
1303 script = (unsigned char *)0; 1347 script = (unsigned char *)0;
1304 1348
1305 init_opts(&opts[0], 'l', false, OPTION_ARG_TYPE_FLG, 1349 init_opts(&opts[0], 'l', false, OPTION_ARG_TYPE_FLG,
1306 (void **)&list_only, (bool *)0, "list configuration only"); 1350 (void **)&list_only, (bool *)0, "list configuration only");
1307 if (!scan_opts(argc, argv, 1, opts, 1, 0, 0, "")) 1351 init_opts(&opts[1], 'n', false, OPTION_ARG_TYPE_FLG,
1308 { 1352 (void **)&nicknames, (bool *)0, "show nicknames");
1309 return; 1353 init_opts(&opts[2], 'f', false, OPTION_ARG_TYPE_FLG,
1354 (void **)&fullnames, (bool *)0, "show full names");
1355
1356 // First look to see if we are setting or getting a single option
1357 // by just quoting its nickname
1358 if ( (2 == argc && '-' != argv[1][0]) ||
1359 (3 == argc && '-' != argv[1][0] && '-' != argv[2][0])) {
1360 // then the command was "fconfig foo [value]"
1361 onlyone = argv[1];
1362 onevalue = (3 == argc) ? argv[2] : NULL;
1363 list_opt = LIST_OPT_NICKNAMES;
1364 }
1365 else {
1366 if (!scan_opts(argc, argv, 1, opts, 3, 0, 0, ""))
1367 return;
1368 list_opt |= list_only ? LIST_OPT_LIST_ONLY : 0;
1369 list_opt |= nicknames ? LIST_OPT_NICKNAMES : LIST_OPT_FULLNAMES;
1370 list_opt |= fullnames ? LIST_OPT_FULLNAMES : 0;
1310 } 1371 }
1311 1372
1312 dp = &config.config_data[0]; 1373 dp = &config.config_data[0];
1313 while (dp < &config.config_data[sizeof(config.config_data)]) { 1374 while (dp < &config.config_data[sizeof(config.config_data)]) {
1314 if (CONFIG_OBJECT_TYPE(dp) == CONFIG_EMPTY) { 1375 if (CONFIG_OBJECT_TYPE(dp) == CONFIG_EMPTY) {
1324 title = opt->title; 1385 title = opt->title;
1325 break; 1386 break;
1326 } 1387 }
1327 opt++; 1388 opt++;
1328 } 1389 }
1329 ret = get_config(dp, title, list_only); 1390 if ( onlyone && 0 != strcmp(opt->key, onlyone) )
1391 ret = CONFIG_OK; // skip this entry
1392 else {
1393 doneone = true;
1394 ret = get_config(dp, title, list_opt, onevalue); // do this opt
1395 }
1330 switch (ret) { 1396 switch (ret) {
1331 case CONFIG_DONE: 1397 case CONFIG_DONE:
1332 goto done; 1398 goto done;
1333 case CONFIG_ABORT: 1399 case CONFIG_ABORT:
1334 memcpy(&config, &hold_config, sizeof(config)); 1400 memcpy(&config, &hold_config, sizeof(config));
1346 printf ("** invalid entry\n"); 1412 printf ("** invalid entry\n");
1347 } 1413 }
1348 } 1414 }
1349 1415
1350 done: 1416 done:
1351 if (!need_update) return; 1417 if (NULL != onlyone && !doneone)
1418 printf("** entry '%s' not found\n", onlyone);
1419 if (!need_update)
1420 return;
1352 flash_write_config(); 1421 flash_write_config();
1353 } 1422 }
1354 1423
1355 // 1424 //
1356 // Write the in-memory copy of the configuration data to the flash device. 1425 // Write the in-memory copy of the configuration data to the flash device.