Esempio n. 1
0
int flash_init(struct spi_flash_ctrl *ctrl, struct blocklevel_device **bl,
		struct flash_chip **flash_chip)
{
	struct flash_chip *c;
	int rc;

	if (!bl)
		return FLASH_ERR_PARM_ERROR;

	*bl = NULL;

	c = malloc(sizeof(struct flash_chip));
	if (!c)
		return FLASH_ERR_MALLOC_FAILED;
	memset(c, 0, sizeof(*c));
	c->ctrl = ctrl;

	rc = flash_identify(c);
	if (rc) {
		FL_ERR("LIBFLASH: Flash identification failed\n");
		goto bail;
	}
	c->smart_buf = malloc(c->min_erase_mask + 1);
	if (!c->smart_buf) {
		FL_ERR("LIBFLASH: Failed to allocate smart buffer !\n");
		rc = FLASH_ERR_MALLOC_FAILED;
		goto bail;
	}
	rc = flash_configure(c);
	if (rc)
		FL_ERR("LIBFLASH: Flash configuration failed\n");
bail:
	if (rc) {
		free(c);
		return rc;
	}

	/* The flash backend doesn't support reiniting it */
	c->bl.keep_alive = true;
	c->bl.reacquire = NULL;
	c->bl.release = NULL;
	c->bl.read = &flash_read;
	c->bl.write = &flash_smart_write;
	c->bl.erase = &flash_erase;
	c->bl.get_info = &flash_get_info;
	c->bl.erase_mask = c->min_erase_mask;
	c->bl.flags = WRITE_NEED_ERASE;

	*bl = &(c->bl);
	if (flash_chip)
		*flash_chip = c;

	return 0;
}
Esempio n. 2
0
unsigned long flash_init(void)
{
	unsigned long addr;
	unsigned int i;

	flash_info[0].size = CFG_FLASH_SIZE;
	flash_info[0].sector_count = 135;

	flash_identify(uncached((void *)CFG_FLASH_BASE), &flash_info[0]);

	for (i = 0, addr = 0; i < 8; i++, addr += 0x2000)
		flash_info[0].start[i] = addr;
	for (; i < flash_info[0].sector_count; i++, addr += 0x10000)
		flash_info[0].start[i] = addr;

	return CFG_FLASH_SIZE;
}
/*!
 * \brief   Kinetis Start
 * \return  None
 *
 * This function calls all of the needed starup routines and then 
 * branches to the main process.
 */
void start(void)
{
	/* Disable the watchdog timer */
	wdog_disable();

	/* Copy any vector or data sections that need to be in RAM */
	common_startup();

	/* Perform processor initialization */
	sysinit();
        
    /* Determine the flash revision */
    flash_identify();    

	/* Jump to main process */
	main();

	/* No actions to perform after this so wait forever */
	while(1);
}
/*!
 * \brief   Kinetis Identify
 * \return  None
 *
 * This is primarly a reporting function that displays information
 * about the specific CPU to the default terminal including:
 * - Kinetis family
 * - package
 * - die revision
 * - P-flash size
 * - Ram size
 */
