手把手教你移植u-boot(目標平臺S3C2410)

Vincent_Song發表於2011-09-24
U-Boot(Universal Boot Loader)是德國DENX小組開發的用於多種嵌入式CPU的BootLoader程式,它可以執行於PowerPC、ARM、MIPS等多種嵌入式開發板上。

u-boot目錄的原始碼結構如下:

board:開發板相關目錄。

common:通用的命令函式。

cpu:特定CPU架構相關目錄,如arm920t。

doc:uboot的開發、使用文件。

drivers:uboot支援的裝置驅動程式,比如串列埠,nandflash,網路卡。

fs: 支援的檔案系統,Uboot現在支援cramfs、fat、fdos、jffs2和registerfs。

include:標頭檔案和開發板配置檔案,configs目錄下是開發板的配置檔案

lib_xxxx: 與體系結構相關的庫檔案。如與ARM相關的庫放在lib_arm中。

lib_generic:通用的庫函式。

net:各種網路協議,TFTP協議、NFS協議等。

tools:uboot自帶的工具。

下面我們就針對S3C2410平臺u-boot的移植步驟做一下簡單介紹:

1、首先下載u-boot的原始碼包,然後解壓,進入原始碼包目錄。

2、修改原始碼讓u-boot支援從Nand Flash啟動。

具體如下:

一、修改“u-boot-1.3.2/cpu/arm920t/start.S”檔案,執行以下命令:

#gedit cpu/arm920t/start.S

(1)181行和201行前加上//,註釋掉

181 //#ifdef  CONFIG_AT91RM9200

201 //#endif

(2)#ifndef CONFIG_SKIP_RELOCATE_UBOOT之後加入:

#ifdef CONFIG_S3C2410_NAND_BOOT

bl   copy_myself

#else

(3)“ble    copy_loop”語句之後加入:

#endif

(4)“_start_armboot: .word start_armboot”語句之後加入copy_loop子程式:

/*

*************************************************************************

*

* copy u-boot  to ram

*

*************************************************************************

*/

#ifdef CONFIG_S3C2410_NAND_BOOT

copy_myself:

mov         r10, lr                         @save return address to r10

ldr                  sp, DW_STACK_START

mov         fp, #0

bl           NF_Init

ldr           r0, =UBOOT_RAM_BASE

mov         r1, #0x0

mov         r2, #0x30000

bl           nand_read_whole

tst            r0, #0x0

beq         ok_nand_read

1:        b            1b

ok_nand_read:

mov         r0, #0x00000000

ldr           r1, =UBOOT_RAM_BASE

mov         r2, #0x400

go_next:

ldr           r3, [r0], #4

ldr           r4, [r1], #4

teq          r3, r4

bne          notmatch

subs         r2, r2, #4

beq         done_nand_read

bne          go_next

notmatch:

1:        b            1b

done_nand_read:

    mov        pc, r10

#endif

DW_STACK_START:

    .word   STACK_BASE+STACK_SIZE-4

二、新建“u-boot-1.3.2/ board/smdk2410/nand.c”檔案

執行命令:

#gedit board/up2410/nand.c

在開啟的檔案裡新增如下內容:

#include <common.h>

#include <s3c2410.h>

#include <config.h>

 

#define TACLS   0

#define TWRPH0  3

#define TWRPH1  0

#define U32 unsigned int

extern unsigned long nand_probe(unsigned long physadr);

 

static void NF_Reset(void)

{

int i;

NF_nFCE_L();

NF_CMD(0xFF);

for(i=0;i<10;i++);

NF_WAITRB();

NF_nFCE_H();

}

void NF_Init(void)

{

rNFCONF=(1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0);

NF_Reset();

}

 

int nand_read_whole(unsigned char *buf, unsigned long start_addr, int size)

