예제 #1
0
파일: main.c 프로젝트: bigcmel/dummygit
WORD load_user_app_to_initd( BYTE* app_name, BYTE* app_binary_base, WORD app_binary_length )
{
  WORD status; // 函数执行情况
  WORD i;

  WORD app_idx;

  WORD block;
  WORD page;
  WORD page_num;
  BYTE* buffer;
  
  WORD nf_blocknum;
  WORD nf_pagepblock;
  WORD nf_mainsize;
  WORD nf_sparesize;


  /* 先注册 initd 的进程表 */

  app_binary_base = 0x00000000;
  app_binary_length = 1024;

  app_idx = initd_register_app(app_name, app_binary_base, app_binary_length);


  /* 这里要切换一下上下文,切换到 app_idx 对应的代码断去 */
  
  MMU_SwitchContext( app_idx );

  
  /* 向 sys_mm 申请需要的内存空间 */

  if( ! sys_mm_apply_sdram(app_idx, (WORD)app_binary_base, app_binary_length) )
    return RETURN_FAILED;


  /* 调用系统调用( SWI 中断),将代码从 SDRAM 读到内存中 */
  
  NF_GetBlockPageInfo(&nf_blocknum, &nf_pagepblock, &nf_mainsize, &nf_sparesize);

  block = 5;
  page = 0;
  page_num = ((INITD_TABLE[app_idx].binary_length - 1) / nf_mainsize) + 1;
  buffer = INITD_TABLE[app_idx].binary_base;

  for(i=0; i<page_num; i++)
    {
      status = NF_WritePage( block, page, buffer );
      page++;
      buffer += nf_mainsize;
      
      if(page == 32)
	{
	  block++;
	  page = 0;
	}
    }

  return RETURN_SUCCESS;
}
예제 #2
0
파일: k9s1208.c 프로젝트: TLARP/research
void K9S1208_Program(void)
{
    int i;
    int programError=0;
    U32 blockIndex;
    int noLoad=0;
    U8 spareBuf[16]=
	{0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
    U8 *srcPt;
    U32 progSize=0;

    printf("\n[SMC(K9S1208V0M) NAND Flash Writing Program]\n");
    
    printf("\nSource size:0h~%xh\n",imageSize-1);
    printf("\nAvailable target block number: 0~4095\n");
    printf("Input target block number:");
    scanf("%d",&targetBlock);
    targetSize=((imageSize+0x4000-1)/0x4000)*0x4000;
    printf("target start block number     =%d\n",targetBlock);
    printf("target size        (0x4000*n) =0x%x\n",targetSize);
    printf("STATUS:");
    blockIndex=targetBlock;
    while(1)
    {
	static j = 0;
	if(noLoad==0)
	{
	    LoadImageFile(blockBuf,0x4000);
	}
	noLoad=0;
	
#if BAD_CHECK       
	if(NF_IsBadBlock(blockIndex) && blockIndex!=0 )	// 1:bad 0:good
        {
	    blockIndex++;   // for next block
	    noLoad=1;
	    continue;
	}
#endif
	if(!NF_EraseBlock(blockIndex))
	{
	    blockIndex++;   // for next block
	    noLoad=1;
	    continue;
	}

	printf("\n");
	srcPt=blockBuf;

	for(i=0;i<32;i++)
	{
	    if(!NF_WritePage(blockIndex,i,srcPt,NULL/*spareBuf*/))// block num, page num, buffer
	    {
	        programError=1;
	        break;
	    }

	    srcPt+=512;	// Increase buffer addr one pase size
	    printf("\rE:(%d/%d)",32*j+i,32 * targetSize / 0x4000);
	    fflush(stdout); 
	}
	j++;
	printf("\n");

        if(programError==1)
	{
	    blockIndex++;
	    noLoad=1;
	    programError=0;
	    continue;
	}
	progSize+=0x4000;
	if(progSize>=imageSize)
	    break;	// Exit while loop
	blockIndex++;
    }
}