void cpu_identify (void)
{
    /* Determine the Kinetis family */
    switch((SIM_SDID & SIM_SDID_FAMID(0x7))>>SIM_SDID_FAMID_SHIFT) 
    {  
    	case 0x0:
    		printf("\nK10-");
    		break;
    	case 0x1:
    		printf("\nK20-");
    		break;
    	case 0x2:
    		printf("\nK30-");
    		break;
    	case 0x3:
    		printf("\nK40-");
    		break;
    	case 0x4:
    		printf("\nK60-");
    		break;
    	case 0x5:
    		printf("\nK70-");
    		break;
    	case 0x6:
    		printf("\nK50-");
    		break;
    	case 0x7:
    		printf("\nK53-");
    		break;
	default:
		printf("\nUnrecognized Kinetis family device.\n");  
		break;  	
    }

    /* Determine the package size */
    switch((SIM_SDID & SIM_SDID_PINID(0xF))>>SIM_SDID_PINID_SHIFT) 
    {  
    	case 0x2:
    		printf("32pin       \n");
    		break;
    	case 0x4:
    		printf("48pin       \n");
    		break;
    	case 0x5:
    		printf("64pin       \n");
    		break;
    	case 0x6:
    		printf("80pin       \n");
    		break;
    	case 0x7:
    		printf("81pin       \n");
    		break;
    	case 0x8:
    		printf("100pin      \n");
    		break;
    	case 0x9:
    		printf("104pin      \n");
    		break;
    	case 0xA:
    		printf("144pin      \n");
    		break;
    	case 0xC:
    		printf("196pin      \n");
    		break;
    	case 0xE:
    		printf("256pin      \n");
    		break;
	default:
		printf("\nUnrecognized Kinetis package code.      \n");  
		break;  	
    }                

    /* Determine the revision ID */
    
    switch((SIM_SDID & SIM_SDID_REVID(0xF))>>SIM_SDID_REVID_SHIFT) 
    { 
   
    case 0x0:
    		printf("Silicon rev 1.0   \n ");
    		break;
    case 0x1:
    		printf("Silicon rev 1.1  \n ");
    		break;
    case 0x2:
    		printf("Silicon rev 1.2  \n ");
    		break;
    default:
		printf("\nThis version of software doesn't recognize the revision code.");  
		break;  
    }
    
    /* Determine the flash revision */
    flash_identify();  
    
    
    /* Determine the P-flash size */
    switch((SIM_FCFG1 & SIM_FCFG1_PFSIZE(0xF))>>SIM_FCFG1_PFSIZE_SHIFT)
    {
    	case 0x7:
    		printf("128 kBytes of P-flash	\n");
    		break;
    	case 0x9:
    		printf("256 kBytes of P-flash	\n");
    		break;
        case 0xB:
    		printf("512 kBytes of P-flash	\n");
    		break;
    	case 0xF:
    		printf("512 kBytes of P-flash	\n");
    		break;
	default:
		printf("ERR!! Undefined P-flash size\n");  
		break;  		
    }
    
    /* Determine if the part has P-flash only or P-flash and FlexNVM */
    if (SIM_FCFG2 & SIM_FCFG2_PFLSH_MASK)  
      printf("P-flash only\n");
    else
      /* if part has FlexNVM determine the FlexNVM size*/
      switch((SIM_FCFG1 & SIM_FCFG1_NVMSIZE(0xF))>>SIM_FCFG1_NVMSIZE_SHIFT)
      {
      	case 0x0:
      		printf("0 kBytes of FlexNVM\n");
      		break;
    	case 0x7:
      		printf("128 kBytes of FlexNVM\n");
    		break;
        case 0x9:
      		printf("256 kBytes of FlexNVM\n");
    		break;
    	case 0xF:
      		printf("256 kBytes of FlexNVM\n");
    		break;
	default:
		printf("ERR!! Undefined FlexNVM size\n");  
		break;  		
      }
      

    /* Determine the RAM size */
    switch((SIM_SOPT1 & SIM_SOPT1_RAMSIZE(0xF))>>SIM_SOPT1_RAMSIZE_SHIFT)
    {
    	case 0x5:
    		printf("32 kBytes of RAM\n\n");
    		break;
    	case 0x7:
    		printf("64 kBytes of RAM\n\n");
    		break;
    	case 0x8:
    		printf("96 kBytes of RAM\n\n");
    		break;
    	case 0x9:
    		printf("128 kBytes of RAM\n\n");
    		break;
		default:
			printf("ERR!! Undefined RAM size\n\n");  
			break;  		
    }

}
Esempio n. 5
0
/*!
 * \brief   Kinetis Identify
 * \return  None
 *
 * This is primarly a reporting function that displays information
 * about the specific CPU to the default terminal including:
 * - Kinetis family
 * - package
 * - die revision
 * - P-flash size
 * - Ram size
 */