{

int i, j;

if((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK))

return 1;

NF_nFCE_L();

for(i=0; i<10; i++);

i = start_addr;

while(i < start_addr + size) {

rNFCMD = 0;

rNFADDR = i & 0xff;

rNFADDR = (i >> 9) & 0xff;

rNFADDR = (i >> 17) & 0xff;

rNFADDR = (i >> 25) & 0xff;

NF_WAITRB();

     

for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {

*buf = (rNFDATA & 0xff);

buf++;

}

}

NF_nFCE_H();

return 0;

}

三、修改“u-boot-1.3.2/board/smdk2410/Makefile”檔案

執行命令:

#gedit board/smdk2410/Makefile

將“COBJS:= smdk2410.o flash.o”改為“COBJS:=smdk2410.o flash.o nand.o”

四、修改“u-boot-1.3.2/include/configs/smdk2410.h”檔案

執行命令:

#gedit include/configs/smdk2410.h

在檔案的最後一個#endif的前面新增如下內容:

#define CONFIG_S3C2410_NAND_BOOT 1

#define STACK_BASE      0x33f00000

#define STACK_SIZE      0x8000

#define UBOOT_RAM_BASE  0x33f80000

#define CFG_NAND_BASE 0x4E000000

#define CFG_MAX_NAND_DEVICE 1

#define SECTORSIZE 512

#define NAND_SECTOR_SIZE SECTORSIZE

#define NAND_BLOCK_MASK (NAND_SECTOR_SIZE - 1)

#define ADDR_COLUMN 1

#define ADDR_PAGE 2

#define ADDR_COLUMN_PAGE 3

#define NAND_ChipID_UNKNOWN 0x00

#define NAND_MAX_FLOORS 1

#define NAND_MAX_CHIPS 1

 

#define WRITE_NAND_COMMAND(d, adr) do {rNFCMD = d;} while(0)

#define WRITE_NAND_ADDRESS(d, adr) do {rNFADDR = d;} while(0)

#define WRITE_NAND(d, adr) do {rNFDATA = d;} while(0)

#define READ_NAND(adr) (rNFDATA)

#define NAND_WAIT_READY(nand) {while(!(rNFSTAT&(1<<0)));}

#define NAND_DISABLE_CE(nand) {rNFCONF |= (1<<11);}

#define NAND_ENABLE_CE(nand) {rNFCONF &= ~(1<<11);}

 

#define NAND_CTL_CLRALE(nandptr)

#define NAND_CTL_SETALE(nandptr)

#define NAND_CTL_CLRCLE(nandptr)

#define NAND_CTL_SETCLE(nandptr)

 

#define CONFIG_MTD_NAND_VERIFY_WRITE 1

 

#define rNFCONF (*(volatile unsigned int *)0x4e000000)

#define rNFCMD (*(volatile unsigned char *)0x4e000004)

#define rNFADDR (*(volatile unsigned char *)0x4e000008)

#define rNFDATA (*(volatile unsigned char *)0x4e00000c)

#define rNFSTAT (*(volatile unsigned int *)0x4e000010)

#define rNFECC (*(volatile unsigned int *)0x4e000014)

#define rNFECC0 (*(volatile unsigned char *)0x4e000014)

#define rNFECC1 (*(volatile unsigned char *)0x4e000015)

#define rNFECC2 (*(volatile unsigned char *)0x4e000016)

 

#define NF_CMD(cmd) {rNFCMD=cmd;}

#define NF_ADDR(addr) {rNFADDR=addr;}

#define NF_nFCE_L() {rNFCONF&=~(1<<11);}

#define NF_nFCE_H() {rNFCONF|=(1<<11);}

#define NF_RSTECC() {rNFCONF|=(1<<12);}

#define NF_RDDATA() (rNFDATA)

#define NF_WRDATA(data) {rNFDATA=data;}

#define NF_WAITRB() {while(!(rNFSTAT&(1<<0)));}

3、使u-boot支援dm9000網路卡

步驟如下:

