由於價格的原因,相對於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
#########################################################################