U-boot移植完整版

來源:互聯網
上載者:User

u-boot移植前的準備工作:
1 下載源碼,建立工作目錄
Uboot的源碼可以從以下網址下載:http://downloads.sourceforge.net/u-boot/u-boot-1.1.4.tar.bz2?modtime=1134752480&big_mirror=0
我們這裡下載的是u-boot-1.1.4.tar.bz2
建立工作目錄:
mkdir /root/build_uboot
cd /root/build_uboot
把下載的源碼拷貝到該目錄,解壓;
tar jxvf u-boot-1.1.4.tar.bz2
mv u-boot-1.1.4 u-boot
2 確定分區:
u-boot移植的具體步驟:
一 建立適合的board平台
參照board/smdk2410目錄,我們在源碼的board下建立自己的自己的平台gec2410,步驟如下.
1 修改頂層Makefile
cd /root/build_uboot/u-boot
vi Makefile
找到:
smdk2410_config : unconfig
@./mkconfig $(@:_config=) arm arm920t smdk2410 NULL s3c24x0
在其後面添加:
gec2410_config : unconfig
@./mkconfig $(@:_config=) arm arm920t gec2410 NULL s3c24x0
各項的意思如下:
arm:        CPU的架構(ARCH)
arm920t:    CPU的類型(CPU),其對應於cpu/arm920t子目錄。
gec2410:    開發板的型號(BOARD),對應於board/gec2410目錄。
NULL:       開發人員/或經銷商(vender)。
s3c24x0:    片上系統(SOC)。
我把我的板子起名叫gec2410,可以依自己的喜好修改
2 建立board/gec2410目錄,拷貝board/smdk2410下的檔案到board/gec2410目錄,將smdk2410.c更名為gec2410.c
cp -r board/smdk2410 board/gec2410
3 修改board/gec2410/Makefile
將:
OBJS    := smdk2410.o flash.o
改為:
OBJS     := gec2410.o flash.o
4 cp include/configs/smdk2410.h include/configs/gec2410.h
5 修改cpu/arm920t/config.mk檔案
將:
PLATFORM_CPPFLAGS +=$(call cc-option,-mapcs-32,-mabi=apcs-gnu)
改為:
PLATFORM_CPPFLAGS +=$(call cc-option,-mapcs-32,$(call cc-option,-mabi=apcs-gnu),)
6 設定交叉編譯環境變數
export PATH=/usr/local/arm/2.95.3/bin:$PATH
7 測試編譯能否成功:
make gec2410_config
make all ARCH=arm
產生u-boot.bin就OK了
二 支援網路和 nand flash操作命令
1 添加網路命令
在include/configs/gec2410.h
只要在
#define CONFIG_COMMANDS
添加定義
                          CFG_CMD_NET
                          CFG_CMD_PING
就可以了
    說明:include/configs/gec2410.h檔案是與開發板相關的配置標頭檔。
2 支援nand flash啟動和讀寫
(1) 支援從nand flash 啟動
a 添加nandflash寄存器的定義
修改include/configs/gec2410.h檔案,添加如下內容:
***********************************************************************************************
/*
* Nandflash Boot
*/
#define CONFIG_S3C2410_NAND_BOOT 1
#define STACK_BASE    0x33f00000
#define STACK_SIZE    0x8000
#define UBOOT_RAM_BASE    0x33f80000
/* NAND Flash Controller */
#define NAND_CTL_BASE            0x4E000000
#define bINT_CTL(Nb)        __REG(INT_CTL_BASE + (Nb))
/* Offset */
#define oNFCONF               0x00
#define oNFCMD                0x04
#define oNFADDR               0x08
#define oNFDATA               0x0c
#define oNFSTAT               0x10
#define oNFECC                0x14
************************************************************************************************
b 在start.S加入搬運代碼
修改cpu/arm920t/start.S檔案
在ldr pc, _start_armboot之前加入:
************************************************************************************************
#ifdef CONFIG_S3C2410_NAND_BOOT
bl    copy_myself

