⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 burn.c

📁 思创S3C44B0黄金开发板一个简化版本的BOOTLOADER
💻 C
字号:
/****************************************************************************/
//
// FLASH burnning routine
// Created by Strong Embeded Studio
//         www.8800.org
// If there are any concerns on the code
// go to www.8800.org for discussion
//
/****************************************************************************/
#include "common.h"

//
// ************* OPTIONS **************
// #define MCLK (66000000)
//

#define MCLKM (66)              
#define PLLP  (3)

#define MCLK  (MCLKM * 1000000)
#define PLLON 1
#define PLLS  1
#define PLLM  ((MCLKM*2*(PLLP+2)/10)-8)

// 20,40,50,60,66,75
//         (PLL_M+8)*Fin      (PLL_M+8)*10Mhz
// MCLK=------------------- = ----------------
//      (PLL_P+2)*(2^PLL_S)        4*2


#define             WRBUFOPT (0x8)   //write_buf_on

#define SYSCFG_0KB  (0x0|WRBUFOPT)
#define SYSCFG_4KB  (0x2|WRBUFOPT)
#define SYSCFG_8KB  (0x6|WRBUFOPT)


#define CACHECFG    SYSCFG_8KB

#define Non_Cache_Start   (0x2000000)                          
#define Non_Cache_End     (0xc000000)                          
#define Non_Cache_Start1  (0x2000000)                          
#define Non_Cache_End1    (0xc000000)                          
#define Non_Cache_Start2  (0x2000000)                          
#define Non_Cache_End2    (0xc000000)                          

extern unsigned int GetIndex(unsigned int offset);
extern unsigned int WriteSector(int index,char *data_buffer);
extern char  *      SetFlashBase(uint base);


int Burn(void)
{
  char c;
  unsigned int len,wlen,slen;
  unsigned int index, offset;

  //
  // Define the temporary buffer base for burnning flash
  //
  char *buf = (char *)(0x0C600000);
  
  //
  // Clear serial port buffer
  //
  while (GetKey(0));
  
  //
  // Display the menu
  //
  c = 0;
  while (c<1 || c>8) {
    OutPut(0,"\n1. Burn boot loader\n");
    OutPut(0,  "2. Burn linux core\n");
    OutPut(0,  "3. Burn linux romfs\n");
    OutPut(0,  "4. Burn recovery stub\n");
    OutPut(0,  "5. Burn arm bios\n");
    OutPut(0,  "6. Burn strong test\n");
    OutPut(0,  "7. Burn user program\n");
    OutPut(0,  "8. Return\n");
    OutPut(0,  "Please choose:");
    
    do {
      c = GetKey(0);
    } while (!c) ;
    
    OutPut(0,"%c\n\n",c);
    c -= '0';
  }
  
  OutPut(0,"Ready for burning Flash...\n");
  
  switch(c) {
    case 1: //Shell
      offset = 0x000000;
      len    = 0x020000;
      break;
    case 2: //Linux Core
      offset = 0x020000;
      len    = 0x0D0000;
      break;
    case 3: //Linux ROMFS
      offset = 0x120000;
      len    = 0x0C0000;
      break;
    case 4: //Shell recovery
      offset = 0x100000;
      len    = 0x010000;
      break;
    case 5: //ArmBios
      offset = 0x110000;
      len    = 0x010000;
      break;
    case 6: //Test
      offset = 0x0F0000;
      len    = 0x010000;
      break;
    case 7: //User prog
      offset = 0x1E0000;
      len    = 0x020000;
      break;
    default:
      OutPut(0, "Burnning Aborted!\n\n");
      return 1; 
  }
  
  
  //
  // Get the sector index from the offset
  //

  FlashNonCache(1);

  OutPut(0,"Flash Type: %s\nFlash Base: %08X\n",SetFlashBase(0),0);
  
  index = GetIndex(offset);

  if (index==(uint)-1) {
    FlashNonCache(0); 
    OutPut(0,"Flash programming aborted!\n\n");
    return 0;
  }

  //
  // Burn the flash
  //
  slen = 0;
  wlen = 0;
  while (1) {
    OutPut(0,"Burning Flash sector %02d... ", index); 
    slen = WriteSector(index,buf);
    if (slen!=0) OutPut(0,"OK!\n");
    else {
      OutPut(0,"BAD!\n");
      break; 
    }
    wlen += slen;
    if (wlen >= len) break;
    buf += slen;
    index ++;
  }

  FlashNonCache(0);

  OutPut(0,"Finished programming!\n\n");
  OutPut(0,"Please reset your system!\n\n");

  return 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -