由于价格的原因,相对于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