为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

U-BOOT移植

2011-05-05 9页 pdf 58KB 67阅读

用户头像

is_051999

暂无简介

举报
U-BOOT移植 U-BOOT移植 (仅供参考) u-boot移植前的准备工作: 1 下载源码,建立工作目录 我们这里移植的是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 u-boot移植的具体步骤: 一 建立适合的 bo...
U-BOOT移植
U-BOOT移植 (仅供参考) u-boot移植前的准备工作: 1 下载源码,建立工作目录 我们这里移植的是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 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 #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移植完成! U-BOOT常用命令介绍 printenv 打印环境变量 setenv 设置环境变量 如:setenv ipaddr 192.168.1.168 setenv serverip 192.168.1.103 saveenv 保存设定的环境变量 我们经常要设置的环境变量有ipaddr,serverip,bootcmd,bootargs。 tftp 即将内核镜像文件从PC中下载到SDRAM的指定地址,然后通过bootm来引导内核,前提 是所用PC要安装设置tftp服务。 如: tftp 33000000 uImage 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
/
本文档为【U-BOOT移植】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索