void cpu_identify (void)
{
    /* Determine the Kinetis family */
    switch((SIM_SDID & SIM_SDID_FAMID(0x7))>>SIM_SDID_FAMID_SHIFT) 
    {  
    	case 0x0:
    		printf("\nK10-");
    		break;
    	case 0x1:
    		//printf("\nK20-");
    		break;
    	case 0x2:
    		printf("\nK30-");
    		break;
    	case 0x3:
    		printf("\nK40-");
    		break;
    	case 0x4:
    		printf("\nK60-");
    		break;
    	case 0x5:
    		printf("\nK70-");
    		break;
    	case 0x6:
    		printf("\nK50 and K52-");
    		break;
    	case 0x7:
    		printf("\nK51 and K53-");
    		break;

	default:
		printf("\nUnrecognized Kinetis family device.\n");  
		break;  	
    }

    /* Determine the package size */
    switch((SIM_SDID & SIM_SDID_PINID(0xF))>>SIM_SDID_PINID_SHIFT) 
    {  
    		break;
    	case 0x6:
    		//printf("80pin       ");
    		break;
    	case 0x7:
    		printf("81pin       ");
    		break;
    	case 0x8:
    		printf("100pin      ");
    		break;
    	case 0x9:
    		printf("121pin      ");
    		break;
    	case 0xA:
    		printf("144pin      ");
    		break;
	default:
		printf("\nUnrecognized Kinetis package code.      ");  
		break;  	
    }                

    /* Determine the revision ID */

 switch((SIM_SDID & SIM_SDID_REVID(0xF))>>SIM_SDID_REVID_SHIFT) 
    { 
   
    case 0x0:
    		printf("Silicon rev 1.0   \n ");
    		break;
    default:
		//printf("\nThis version of software doesn't recognize the revision code.");  
		break;  
    }
    
    /* Determine the flash revision */
    flash_identify();    
    
    /* Determine the P-flash size */
  switch((SIM_FCFG1 & SIM_FCFG1_PFSIZE(0xF))>>SIM_FCFG1_PFSIZE_SHIFT)
    {
  	case 0x7:
    		printf("128 kBytes of P-flash	");
    		break;
    	case 0x9:
    		//printf("256 kBytes of P-flash	");
    		break;
        case 0xB:
    		printf("512 kBytes of P-flash	");
    		break;
    	case 0xF:
    		printf("512 kBytes of P-flash	");
    		break;
	default:
		printf("ERR!! Undefined P-flash size\n");  
		break;  	  		
    }

    /* Determine the RAM size */
    switch((SIM_SOPT1 & SIM_SOPT1_RAMSIZE(0xF))>>SIM_SOPT1_RAMSIZE_SHIFT)
    {
    	case 0x5:
    		printf(" 32 kBytes of RAM\n\n");
    		break;
    	case 0x7:
    		printf(" 64 kBytes of RAM\n\n");
    		break;
    	case 0x8:
    		printf(" 96 kBytes of RAM\n\n");
    		break;
    	case 0x9:
    		//printf(" 128 kBytes of RAM\n\n");
    		break;
		default:
			printf(" ERR!! Undefined RAM size\n\n");  
			break;  		
    }
}
Esempio n. 6
0
/*!
 * \brief   Kinetis Identify
 * \return  None
 *
 * This is primarly a reporting function that displays information
 * about the specific CPU to the default terminal including:
 * - Kinetis family
 * - package
 * - die revision
 * - P-flash size
 * - Ram size
 */