@ jump to ram
ldr   r1, =on_the_ram
add pc, r1, #0
nop
nop
1:    b     1b          @ infinite loop
on_the_ram:
#endif
************************************************************************************************
在_start_armboot: .word start_armboot之後加入:
************************************************************************************************
#ifdef CONFIG_S3C2410_NAND_BOOT
copy_myself:
mov r10, lr
@ reset NAND
mov r1, #NAND_CTL_BASE
ldr   r2, =0xf830           @ initial value
str   r2, [r1, #oNFCONF]
ldr   r2, [r1, #oNFCONF]
bic r2, r2, #0x800              @ enable chip
str   r2, [r1, #oNFCONF]
mov r2, #0xff         @ RESET command
strb r2, [r1, #oNFCMD]
mov r3, #0                   @ wait
1:add r3, r3, #0x1
cmp r3, #0xa
blt   1b
2:ldr   r2, [r1, #oNFSTAT]      @ wait ready
tst    r2, #0x1
beq 2b
ldr   r2, [r1, #oNFCONF]
orr r2, r2, #0x800              @ disable chip
str   r2, [r1, #oNFCONF]
@ get read to call C functions (for nand_read())
ldr   sp, DW_STACK_START       @ setup stack pointer
mov fp, #0                    @ no previous frame, so fp=0
@ copy vivi to RAM
ldr   r0, =UBOOT_RAM_BASE
mov     r1, #0x0
mov r2, #0x20000
bl    nand_read_ll
tst    r0, #0x0
beq ok_nand_read
#ifdef CONFIG_DEBUG_LL
bad_nand_read:
ldr   r0, STR_FAIL
ldr   r1, SerBase
bl    PrintWord
1:b     1b          @ infinite loop
#endif
ok_nand_read:
#ifdef CONFIG_DEBUG_LL
ldr   r0, STR_OK
ldr   r1, SerBase
bl    PrintWord
#endif
@ verify
mov r0, #0
ldr   r1, =UBOOT_RAM_BASE
mov r2, #0x400     @ 4 bytes * 1024 = 4K-bytes
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:
#ifdef CONFIG_DEBUG_LL
sub r0, r0, #4
ldr   r1, SerBase
bl    PrintHexWord
ldr   r0, STR_FAIL
ldr   r1, SerBase
bl    PrintWord
#endif
1:b     1b
done_nand_read:
#ifdef CONFIG_DEBUG_LL
ldr   r0, STR_OK
ldr   r1, SerBase
bl    PrintWord
#endif
mov pc, r10
@ clear memory
@ r0: start address
@ r1: length
mem_clear:
mov r2, #0
mov r3, r2
mov r4, r2
mov r5, r2
mov r6, r2
mov r7, r2
mov r8, r2
mov r9, r2
clear_loop:
stmia      r0!, {r2-r9}
subs r1, r1, #(8 * 4)
bne clear_loop
mov pc, lr
#endif @ CONFIG_S3C2410_NAND_BOOT
************************************************************************************************
在檔案的最後加入如下,堆棧地址:
*************************************************************************************************
   .align     2
DW_STACK_START:
.word      STACK_BASE+STACK_SIZE-4
*************************************************************************************************
c 添加nand_read_ll函數的實現
在board/gec2410/建立nand_read.c,加入如下內容(copy from vivi):
*************************************************************************************************
#include <config.h>
#define __REGb(x) (*(volatile unsigned char *)(x))
#define __REGi(x) (*(volatile unsigned int *)(x))
#define NF_BASE 0x4e000000
#define NFCONF __REGi(NF_BASE + 0x0)
#define NFCMD __REGb(NF_BASE + 0x4)
#define NFADDR __REGb(NF_BASE + 0x8)
#define NFDATA __REGb(NF_BASE + 0xc)
#define NFSTAT __REGb(NF_BASE + 0x10)
#define BUSY 1
inline void wait_idle(void) {
    int i;
    while(!(NFSTAT & BUSY))
      for(i=0; i<10; i++);
}
#define NAND_SECTOR_SIZE 512
#define NAND_BLOCK_MASK (NAND_SECTOR_SIZE - 1)
/* low level nand read function */
int
nand_read_ll(unsigned char *buf, unsigned long start_addr, int size)
{
    int i, j;
    if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {
        return -1; /* invalid alignment */
    }
    /* chip Enable */
    NFCONF &= ~0x800;
    for(i=0; i<10; i++);
     for(i=start_addr; i < (start_addr + size);) {
      /* READ0 */
      NFCMD = 0;
       /* Write Address */
      NFADDR = i & 0xff;
      NFADDR = (i >> 9) & 0xff;
      NFADDR = (i >> 17) & 0xff;
      NFADDR = (i >> 25) & 0xff;
       wait_idle();
       for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {
*buf = (NFDATA & 0xff);
buf++;
      }
    }
     /* chip Disable */
    NFCONF |= 0x800; /* chip disable */
    return 0;
}
************************************************************************************************
修改board/gec2410/Makefile為
OBJS := gec2410.o flash.o nand_read.o
以上步驟就可以把u-boot燒寫到nandflash上了
2) 支援nand flash操作命令
a 在/include/configs/gec2410.h檔案中添加宏定義
#define CONFIG_COMMANDS
添加定義
                          CFG_CMD_NAND
                        CFG_CMD_ENV        

b 定義環境變數宏
#define CFG_ENV_IS_IN_FLASH 1
#define CFG_ENV_SIZE               0x10000 /* Total Size of Environment Sector */
改為
#define CFG_ENV_IS_IN_NAND        1
#define CFG_ENV_OFFSET             0x030000
#define CFG_NAND_BASE    0x4E000000
#define CMD_SAVEENV
#define CFG_NAND_LEGACY
#define CFG_ENV_SIZE               0x10000 /* Total Size of Environment Sector */                       
/*set env*/
#define CFG_MONITOR_BASE PHYS_SDRAM_1
c 修改common/cmd_nand.c檔案,添加nand flash初始化函數
添加
**************************************************************************************************
#define rNFCONF (*(volatile unsigned *)0x4E000000)
#define rNFCMD (*(volatile unsigned *)0x4E000004)
#define rNFADDR (*(volatile unsigned *)0x4E000008)
#define rNFDATA (*(volatile unsigned *)0x4E00000C)
#define rNFSTAT (*(volatile unsigned *)0x4E000010)
#define rNFECC (*(volatile unsigned *)0x4E000014)
#define CFG_NAND_BASE    0x4E000000
#define CFG_MAX_NAND_DEVICE 1 /* Max number of NAND devices */
#define SECTORSIZE 512
#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 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 WRITE_NAND_COMMAND(d , adr) {rNFCMD=d;}
#define WRITE_NAND_ADDRESS(d, adr) {rNFADDR=d;}
#define WRITE_NAND(d , adr) {rNFDATA=d;}
#define READ_NAND(adr)         (rNFDATA)
/* the following functions are NOP's because S3C24X0 handles this in hardware */
#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
********************************************************************************************************
添加nand_init()函數的實現
*******************************************************************************************************
void nand_init(void)
{
         int i;
         unsigned long j;
         rNFCONF=(1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(0<<8)|(3<<4)|(0<<0);
        
         rNFCONF=rNFCONF&~(1<<11);
         rNFCMD=0xff;
                
         for(i=0;i<10;i++);
         while(!(rNFSTAT&(1<<0)));
        
         rNFCONF=rNFCONF|(1<<11);
         j=nand_probe(0x4e000000);
         printf("nand flash : %4lu MB\n",j>>20);
}
********************************************************************************************************
d 在nand_probe函數中添加一行
********************************************************************************************************
#endif
         oob_config.badblock_pos = 5;
        nand_dev_desc[0].ChipID = 0x00;
********************************************************************************************************
uboot移植完成!
配置編譯
export PATH=/usr/local/arm/2.95.3/bin:$PATH
make gec2410_config
make ARCH=arm all
u-boot的測試
把u-boot燒寫到nand flash上
啟動資訊:
*************************************************************
U-Boot 1.1.4 (Feb 10 2007 - 23:56:56)               
                                                    
U-Boot code: 33F80000 -> 33F9C5D0 BSS: -> 33FA06B8
RAM Configuration:
Bank #0: 30000000 64 MB
Flash: 512 kB
nand flash :   64 MB
In:    serial
Out:   serial
Err:   serial
GEC2410#
**************************************************************
tftp 30008000 zImage
go 300080000
出現錯誤,因為go命令的實現函數不完整。
下面完善go命令的實現函數do_go()
三 完善do_go函數
gedit common/cmd_boot.c
添加
/*添加call_linux函數*/
********************************************************************************
void call_linux(long a0, long a1, long a2)
{  
__asm__(
             "   mov r1, #0\n"
             "   mov r1, #7 << 5\n"        /* 8 segments */
             "1: orr r3, r1, #63 << 26\n"      /* 64 entries */
             "2: mcr p15, 0, r3, c7, c14, 2\n" /* clean & invalidate D index */
             "   subs    r3, r3, #1 << 26\n"
             "   bcs 2b\n"             /* entries 64 to 0 */
             "   subs    r1, r1, #1 << 5\n"
             "   bcs 1b\n"             /* segments 7 to 0 */
             "   mcr p15, 0, r1, c7, c5, 0\n" /* invalidate I cache */
             "   mcr p15, 0, r1, c7, c10, 4\n" /* drain WB */
);
__asm__(
"mov    r0, #0\n"
"mcr    p15, 0, r0, c7, c10, 4\n"   /* drain WB */
"mcr    p15, 0, r0, c8, c7, 0\n"    /* invalidate I & D TLBs */
);
__asm__(
"mov    r0, %0\n"
"mov    r1, #0x0c1\n"
"mov    r2, %2\n"
"mov    ip, #0\n"
"mcr    p15, 0, ip, c13, c0, 0\n"   /* zero PID */
"mcr    p15, 0, ip, c7, c7, 0\n"    /* invalidate I,D caches */
"mcr    p15, 0, ip, c7, c10, 4\n"   /* drain write buffer */
"mcr    p15, 0, ip, c8, c7, 0\n"    /* invalidate I,D TLBs */
"mrc    p15, 0, ip, c1, c0, 0\n"    /* get control register */
"bic    ip, ip, #0x0001\n"      /* disable MMU */
"mcr    p15, 0, ip, c1, c0, 0\n"    /* write control register */
"mov    pc, r2\n"
"nop\n"
"nop\n"
: /* no outpus */
: "r" (a0), "r" (a1), "r" (a2)
);
}
****************************************************************************
添加setup_linux_param函數
****************************************************************************
static void setup_linux_param(ulong param_base)
{  
struct param_struct *params = (struct param_struct *)param_base;
char *linux_cmd;

//linux_cmd = "noinitrd root=/dev/mtdblock/2 init=/linuxrc console=ttyS0";
linux_cmd = getenv("bootargs");
memset(params, 0, sizeof(struct param_struct));

params->u1.s.page_size = 0x00001000;
params->u1.s.nr_pages = (0x04000000 >> 12);
/* set linux command line */
memcpy(params->commandline, linux_cmd, strlen(linux_cmd) + 1);
}
****************************************************************************
在do_go()函數中添加
****************************************************************************
printf ("## Starting application at 0x%08lX ...\n", addr);
         setup_linux_param(0x30000100);
         call_linux(0,0x0c1,0x30008000);
         printf("ok\n");
****************************************************************************
3重新編譯u-boot
make all ARCH=arm
通過jtag將u-boot燒寫到flash中就可以從NAND flash啟動了
U-BOOT常用命令介紹
printenv   列印環境變數
setenv     設定環境變數
如:setenv ipaddr 172.22.60.44
      Setenv serverip 172.22.60.88
saveenv        儲存設定的環境變數
我們經常要設定的環境變數有ipaddr,serverip,bootcmd,bootargs。
tftp       即將核心鏡像檔案從PC中下載到SDRAM的指定地址,然後通過bootm來引導核心,前提是所用PC要安裝設定tftp服務。
如: tftp 30008000 zImage
nand erase 擦除nand flash中資料
如:nand erase 0x40000 0x1c0000
               起始地址 大小
nand write 把RAM中的資料寫到Nand Flash中
如:nand write 0x30008000 0x40000 0x1c0000
nand read   從nand flash中讀取資料到RAM
如:nand read 0x30008000 0x40000 0x1c0000
go          直接跳轉到可執行檔的入口地址,執行可執行檔。
下載並燒寫核心如下
1 用網線串連開發板和PC機
2 啟動U-BOOT並設定環境變數
setenv ipaddr 172.22.60.32 //設定開發板的IP
setenv serverip 172.22.60.99 //設定PC機的IP
setenv ethaddr 11.22.33.44.55.66 //設定開發板的物理地址
saveenv //儲存
3 在PC機端開啟TFTP伺服器,並且把要下載的檔案拷貝到tftp伺服器程式所在的目錄下
4 下載和燒寫
在u-boot下用以下命令
    tftp 30008000 zImage
nand erase 40000 1c0000
nand write 30008000 40000 1c0000

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.