失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > linux 移植 内存 配置 Linux 移植篇 之 uboot的移植

linux 移植 内存 配置 Linux 移植篇 之 uboot的移植

时间:2019-09-25 11:01:33

相关推荐

linux 移植 内存 配置 Linux 移植篇 之 uboot的移植

本文主要针对对于s3c2410的板子

一、在 U-Boot 中建立自己的开发板类型,并测试编译

(1)进入 UBoot 根目录,修改 Makefile

<1>为 james2410_config 建立编译选项,可以自己定义名字。

smdk2410_config : unconfig

@$(MKCONFIG) $(@:_config=) arm arm920t smdk2410 samsung

s3c24x0

james2410_config : unconfig

@$(MKCONFIG) $(@:_config=) arm arm920t james2410 samsung

s3c24x0

<2>指定交叉编译工具

在代码

ifeq ($(HOSTARCH),$(ARCH))

CROSS_COMPILE ?=

endif

前面添加代码

CROSS_COMPILE= /usr/local/arm/crosstool-ng/crosstool_out/bin/armlinux-<3>修改如下

__LIBS := $(subst $(obj),,$(LIBS)) $(subst $(obj),,$(LIBBOARD))

修改为

__LIBS := $(subst $(obj),,$(LIBBOARD)) $(subst $(obj),,$(LIBS))

(2)建立自己的开发板目录

<1>建立开发板目录

# cd board/samsung/

# cp smdk2410/ james2410 -fr

# cd james2410/

# mv smdk2410.c james2410.c

<2>修改 james2410 目录下的 Makefile,如下:

COBJS := james2410.o flash.o

SOBJS := lowlevel_init.o

<3>建立自己开发板的头文件

进入 u-boot 源码的根目录

# cp include/configs/smdk2410.h include/configs/james2410.h

(3)测试编译能否成功

<1>进入 u-boot 源码的根目录

<2>#make james2410_config,出现如下语句,正常。

<3>#make

<4>若不报错且生成 u-boot.bin 文件,说明基本配置成功。

二、内存配置,从 NAND FLASH 搬运 UBOOT 到内存中

(1)修改文件 config.mk

<1># vim board/samsung/james2410/config.mk

<2>TEXT_BASE = 0x33F80000

改为

TEXT_BASE = 0x31F80000

(2)修改文件/arch/arm/cpu/arm920t/start.S

注释掉 set the cpu to SVC32 mode 后面的语句

//bl coloured_LED_init

//bl red_LED_on

在代码

# define INTSUBMSK 0x4A00001C

# define CLKDIVN 0x4C000014 /* clock divisor register */

下面添加代码:

# define CLK_CTL_BASE 0x4C000000

# define MDIV_200 0xa1 << 12

# define PSDIV_200 0x31

在代码

/* FCLK:HCLK:PCLK = 1:2:4 */

/* default FCLK is 120 MHz ! */

ldr r0, =CLKDIVN

mov r1, #3

str r1, [r0]

下面添加代码:

用于设置时钟频率(202.8MHz)

mrc p15, 0, r1, c1, c0, 0

orr r1, r1, #0xc0000000

mcr p15, 0, r1, c1, c0, 0 /*write ctrl register */

mov r1, #CLK_CTL_BASE

mov r2, #MDIV_200

add r2, r2, #PSDIV_200