一、將dm9000x.h和dm9000x.c兩個檔案拷貝到drivers/net/下。

二、2.  修改“u-boot-1.3.2/include/configs/smdk2410.h”檔案

執行命令:

#gedit include/configs/smdk2410.h

(1)將原網路卡“CS8900”改為“DM9000”

(2)新增網路命令

(3)修改IP地址

(4)修改命令提示符

(5)修改預設下載地址

(6)修改環境變數在Nand Flash中的儲存地址

具體如下:

(1)將原網路卡“CS8900”改為“DM9000”

註釋掉:

// #define CONFIG_DRIVER_CS8900    1       /* we have a CS8900 on-board */

// #define CS8900_BASE             0x19000300

// #define CS8900_BUS16            1 /* the Linux driver does accesses as shorts */

這3行之後新增:

#define CONFIG_DRIVER_DM9000  1

#define CONFIG_DRIVER_DM9000_BASE 0x10000000

#define DM9000_IO CONFIG_DM9000_BASE

#define DM9000_DATA (DM9000_IO + 2)

#define CONFIG_DM9000_USE_16BIT

(2)新增網路命令

找到下面的幾行:

#define CONFIG_CMD_CACHE

#define CONFIG_CMD_DATE

#define CONFIG_CMD_ELF

      在其下面新增下面幾行:

#define CONFIG_CMD_REGINFO

#define CONFIG_CMD_NAND

#define CONFIG_CMD_PING

#define CONFIG_CMD_DLF

#define CONFIG_CMD_ENV

#define CONFIG_CMD_NET

(3)修改IP地址

找到下面幾行:

#define CONFIG_BOOTDELAY        3

/*#define CONFIG_BOOTARGS       "root=ramfs devfs=mount console=ttySA0,9600" */

/*#define CONFIG_ETHADDR        08:00:3e:26:0a:5b */

#define CONFIG_NETMASK          255.255.255.0

#define CONFIG_IPADDR           10.0.0.110

#define CONFIG_SERVERIP         10.0.0.1

/*#define CONFIG_BOOTFILE       "elinos-lart" */

/*#define CONFIG_BOOTCOMMAND    "tftp; bootm" */

修改為:

#define CONFIG_BOOTDELAY   3

#define CONFIG_BOOTARGS "root=/dev/mtdblock3 init=/linuxrc console=ttySAC0,115200"

#define CONFIG_ETHADDR 08:00:3e:26:0a:5b

#define CONFIG_NETMASK       255.255.255.0

#define CONFIG_IPADDR            192.168.1.13  

#define CONFIG_SERVERIP 192.168.1.12  

#define CONFIG_BOOTFILE       "uImage"

#define CONFIG_BOOTCOMMAND "tftp; bootm"

#define CONFIG_CMDLINE_TAG      1

#define CONFIG_SETUP_MEMORY_TAGS    1

#define CONFIG_INITRD_TAG    1

(4)修改命令提示符

找到下面一行:

#define CFG_PROMPT      "SMDK2410 # "  

修改為:

#define CFG_PROMPT      "[ smdk2410 #]"

(5)修改預設下載地址

找到下面一行:

#define CFG_LOAD_ADDR           0x33000000     

修改為:

#define CFG_LOAD_ADDR           0x30008000

#define CFG_TFTP_LOAD_ADDR      0x30008000

(6)修改環境變數在Nand Flash中的儲存地址

找到下面兩行:

#define CFG_ENV_IS_IN_FLASH      1

#define CFG_ENV_SIZE               0x10000

修改為:

#define CFG_ENV_IS_IN_NAND       1

#define CFG_ENV_SIZE               0x4000

#define CFG_ENV_OFFSET  (0x80000-0x4000)

4、編譯生成u-boot

依次執行以下命令:

#make smdk2410_config

#make

編譯完成之後就生成了u-boot.bin檔案,這個檔案就是我們要燒寫到開發板上的檔案。

相關文章