Esempio n. 1
0
void fisInitialize(void)
{
	do_flash_init(); //hack, put the init here.
#ifdef _CLI
	fisInstallCLITools();
#endif 
}
Esempio n. 2
0
// Wrapper to avoid compiler warnings
static void
_do_flash_init(void)
{
    static int init_done = 0;
    if (init_done) return;
    init_done = 1;
    do_flash_init();
}
Esempio n. 3
0
static void
do_fis(int argc, char *argv[])
{
    struct cmd *cmd;

    if (argc < 2) {
        fis_usage("too few arguments");
        return;
    }
    if (!do_flash_init()) {
        diag_printf("Sorry, no FLASH memory is available\n");
        return;
    }
    if ((cmd = cmd_search(__FIS_cmds_TAB__, &__FIS_cmds_TAB_END__, 
                          argv[1])) != (struct cmd *)0) {
        (cmd->fun)(argc, argv);
        return;
    }
    fis_usage("unrecognized command");
}
Esempio n. 4
0
static int
flash_fis_op2( int op, unsigned int index, struct fis_table_entry *entry)
{
   int res=0;
   CYGARC_HAL_SAVE_GP();
   switch ( op ) {
      case CYGNUM_CALL_IF_FLASH_FIS_GET_VERSION:
         res=CYG_REDBOOT_FIS_VERSION;
         break;
      case CYGNUM_CALL_IF_FLASH_FIS_INIT:
         __flash_init=0;  //force reinitialization
         res=do_flash_init();
         break;
      case CYGNUM_CALL_IF_FLASH_FIS_GET_ENTRY_COUNT:
         res=fisdir_size / sizeof(struct fis_image_desc);
         break;
      case CYGNUM_CALL_IF_FLASH_FIS_GET_ENTRY:
         {
            struct fis_image_desc* img = (struct fis_image_desc *)fis_work_block;
            CYG_ASSERT(entry!=0, "fis_table_entry == 0 !");
            memcpy(entry->name, img[index].u.name, 16);
            entry->flash_base=img[index].flash_base;
            entry->mem_base=img[index].mem_base;
            entry->size=img[index].size;
            entry->entry_point=img[index].entry_point;
            entry->data_length=img[index].data_length;
            entry->desc_cksum=img[index].desc_cksum;
            entry->file_cksum=img[index].file_cksum;
            res=0;
         }
         break;
      case CYGNUM_CALL_IF_FLASH_FIS_START_UPDATE:
         fis_start_update_directory(1);
         break;
      case CYGNUM_CALL_IF_FLASH_FIS_FINISH_UPDATE:
         fis_update_directory(1, index);
         break;
      case CYGNUM_CALL_IF_FLASH_FIS_MODIFY_ENTRY:
         {
            res=0;
            if (entry->name[0]!=0xff)
            {
               if ((entry->size==0)
                   || ((entry->size % flash_block_size) !=0)
                   || (flash_verify_addr((void*)entry->flash_base)!=0)
                   || (flash_verify_addr((void*)(entry->flash_base+entry->size-1))!=0)
                   || (entry->size < entry->data_length))
                  res=-1;
            }

            if (res==0)
            {
               struct fis_image_desc* img = (struct fis_image_desc *)fis_work_block;
               memcpy(img[index].u.name, entry->name, 16);
               img[index].flash_base=entry->flash_base;
               img[index].mem_base=entry->mem_base;
               img[index].size=entry->size;
               img[index].entry_point=entry->entry_point;
               img[index].data_length=entry->data_length;
               img[index].desc_cksum=entry->desc_cksum;
               img[index].file_cksum=entry->file_cksum;
            }
         }
         break;
      default:
         break;
   }
   CYGARC_HAL_RESTORE_GP();
   return res;
}
Esempio n. 5
0
//
// Attempt to get configuration information from the FLASH.
// If available (i.e. good checksum, etc), initialize "known"
// values for later use.
//
static void
load_flash_config(void)
{
    bool use_boot_script;
    unsigned char *cfg_temp = (unsigned char *)workspace_end;
#ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
    void *err_addr;
#endif

    config_ok = false;
    script = (unsigned char *)0;
    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
    backup_config = (struct _config *)cfg_temp;
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK
    cfg_temp -= sizeof(struct _config);  // Space for readonly copy of config data
    readonly_config = (struct _config *)cfg_temp;
#endif
    workspace_end = cfg_temp;
#ifdef CYGHWR_REDBOOT_FLASH_CONFIG_MEDIA_FLASH
    if (!do_flash_init()) 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 *
                                  CYGNUM_REDBOOT_FIS_DIRECTORY_ENTRY_SIZE)) {
        // Too bad this can't be checked at compile/build time
        diag_printf("Sorry, FLASH config exceeds available space in FIS directory\n");
        return;
    }
    cfg_base = (void *)(((CYG_ADDRESS)fis_addr + fisdir_size) - cfg_size);
    fisdir_size -= cfg_size;
#else
    cfg_size = (flash_block_size > sizeof(struct _config)) ? 
        sizeof(struct _config) : 
        _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));
    } else {
        cfg_base = (void *)((CYG_ADDRESS)flash_start + 
           _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);
    conf_endian_fixup(config);
#else
    read_eeprom(config, sizeof(struct _config));  // into 'config'
#endif
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG_READONLY_FALLBACK
    memcpy(readonly_config, config, sizeof(struct _config));
#endif
    if ((flash_crc(config) != config->cksum) ||
        (config->key1 != CONFIG_KEY1)|| (config->key2 != CONFIG_KEY2)) {
        diag_printf("**Warning** FLASH configuration checksum error or invalid key\n");
        diag_printf("Use 'fconfig -i' to [re]initialize database\n");
        config_init();
        return;
    }
    config_ok = true;
    flash_get_config("boot_script", &use_boot_script, CONFIG_BOOL);
    if (use_boot_script) {
        flash_get_config("boot_script_data", &script, CONFIG_SCRIPT);
        flash_get_config("boot_script_timeout", &script_timeout, CONFIG_INT);
    }
#ifdef CYGSEM_REDBOOT_VARIABLE_BAUD_RATE
    if (flash_get_config("console_baud_rate", &console_baud_rate, CONFIG_INT)) {
        extern int set_console_baud_rate(int);
        set_console_baud_rate(console_baud_rate);
    }
#endif
}