str r2, [r1, #0x04]

修改:

# if defined(CONFIG_S3C2410)

ldr r1, =0x3ff

# if defined(CONFIG_S3C2410)

ldr r1, =0x7ff

(3)进入内存配置阶段

修改/board/samsung/james2410/lowlevel_init.S

<1>修改代码

#define B1_BWSCON (DW32)

#define B2_BWSCON (DW16)

#define B3_BWSCON (DW16 + WAIT + UBLB)

#define B4_BWSCON (DW16)

#define B5_BWSCON (DW16)

#define B6_BWSCON (DW32)

#define B7_BWSCON (DW32)

#define B1_BWSCON (DW16)

#define B2_BWSCON (DW32)

#define B3_BWSCON (DW16)

#define B4_BWSCON (DW16)

#define B5_BWSCON (DW16)

#define B6_BWSCON (DW16)

#define B7_BWSCON (DW16)

<2>修改刷新律

#define REFCNT 1268 /* period=7.8125us, HCLK=100Mhz,

(2048+1-7.8125*100) */

<3>寻找如下部分并做修改

.word ((REFEN<<23)+(TREFMD<<22)+(Trp<<20)+(Trc<<18)+

(Tchr<<16)+REFCNT)

.word 0x32

.word 0x30

.word 0x30

修改 word 0x32 为 word 0xb2

<4>修改如下部分

#define B3_Tacs 0x0 /* 0clk */

#define B3_Tcos 0x3 /* 4clk */

#define B3_Tacc 0x7 /* 14clk */

#define B3_Tcoh 0x1 /* 1clk */

#define B3_Tah 0x0 /* 0clk */

#define B3_Tacp 0x3 /* 6clk */

#define B3_PMC 0x0 /* normal */

为:

#define B3_Tacs 0x0 /* 0clk */

#define B3_Tcos 0x0 /* 4clk */

#define B3_Tacc 0x7 /* 14clk */

#define B3_Tcoh 0x0 /* 1clk */

#define B3_Tah 0x0 /* 0clk */

#define B3_Tacp 0x0 /* 6clk */

#define B3_PMC 0x0 /* normal */

(4)修改文件/arch/arm/cpu/arm920t/start.S

<1>如下注释掉以前的搬运代码

#if 0

#ifndef CONFIG_SKIP_RELOCATE_UBOOT

relocate: /* relocate U-Boot to RAM */

adr r0, _start /* r0

ldr r1, _TEXT_BASE /* test if we run from flash or RAM */

cmp r0, r1 /* don't reloc during debug */

beq stack_setup

ldr r2, _armboot_start

ldr r3, _bss_start

sub r2, r3, r2 /* r2

add r2, r0, r2 /* r2

copy_loop:

ldmia r0!, {r3-r10} /* copy from source address [r0] */

stmia r1!, {r3-r10} /* copy to target address [r1] */

cmp r0, r2 /* until source end addreee [r2] */

ble copy_loop

#endif /* CONFIG_SKIP_RELOCATE_UBOOT */

#endif

紧接着添加如下代码:

/*copy U-Boot to RAM*/

#define LENGTH_UBOOT 0x40000

#define NAND_CTL_BASE 0x4E000000

#ifdef CONFIG_S3C2410

/* Offset */

#define oNFCONF 0x00

#define oNFCMD 0x04

#define oNFSTAT 0x10

@ 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

nand1:

add r3, r3, #0x1

cmp r3, #0xa

blt nand1

nand2:

ldr r2, [r1, #oNFSTAT] @ wait ready

tst r2, #0x1

beq nand2

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 U-Boot to RAM

ldr r0, =TEXT_BASE

mov r1, #0x0

mov r2, #LENGTH_UBOOT

bl nand_read_ll

tst r0, #0x0

beq ok_nand_read

bad_nand_read:

loop2:

b loop2 @ infinite loop

ok_nand_read:

@ verify

mov r0, #0

ldr r1, =TEXT_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 stack_setup

bne go_next

notmatch:

loop3:

b loop3 @ infinite loop

#endif

<2>在代码

_start_armboot: .word start_armboot

下面添加:

#define STACK_BASE 0x31f00000

#define STACK_SIZE 0x8000

.align 2

DW_STACK_START: .word STACK_BASE+STACK_SIZE-4

STACK_BASE 的设置,与上面 TEXT_BASE 的设置原因相同

(5)修改/include/configs/james2410.h 文件

/* nand boot */

#define CONFIG_S3C2410 1

修改下面宏定义的常量值

#define CONFIG_SYS_MEMTEST_END 0x31F00000 /* 31 MB in DRAM */

#define CONFIG_SYS_LOAD_ADDR 0x30008000 /* default load address */

#define PHYS_SDRAM_1_SIZE 0x02000000 /* 32 MB */

(6)在/board/samsung/james2410 路径下建立 nand_read.c,供 start.S 调用。文件

内容如下:

#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)

#if defined(CONFIG_S3C2410)

#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

#define NAND_SECTOR_SIZE 512

#define NAND_BLOCK_MASK (NAND_SECTOR_SIZE - 1)

inline void wait_idle(void) {

int i;

while(!(NFSTAT & BUSY))

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

}

/* 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); i += NAND_SECTOR_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++) {

*buf = (NFDATA & 0xff);

buf++;

}

}

/* chip Disable */

NFCONF |= 0x800; /* chip disable */

return 0;

}

#endif

(7)修改/board/samsung/james2410/Makefile

COBJS := my2410.o flash.o nand_read.o

(8)修改/board/samsung/james2410/james2410.c

在 board_init()函数中

<1>修改下面的配置

gpio->GPFCON = 0x000051AA;

gpio->GPFUP = 0x000000EF;

gpio->GPGCON = 0xFD95FFBA;

gpio->GPGUP = 0x0000EFFF;

gpio->GPHCON = 0x0016FAAA;

<2>在上面配置下添加代码:

gpio->EXTINT0=0x22222222;

gpio->EXTINT1=0x22222222;

gpio->EXTINT2=0x22222222;

三、去掉 Nor Flash 部分

(1)修改/include/configs/james2410.h

注释 CONFIG_AMD_LV400

#if 0

#define CONFIG_AMD_LV400 1 /* uncomment this if you have a LV400

flash */

#define CONFIG_AMD_LV800 1 /* uncomment this if you have a LV800

flash */

#endif

去掉:

//#define CONFIG_ENV_IS_IN_FLASH 1

//#define CONFIG_ENV_SIZE 0x10000 /* Total Size of Environment

Sector */

添加:

#define CONFIG_SYS_NO_FLASH 1

#define CONFIG_ENV_IS_IN_NAND 1

#define CONFIG_ENV_OFFSET 0X60000

#define CONFIG_ENV_SIZE 0x20000 /* Total Size of Environment

Sector */

(2)修改/board/samsung/james2410/Makefile

COBJS := my2410.o nand_read.o

(3)修改/common/cmd_bootm.c 的部分内容如下:

注释掉下面代码块:

#if 0

#if defined(CONFIG_CMD_IMLS)

#include

extern flash_info_t flash_info[]; /* info for FLASH chips */

static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);