void cpu_identify (void)
{
    /* Determine the Kinetis family */
    switch((SIM_SDID & SIM_SDID_FAMID(0x7))>>SIM_SDID_FAMID_SHIFT) 
    {  
    	case 0x0:
    		printf("\nK10-");
    		break;
    	case 0x1:
    		printf("\nK20-");
    		break;
    	case 0x2:
    		printf("\nK30-");
    		break;
    	case 0x3:
    		printf("\nK40-");
    		break;
    	case 0x4:
    		printf("\nK60-");
    		break;
    	case 0x5:
    		printf("\nK70-");
    		break;
    	case 0x6:
    		printf("\nK50-");
    		break;
    	case 0x7:
    		printf("\nK53-");
    		break;
	default:
		printf("\nUnrecognized Kinetis family device.\n");  
		break;  	
    }

    /* Determine the package size */
    switch((SIM_SDID & SIM_SDID_PINID(0xF))>>SIM_SDID_PINID_SHIFT) 
    {  
    	case 0x2:
    		printf("32pin       ");
    		break;
    	case 0x4:
    		printf("48pin       ");
    		break;
    	case 0x5:
    		printf("64pin       ");
    		break;
    	case 0x6:
    		printf("80pin       ");
    		break;
    	case 0x7:
    		printf("81pin       ");
    		break;
    	case 0x8:
    		printf("100pin      ");
    		break;
    	case 0x9:
    		printf("104pin      ");
    		break;
    	case 0xA:
    		printf("144pin      ");
    		break;
    	case 0xC:
    		printf("196pin      ");
    		break;
    	case 0xE:
    		printf("256pin      ");
    		break;
	default:
		printf("\nUnrecognized Kinetis package code.      ");  
		break;  	
    }                

    /* Determine the revision ID */
    printf("Silicon rev %d     \n", (SIM_SDID & SIM_SDID_REVID(0xF))>>SIM_SDID_REVID_SHIFT);
    
    
    /* Determine the flash revision */
    flash_identify();    
    
    /* Determine the P-flash size */
    switch((SIM_FCFG1 & SIM_FCFG1_FSIZE(0xFF))>>SIM_FCFG1_FSIZE_SHIFT)
    {
    	case 0x0:
    		printf("12 kBytes of P-flash	");
    		break;
    	case 0x1:
    		printf("16 kBytes of P-flash	");
    		break;
    	case 0x2:
    		printf("32 kBytes of P-flash	");
    		break;
    	case 0x3:
    		printf("48 kBytes of P-flash	");
    		break;
    	case 0x4:
    		printf("64 kBytes of P-flash	");
    		break;
    	case 0x5:
    		printf("96 kBytes of P-flash	");
    		break;
    	case 0x6:
    		printf("128 kBytes of P-flash	");
    		break;
    	case 0x7:
    		printf("192 kBytes of P-flash	");
    		break;
    	case 0x8:
    		printf("256 kBytes of P-flash	");
    		break;
    	case 0x9:
    		printf("320 kBytes of P-flash	");
    		break;
    	case 0xA:
    		printf("384 kBytes of P-flash	");
    		break;
    	case 0xB:
    		printf("448 kBytes of P-flash	");
    		break;
    	case 0xC:
    		printf("512 kBytes of P-flash	");
    		break;
    	case 0xFF:
    		printf("Full size P-flash	");
    		break;
		default:
			printf("ERR!! Undefined P-flash size\n");  
			break;  		
    }

    /* Determine the RAM size */
    switch((SIM_SOPT1 & SIM_SOPT1_RAMSIZE(0xF))>>SIM_SOPT1_RAMSIZE_SHIFT)
    {
    	case 0x5:
    		printf(" 32 kBytes of RAM\n\n");
    		break;
    	case 0x7:
    		printf(" 64 kBytes of RAM\n\n");
    		break;
    	case 0x8:
    		printf(" 96 kBytes of RAM\n\n");
    		break;
    	case 0x9:
    		printf(" 128 kBytes of RAM\n\n");
    		break;
		default:
			printf(" ERR!! Undefined RAM size\n\n");  
			break;  		
    }
}