Mercurial > ecos
comparison packages/redboot/current/src/flash.c @ 172:cd45958b28ff
Merge from eCos master repository on 2001-07-20-10:24:43-BST
| author | jlarmour |
|---|---|
| date | Fri, 20 Jul 2001 10:23:16 +0000 |
| parents | 42f843b391aa |
| children | 38892b97b685 |
comparison
equal
deleted
inserted
replaced
| 171:42f843b391aa | 172:cd45958b28ff |
|---|---|
| 144 | 144 |
| 145 // Local data used by these routines | 145 // Local data used by these routines |
| 146 static void *flash_start, *flash_end; | 146 static void *flash_start, *flash_end; |
| 147 static int block_size, blocks; | 147 static int block_size, blocks; |
| 148 static void *fis_work_block; | 148 static void *fis_work_block; |
| 149 static int fisdir_size; // Size of FIS directory. Note: zero if FIS not enabled | |
| 150 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG | |
| 151 static void *cfg_base; // Location in Flash of config data | |
| 152 static int cfg_size; // Length of config data - rounded to Flash block size | |
| 153 #endif | |
| 149 | 154 |
| 150 static void | 155 static void |
| 151 fis_usage(char *why) | 156 fis_usage(char *why) |
| 152 { | 157 { |
| 153 printf("*** invalid 'fis' command: %s\n", why); | 158 printf("*** invalid 'fis' command: %s\n", why); |
| 177 fis_init(int argc, char *argv[]) | 182 fis_init(int argc, char *argv[]) |
| 178 { | 183 { |
| 179 int stat; | 184 int stat; |
| 180 struct fis_image_desc *img; | 185 struct fis_image_desc *img; |
| 181 void *fis_base, *err_addr; | 186 void *fis_base, *err_addr; |
| 182 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG | |
| 183 void *cfg_base; | |
| 184 #endif | |
| 185 bool full_init = false; | 187 bool full_init = false; |
| 186 struct option_info opts[1]; | 188 struct option_info opts[1]; |
| 187 unsigned long redboot_image_size, redboot_flash_start; | 189 unsigned long redboot_image_size, redboot_flash_start; |
| 188 | 190 |
| 189 init_opts(&opts[0], 'f', false, OPTION_ARG_TYPE_FLG, | 191 init_opts(&opts[0], 'f', false, OPTION_ARG_TYPE_FLG, |
| 247 #endif | 249 #endif |
| 248 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG | 250 #ifdef CYGSEM_REDBOOT_FLASH_CONFIG |
| 249 // And a descriptor for the configuration data | 251 // And a descriptor for the configuration data |
| 250 memset(img, 0, sizeof(*img)); | 252 memset(img, 0, sizeof(*img)); |
| 251 strcpy(img->name, "RedBoot config"); | 253 strcpy(img->name, "RedBoot config"); |
| 252 cfg_base = (void *)((unsigned long)flash_end - (2*block_size)); | |
| 253 img->flash_base = (unsigned long)cfg_base; | 254 img->flash_base = (unsigned long)cfg_base; |
| 254 img->mem_base = (unsigned long)cfg_base; | 255 img->mem_base = (unsigned long)cfg_base; |
| 255 img->size = block_size; | 256 img->size = cfg_size; |
| 256 img++; | 257 img++; |
| 257 #endif | 258 #endif |
| 258 // And a descriptor for the descriptor table itself | 259 // And a descriptor for the descriptor table itself |
| 259 memset(img, 0, sizeof(*img)); | 260 memset(img, 0, sizeof(*img)); |
| 260 strcpy(img->name, "FIS directory"); | 261 strcpy(img->name, "FIS directory"); |
| 1028 } | 1029 } |
| 1029 flash_get_limits((void *)0, (void **)&flash_start, (void **)&flash_end); | 1030 flash_get_limits((void *)0, (void **)&flash_start, (void **)&flash_end); |
| 1030 flash_get_block_info(&block_size, &blocks); | 1031 flash_get_block_info(&block_size, &blocks); |
| 1031 fis_work_block = (unsigned char *)(workspace_end-FLASH_MIN_WORKSPACE-block_size); | 1032 fis_work_block = (unsigned char *)(workspace_end-FLASH_MIN_WORKSPACE-block_size); |
| 1032 workspace_end = fis_work_block; | 1033 workspace_end = fis_work_block; |
| 1033 _flash_info(); | 1034 fisdir_size = block_size; |
| 1034 } | 1035 } |
| 1035 return true; | 1036 return true; |
| 1036 } | 1037 } |
| 1038 | |
| 1039 #ifndef CYGOPT_REDBOOT_FLASH_CONFIG | |
| 1040 RedBoot_init(do_flash_init, RedBoot_INIT_FIRST); | |
| 1041 #endif | |
| 1037 | 1042 |
| 1038 static void | 1043 static void |
| 1039 do_fis(int argc, char *argv[]) | 1044 do_fis(int argc, char *argv[]) |
| 1040 { | 1045 { |
| 1041 struct cmd *cmd; | 1046 struct cmd *cmd; |
| 1605 // | 1610 // |
| 1606 void | 1611 void |
| 1607 flash_write_config(void) | 1612 flash_write_config(void) |
| 1608 { | 1613 { |
| 1609 int stat; | 1614 int stat; |
| 1610 void *cfg_base, *err_addr; | 1615 void *err_addr; |
| 1611 | 1616 |
| 1612 config.len = sizeof(config); | 1617 config.len = sizeof(config); |
| 1613 config.key1 = CONFIG_KEY1; | 1618 config.key1 = CONFIG_KEY1; |
| 1614 config.key2 = CONFIG_KEY2; | 1619 config.key2 = CONFIG_KEY2; |
| 1615 config.cksum = crc32((unsigned char *)&config, sizeof(config)-sizeof(config.cksum)); | 1620 config.cksum = crc32((unsigned char *)&config, sizeof(config)-sizeof(config.cksum)); |
| 1616 cfg_base = (void *)((unsigned long)flash_end - (2*block_size)); | |
| 1617 if (verify_action("Update RedBoot non-volatile configuration")) { | 1621 if (verify_action("Update RedBoot non-volatile configuration")) { |
| 1618 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL | 1622 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL |
| 1619 // Insure [quietly] that the config page is unlocked before trying to update | 1623 // Insure [quietly] that the config page is unlocked before trying to update |
| 1620 flash_unlock((void *)cfg_base, block_size, (void **)&err_addr); | 1624 flash_unlock((void *)cfg_base, cfg_size, (void **)&err_addr); |
| 1621 #endif | 1625 #endif |
| 1622 if ((stat = flash_erase(cfg_base, block_size, (void **)&err_addr)) != 0) { | 1626 if ((stat = flash_erase(cfg_base, cfg_size, (void **)&err_addr)) != 0) { |
| 1623 printf(" initialization failed %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); | 1627 printf(" initialization failed %p: 0x%x(%s)\n", err_addr, stat, flash_errmsg(stat)); |
| 1624 } else { | 1628 } else { |
| 1625 if ((stat = flash_program(cfg_base, (void *)&config, | 1629 if ((stat = flash_program(cfg_base, (void *)&config, |
| 1626 sizeof(config), (void **)&err_addr)) != 0) { | 1630 sizeof(config), (void **)&err_addr)) != 0) { |
| 1627 printf("Error writing config data at %p: 0x%x(%s)\n", | 1631 printf("Error writing config data at %p: 0x%x(%s)\n", |
| 1628 err_addr, stat, flash_errmsg(stat)); | 1632 err_addr, stat, flash_errmsg(stat)); |
| 1629 } | 1633 } |
| 1630 } | 1634 } |
| 1631 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL | 1635 #ifdef CYGSEM_REDBOOT_FLASH_LOCK_SPECIAL |
| 1632 // Insure [quietly] that the config data is locked after the update | 1636 // Insure [quietly] that the config data is locked after the update |
| 1633 flash_lock((void *)cfg_base, block_size, (void **)&err_addr); | 1637 flash_lock((void *)cfg_base, cfg_size, (void **)&err_addr); |
| 1634 #endif | 1638 #endif |
| 1635 } | 1639 } |
| 1636 } | 1640 } |
| 1637 | 1641 |
| 1638 // | 1642 // |
| 1822 // values for later use. | 1826 // values for later use. |
| 1823 // | 1827 // |
| 1824 static void | 1828 static void |
| 1825 load_flash_config(void) | 1829 load_flash_config(void) |
| 1826 { | 1830 { |
| 1827 void *cfg_base; | |
| 1828 bool use_boot_script; | 1831 bool use_boot_script; |
| 1829 | 1832 |
| 1830 config_ok = false; | 1833 config_ok = false; |
| 1831 script = (unsigned char *)0; | 1834 script = (unsigned char *)0; |
| 1832 if (!do_flash_init()) return; | 1835 if (!do_flash_init()) return; |
| 1833 cfg_base = (void *)((unsigned long)flash_end - (2*block_size)); | 1836 #define _roundup(n,s) ((((n)+(s-1))/s)*s) |
| 1837 cfg_size = (block_size > sizeof(config)) ? sizeof(config) : | |
| 1838 _roundup(sizeof(config), block_size); | |
| 1839 cfg_base = (void *)((unsigned long)flash_end - (cfg_size+fisdir_size)); | |
| 1834 memcpy(&config, cfg_base, sizeof(config)); | 1840 memcpy(&config, cfg_base, sizeof(config)); |
| 1835 if ((crc32((unsigned char *)&config, sizeof(config)-sizeof(config.cksum)) != config.cksum) || | 1841 if ((crc32((unsigned char *)&config, sizeof(config)-sizeof(config.cksum)) != config.cksum) || |
| 1836 (config.key1 != CONFIG_KEY1)|| (config.key2 != CONFIG_KEY2)) { | 1842 (config.key1 != CONFIG_KEY1)|| (config.key2 != CONFIG_KEY2)) { |
| 1837 printf("FLASH configuration checksum error or invalid key\n"); | 1843 printf("FLASH configuration checksum error or invalid key\n"); |
| 1838 config_init(); | 1844 config_init(); |
