由于价格的原因,相对于norflash,nandflash对于存储大容量的数据来说更具有优势。但是程序不能直接在nandflash上运行,因此s3c2440提供了一个机制,即系统会自动把nandflash中前4k的内容复制到名为“Steppingstone”的内部SRAM中,利用这段SRAM,程序员需要再把程序复制到其余的SRAM中,然后运行刚刚复制到SRAM中的程序。
本文就介绍如何使u-boot在nandflash中启动,该工作原理类似于u-boot-2011.06自带的smdk6400开发板的nandflash启动过程,即最终生成的烧写文件为u-boot-nand.bin,它是由两个文件组成的:
nand_spl/u-boot-spl-16k.bin+ u-boot.bin = u-boot-nand.bin
u-boot-spl-16k.bin文件的大小正好为4k,系统启动后,这4k的内容自动复制到Steppingstone中。u-boot-spl-16k.bin在完成必要的硬件初始化后,复制u-boot.bin文件到指定的内存中,然后运行已经复制到内存中的u-boot.bin文件。
下面就具体讲解移植的过程:
1、boards.cfg
在该文件内去掉下面语句:
zhaocj2440 arm arm920t - samsung s3c24x0
2、Makefile
在该文件内的第1050行左右添加下面语句:
#########################################################################
## ARM920T Systems
#########################################################################
zhaocj2440_config : unconfig
@mkdir-p $(obj)include $(obj)board/samsung/zhaocj2440
@mkdir-p $(obj)nand_spl/board/samsung/zhaocj2440
@echo"#define CONFIG_NAND_U_BOOT" > $(obj)include/config.h
@echo"CONFIG_NAND_U_BOOT = y" >> $(obj)include/config.mk
@echo"RAM_TEXT = 0x33000000" >>$(obj)board/samsung/zhaocj2440/config.tmp
@$(MKCONFIG)zhaocj2440 arm arm920t - samsung s3c24x0
@echo"CONFIG_NAND_U_BOOT = y" >> $(obj)include/config.mk
3、board/samsung/zhaocj2440/
在该目录下创建config.mk文件,内容为:
sinclude$(OBJTREE)/board/$(BOARDDIR)/config.tmp
ifndef CONFIG_NAND_SPL
CONFIG_SYS_TEXT_BASE =$(RAM_TEXT)
else
CONFIG_SYS_TEXT_BASE = 0
endif
4、nand_spl/board/Samsung/
在该目录下创建zhaocj2440目录,并在zhaocj2440目录下再创建config.mk,Makefile,和u-boot.lds这三个文件,内容分别为:
config.mk文件:
include$(TOPDIR)/board/$(BOARDDIR)/config.mk
# PAD_TO used to generate a 4kByte binaryneeded for the combined image
# -> PAD_TO = CONFIG_SYS_TEXT_BASE +4096
PAD_TO :=$(shell expr $$[$(CONFIG_SYS_TEXT_BASE) + 4096])
ifeq ($(debug),1)
PLATFORM_CPPFLAGS += -DDEBUG
endif
Makefile文件:
CONFIG_NAND_SPL = y
include $(TOPDIR)/config.mk
include$(TOPDIR)/nand_spl/board/$(BOARDDIR)/config.mk
nandobj :=$(OBJTREE)/nand_spl/
LDSCRIPT=$(TOPDIR)/nand_spl/board/$(BOARDDIR)/u-boot.lds
LDFLAGS := -T $(nandobj)u-boot.lds -Ttext$(CONFIG_SYS_TEXT_BASE) $(LDFLAGS)
$(LDFLAGS_FINAL)
AFLAGS +=-DCONFIG_NAND_SPL
CFLAGS +=-DCONFIG_NAND_SPL
SOBJS =start.o lowlevel_init.o
COBJS =nand_boot.o s3c2440_nand.o
SRCS :=$(addprefix $(obj),$(SOBJS:.o=.S) $(COBJS:.o=.c))
OBJS :=$(addprefix $(obj),$(SOBJS) $(COBJS))
__OBJS :=$(SOBJS) $(COBJS)
LNDIR :=$(nandobj)board/$(BOARDDIR)
ALL =$(nandobj)u-boot-spl $(nandobj)u-boot-spl.bin $(nandobj)u-boot-spl-16k.bin
all: $(obj).depend$(ALL)
$(nandobj)u-boot-spl-16k.bin:$(nandobj)u-boot-spl
$(OBJCOPY)${OBJCFLAGS} --pad-to=$(PAD_TO) -O binary $< $@
$(nandobj)u-boot-spl.bin: $(nandobj)u-boot-spl
$(OBJCOPY)${OBJCFLAGS} -O binary $< $@
$(nandobj)u-boot-spl: $(OBJS) $(nandobj)u-boot.lds
cd$(LNDIR) && $(LD) $(LDFLAGS) $(__OBJS)
-Map$(nandobj)u-boot-spl.map
-o$(nandobj)u-boot-spl
$(nandobj)u-boot.lds: $(LDSCRIPT)
$(CPP)$(CPPFLAGS) $(LDPPFLAGS) -ansi -D__ASSEMBLY__ -P - <$^ >$@
# create symbolic links for common files
# from cpu directory
$(obj)start.S:
@rm-f $@
@ln-s $(TOPDIR)/arch/arm/cpu/arm920t/start.S $@
# from board directory
$(obj)lowlevel_init.S:
@rm-f $@
@ln-s $(TOPDIR)/board/samsung/zhaocj2440/lowlevel_init.S $@
# from nand_spl directory
$(obj)nand_boot.c:
@rm-f $@
@ln-s $(TOPDIR)/nand_spl/nand_boot.c $@
$(obj)s3c2440_nand.c:
@rm-f $@
@ln-s $(TOPDIR)/drivers/mtd/nand/s3c2440_nand.c$@
#########################################################################
$(obj)%.o: $(obj)%.S
$(CC)$(AFLAGS) -c -o $@ $<
$(obj)%.o: $(obj)%.c
$(CC)$(CFLAGS) -c -o $@ $<
# defines $(obj).depend target
include $(SRCTREE)/rules.mk
sinclude $(obj).depend
#########################################################################
u-boot.lds文件:
OUTPUT_FORMAT("elf32-littlearm","elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
.= 0x00000000;
.= ALIGN(4);
.text :
{
start.o (.text)
nand_boot.o (.text)
*(.text)
}
.= ALIGN(4);
.rodata: { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }
.= ALIGN(4);
.data: { *(.data) }
.= ALIGN(4);
.got: { *(.got) }
__u_boot_cmd_start= .;
.u_boot_cmd: { *(.u_boot_cmd) }
__u_boot_cmd_end= .;
.= ALIGN(4);
.rel.dyn: {
__rel_dyn_start= .;
*(.rel*)
__rel_dyn_end= .;
}
.dynsym: {
__dynsym_start= .;
*(.dynsym)
}
_end= .;
.bss__rel_dyn_start (OVERLAY) : {
__bss_start= .;
*(.bss)
.= ALIGN(4);
__bss_end__= .;
}
}
5、arch/arm/cpu/arm920t/start.s
在该文件内修改下列内容,其中红色标记的代码为需要修改的部分:
.globl _start
_start: b start_code
#ifndef CONFIG_NAND_SPL // by zhaocj
ldr pc, _undefined_instruction
ldr pc, _software_interrupt
ldr pc, _prefetch_abort
ldr pc, _data_abort
ldr pc, _not_used
ldr pc, _irq
ldr pc, _fiq
_undefined_instruction: .word undefined_instruction
_software_interrupt: .word software_interrupt
_prefetch_abort: .word prefetch_abort
_data_abort: .word data_abort
_not_used: .wordnot_used
_irq: .wordirq
_fiq: .wordfiq
_pad: .word 0x12345678 //by zhaocj start
#else
. = _start + 64
#endif //by zhaocj end
.balignl16,0xdeadbeef
…………
/* Set stackpointer in internal RAM to callboard_init_f */
#ifndef CONFIG_NAND_SPL //by zhaocj
call_board_init_f:
ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
bic sp, sp, #7 /* 8-byte alignment for ABIcompliance */
ldr r0,=0x00000000
bl board_init_f
…………
blcoloured_LED_init
blred_LED_on
#endif
#endif // by zhaocj
/*
* We are done. Do notreturn, instead branch to second part of board
* initialization, nowrunning from RAM.
*/
#ifdef CONFIG_NAND_SPL