#endif

#endif

修改

#if 0

#if defined(CONFIG_CMD_IMLS)

#if 0

defined(CONFIG_CMD_IMLS)

(4)修改/common/cmd_flash.c

/common/cmd_flash.c 32 行后面的所有部分均注释掉

#if 0

defined(CONFIG_CMD_JFFS2) && defined(CONFIG_CMD_MTDPARTS)

#endif

(5)修改配置文件,添加对 NAND FLASH 的支持 /include/configs/james2410.h

在 Command line configuration 部分,添加

#define CONFIG_CMD_NAND

在最后添加

#if defined(CONFIG_CMD_NAND)

#define CONFIG_NAND_S3C2410

#define CONFIG_SYS_NAND_BASE 0x4E000000

#define CONFIG_SYS_MAX_NAND_DEVICE 1 /* Max number of NAND

devices */

#define SECTORSIZE 512

#define SECTORSIZE_2K 2048

#define NAND_SECTOR_SIZE SECTORSIZE

#define NAND_SECTOR_SIZE_2K SECTORSIZE_2K

#define NAND_BLOCK_MASK 511

#define NAND_BLOCK_MASK_2K 2047

#define NAND_MAX_CHIPS 1

#define CONFIG_MTD_NAND_VERIFY_WRITE

#define CONFIG_SYS_64BIT_VSPRINTF /* needed for nand_util.c */

