comparison packages/redboot/current/src/flash.c @ 307:906a5d289c6d

Better memory use vis FIS & ZLIB - from Thomas Koeller
author gthomas
date Sat, 24 Aug 2002 11:34:49 +0000
parents 3e80ecaaa3f8
children 113a540ea6db
comparison
equal deleted inserted replaced
306:eb332fa195ca 307:906a5d289c6d
39 //####ECOSGPLCOPYRIGHTEND#### 39 //####ECOSGPLCOPYRIGHTEND####
40 //========================================================================== 40 //==========================================================================
41 //#####DESCRIPTIONBEGIN#### 41 //#####DESCRIPTIONBEGIN####
42 // 42 //
43 // Author(s): gthomas 43 // Author(s): gthomas
44 // Contributors: gthomas 44 // Contributors: gthomas, tkoeller
45 // Date: 2000-07-28 45 // Date: 2000-07-28
46 // Purpose: 46 // Purpose:
47 // Description: 47 // Description:
48 // 48 //
49 // This code is part of RedBoot (tm). 49 // This code is part of RedBoot (tm).
475 #endif 475 #endif
476 if (!scan_opts(argc, argv, 2, opts, i, 0, 0, "")) 476 if (!scan_opts(argc, argv, 2, opts, i, 0, 0, ""))
477 { 477 {
478 return; 478 return;
479 } 479 }
480 img = (struct fis_image_desc *)fis_work_block; 480 img = (struct fis_image_desc *) fis_addr;
481 // Let diag_printf do the formatting in both cases, rather than counting 481 // Let diag_printf do the formatting in both cases, rather than counting
482 // cols by hand.... 482 // cols by hand....
483 diag_printf("%-16s %-10s %-10s %-10s %-s\n", 483 diag_printf("%-16s %-10s %-10s %-10s %-s\n",
484 "Name","FLASH addr", 484 "Name","FLASH addr",
485 show_cksums ? "Checksum" : "Mem addr", 485 show_cksums ? "Checksum" : "Mem addr",
617 { 617 {
618 fis_usage("invalid arguments"); 618 fis_usage("invalid arguments");
619 return; 619 return;
620 } 620 }
621 621
622 memcpy(fis_work_block, fis_addr, fisdir_size);
622 defaults_assumed = false; 623 defaults_assumed = false;
623 if (name) { 624 if (name) {
624 // Search existing files to acquire defaults for params not specified: 625 // Search existing files to acquire defaults for params not specified:
625 img = fis_lookup(name, NULL); 626 img = fis_lookup(name, NULL);
626 if (img) { 627 if (img) {
817 #endif 818 #endif
818 #if 1 // And the descriptor for the descriptor table itself 819 #if 1 // And the descriptor for the descriptor table itself
819 num_reserved++; 820 num_reserved++;
820 #endif 821 #endif
821 822
823 memcpy(fis_work_block, fis_addr, fisdir_size);
822 img = fis_lookup(name, &i); 824 img = fis_lookup(name, &i);
823 if (img) { 825 if (img) {
824 if (i < num_reserved) { 826 if (i < num_reserved) {
825 diag_printf("Sorry, '%s' is a reserved image and cannot be deleted\n", img->name); 827 diag_printf("Sorry, '%s' is a reserved image and cannot be deleted\n", img->name);
826 return; 828 return;
872 if (!scan_opts(argc, argv, 2, opts, num_options, (void **)&name, OPTION_ARG_TYPE_STR, "image name")) 874 if (!scan_opts(argc, argv, 2, opts, num_options, (void **)&name, OPTION_ARG_TYPE_STR, "image name"))
873 { 875 {
874 fis_usage("invalid arguments"); 876 fis_usage("invalid arguments");
875 return; 877 return;
876 } 878 }
879 memcpy(fis_work_block, fis_addr, fisdir_size);
877 if ((img = fis_lookup(name, NULL)) == (struct fis_image_desc *)0) { 880 if ((img = fis_lookup(name, NULL)) == (struct fis_image_desc *)0) {
878 diag_printf("No image '%s' found\n", name); 881 diag_printf("No image '%s' found\n", name);
879 return; 882 return;
880 } 883 }
881 if (!mem_addr_set) { 884 if (!mem_addr_set) {
913 } 916 }
914 917
915 // Set load address/top 918 // Set load address/top
916 load_address = mem_addr; 919 load_address = mem_addr;
917 load_address_end = (unsigned long)p->out_buf; 920 load_address_end = (unsigned long)p->out_buf;
921
922 // Reload fis directory
923 memcpy(fis_work_block, fis_addr, fisdir_size);
918 } else // dangling block 924 } else // dangling block
919 #endif 925 #endif
920 { 926 {
921 memcpy((void *)mem_addr, (void *)img->flash_base, img->data_length); 927 memcpy((void *)mem_addr, (void *)img->flash_base, img->data_length);
922 928
1090 } 1096 }
1091 1097
1092 /* Get parameters from image if specified */ 1098 /* Get parameters from image if specified */
1093 if (name) { 1099 if (name) {
1094 struct fis_image_desc *img; 1100 struct fis_image_desc *img;
1101 memcpy(fis_work_block, fis_addr, fisdir_size);
1095 if ((img = fis_lookup(name, NULL)) == (struct fis_image_desc *)0) { 1102 if ((img = fis_lookup(name, NULL)) == (struct fis_image_desc *)0) {
1096 diag_printf("No image '%s' found\n", name); 1103 diag_printf("No image '%s' found\n", name);
1097 return; 1104 return;
1098 } 1105 }
1099 1106
1136 return; 1143 return;
1137 } 1144 }
1138 1145
1139 if (name) { 1146 if (name) {
1140 struct fis_image_desc *img; 1147 struct fis_image_desc *img;
1148 memcpy(fis_work_block, fis_addr, fisdir_size);
1141 if ((img = fis_lookup(name, NULL)) == (struct fis_image_desc *)0) { 1149 if ((img = fis_lookup(name, NULL)) == (struct fis_image_desc *)0) {
1142 diag_printf("No image '%s' found\n", name); 1150 diag_printf("No image '%s' found\n", name);
1143 return; 1151 return;
1144 } 1152 }
1145 1153
1188 // Keep 'end' address as last valid location, to avoid wrap around problems 1196 // Keep 'end' address as last valid location, to avoid wrap around problems
1189 flash_end = (void *)((CYG_ADDRESS)flash_end - 1); 1197 flash_end = (void *)((CYG_ADDRESS)flash_end - 1);
1190 flash_get_block_info(&flash_block_size, &flash_num_blocks); 1198 flash_get_block_info(&flash_block_size, &flash_num_blocks);
1191 workspace_end = (unsigned char *)(workspace_end-FLASH_MIN_WORKSPACE); 1199 workspace_end = (unsigned char *)(workspace_end-FLASH_MIN_WORKSPACE);
1192 #ifdef CYGOPT_REDBOOT_FIS 1200 #ifdef CYGOPT_REDBOOT_FIS
1201 # ifdef CYGOPT_REDBOOT_FIS_ZLIB_COMMON_BUFFER
1202 fis_work_block = fis_zlib_common_buffer;
1203 if(CYGNUM_REDBOOT_FIS_ZLIB_COMMON_BUFFER_SIZE < flash_block_size) {
1204 diag_printf("FLASH: common buffer too small\n");
1205 workspace_end += FLASH_MIN_WORKSPACE;
1206 return false;
1207 }
1208 # else
1193 workspace_end = (unsigned char *)(workspace_end-flash_block_size); 1209 workspace_end = (unsigned char *)(workspace_end-flash_block_size);
1194 fis_work_block = workspace_end; 1210 fis_work_block = workspace_end;
1211 # endif
1195 fisdir_size = flash_block_size; 1212 fisdir_size = flash_block_size;
1196 if (CYGNUM_REDBOOT_FIS_DIRECTORY_BLOCK < 0) { 1213 if (CYGNUM_REDBOOT_FIS_DIRECTORY_BLOCK < 0) {
1197 fis_addr = (void *)((CYG_ADDRESS)flash_end + 1 + 1214 fis_addr = (void *)((CYG_ADDRESS)flash_end + 1 +
1198 (CYGNUM_REDBOOT_FIS_DIRECTORY_BLOCK*flash_block_size)); 1215 (CYGNUM_REDBOOT_FIS_DIRECTORY_BLOCK*flash_block_size));
1199 } else { 1216 } else {
1228 } 1245 }
1229 if (!do_flash_init()) { 1246 if (!do_flash_init()) {
1230 diag_printf("Sorry, no FLASH memory is available\n"); 1247 diag_printf("Sorry, no FLASH memory is available\n");
1231 return; 1248 return;
1232 } 1249 }
1233 #ifdef CYGOPT_REDBOOT_FIS
1234 memcpy(fis_work_block, fis_addr, flash_block_size);
1235 #endif
1236 if ((cmd = cmd_search(__FIS_cmds_TAB__, &__FIS_cmds_TAB_END__, 1250 if ((cmd = cmd_search(__FIS_cmds_TAB__, &__FIS_cmds_TAB_END__,
1237 argv[1])) != (struct cmd *)0) { 1251 argv[1])) != (struct cmd *)0) {
1238 (cmd->fun)(argc, argv); 1252 (cmd->fun)(argc, argv);
1239 return; 1253 return;
1240 } 1254 }