#endif /* CONFIG_CMD_NAND */

(6)在 board/samsung/james2410/james2410.c 文件中添加

#if defined(CONFIG_CMD_NAND)

#include

#endif

寻找如下部分:

clk_power->MPLLCON = ((M_MDIV << 12) + (M_PDIV << 4) + M_SDIV);

/* some delay between MPLL and UPLL */

delay (4000);

/* configure UPLL */

clk_power->UPLLCON = ((U_M_MDIV <

U_M_SDIV);

在 delay(4000);后再增加一段代码:delay (4000);。为了增加板子对 U 盘的支持。

(7)编译,运行

make distclean

make james2410_config

make

生成 u-boot.bin 文件

(8)烧写 uboot.bin 文件,进入 uboot 模式输入 help 命令,可以看到 nand 相关的命令。

四、增加 UBI 文件系统的支持

(1)修改/include/configs/james2410.h 文件,增加如下代码:

#if 1

#define CONFIG_MTD_DEVICE 1

#define CONFIG_MTD_PARTITIONS 1

#define CONFIG_CMD_MTDPARTS

#define CONFIG_CMD_UBIFS

#define CONFIG_CMD_UBI

#define CONFIG_LZO 1

#define CONFIG_RBTREE 1

#endif

#define MTDIDS_DEFAULT "nand0=nandflash0"

#define MTDPARTS_DEFAULT "mtdparts=nandflash0:1m@0(uboot),"

"3m(kernel)," "-(root)"

(2)修改/arch/arm/cpu/arm920t/start.S

寻找并修改/*copy U-Boot to RAM*/下

ldr r0, =TEXT_BASE //传递给 C 代码的第一个参数:u-boot 在 RAM 中的起始地址

mov r1, #0x0 //传递给 C 代码的第二个参数:Nand Flash 的起始地址

mov r2, #0x50000 //传递给 C 代码的第三个参数:u-boot 的长度大小(320KB)

bl nand_read_ll //此处调用 C 代码中读 Nand 的函数,现在还没有要自己编写实现

(3)修改/include/configs/james2410.h

寻找如下信息并修改为:

#define CONFIG_SYS_MALLOC_LEN (CONFIG_ENV_SIZE+ 512*1024)

#define CONFIG_SYS_GBL_DATA_SIZE 512 /* size in bytes reserved for initial data */

#define CONFIG_STACKSIZE (512*1024) /* regular stack */

五、修改 uboot 的开机启动环境以及生成 uboot 镜像

(1)修改/u-boot-.06/include/configs/james2410.h

#define CONFIG_BOOTDELAY 3

#define CONFIG_BOOTARGS "console=ttySAC0,115200 ubi.mtd=2 root=ubi0:root

rootfstype=ubifs init=/linuxrc"

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

#define CONFIG_NETMASK 255.255.0.0

#define CONFIG_IPADDR 192.168.3.181

#define CONFIG_SERVERIP 192.168.3.124

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

#define CONFIG_BOOTCOMMAND "nboot 0x30008000 0 0x100000; bootm"

#define CONFIG_SETUP_MEMORY_TAGS//to pass args to kernel

#define CONFIG_CMDLINE_TAG

#define CONFIG_CMDLINE_EDITING//mem last cmd

(4)编译,运行

make distclean

make james2410_config

make

生成 u-boot.bin 文件

(5)烧写 uboot.bin 文件,进入 uboot 模式输入 help 命令,可以看到 ubi 相关的命令。

(6)执行如下命令

#mtdpart default

#mtdpart

可以看到与我们对 ubi 文件系统的默认分区配置是一致的。

如果觉得《linux 移植 内存 配置 Linux 移植篇 之 uboot的移植》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。