GNU ARM Assembly--(XVIII) u-boot-boot method using nand_spl

Publisher:疯狂小马Latest update time:2015-10-14 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
        After analyzing the makefile and mkconfig script of u-boot-2012.07 in " GNU ARM Assembly -- (Seventeen) Interpretation of u-boot's makefile and mkconfig ", a phenomenon was found: there are many fewer targets such as xxx_config in the makefile, and there is an additional boards.cfg file in the directory. A closer look at the makefile and mkconfig will show that there is actually no substantial change. In other words, when we make xxx_config, we use

%_config::unconfig
@$(MKCONFIG) -A $(@:_config=)

        The weird thing is that there is this little bit below:

################################################ ######################
## ARM1176 Systems
####################### ################################################
smdk6400_noUSB_config
smdk6400_config :unconfig
@mkdir -p $(obj)include $(obj)board/samsung/smdk6400
@mkdir -p $(obj)nand_spl/board/samsung/smdk6400
@echo "#define CONFIG_NAND_U_BOOT" > $(obj)include/config.h
@echo "CONFIG_NAND_U_BOOT = y" >> $(obj)include/config.mk
@if [ - z "$(findstring smdk6400_noUSB_config,$@)" ]; then
echo "RAM_TEXT = 0x57e00000" >> $(obj)board/samsung/smdk6400/config.tmp;
else
echo "RAM_TEXT = 0xc7e00000" >> $(obj)board /samsung/smdk6400/config.tmp;
fi
@$(MKCONFIG) smdk6400 arm arm1176 smdk6400 samsung s3c64xx
@echo "CONFIG_NAND_U_BOOT = y" >> $(obj)include/config.mk

        I felt strange when I saw this. In the new version of uboot, the configuration of other boards all use the %_config target. Why does smdk6400 have a separate target? I looked at the nand_spl directory out of curiosity, and used make smdk6400_config and make to see the configuration and compilation process. At that time, I initially figured out what was going on:

        There is a nand_boot.c in the nand_spl directory. From the file name, it seems to be related to booting from nand. Speaking of nand booting, I have to add a sentence: I studied the GNU ARM assembly series on a broken notebook with Ubuntu installed. Because it is a notebook, there is no parallel port or serial port. I can only use a USB to serial port. I can't afford advanced gadgets like jlink. Because it is a broken notebook, win doesn't run well, so I just run linux. So I dare not touch the nor flash in my board at all, and can only use nand flash. Therefore, I am quite familiar with the process of nand flash booting. Then why does s3c2440 boot from nand Flash booting must use the internal 4K sram. According to the datasheet, when booting from nand, you must set the OM[0:1] switch to map the internal 4K sram to 0x00000000, because arm boots from 0x00000000. Samsung's design is that in this case, the first 4K data in nand will be loaded into sram by hardware, so that nand can be booted with this 4K sram. Why is this 4K sram necessary to boot from nand? According to some predecessors and my own understanding, there are two main reasons: first, nand flash operation requires a controller, and when soc is booting, no instruction is executed in time, how to initialize the controller, if the controller is not initialized, how to get the instructions on nand flash; second, nand flash itself can only read pages, and cpu cannot get a 32-bit instruction from nand. In addition, nand flash is dumbfounded for jump instructions, and nand flash cannot be read randomly in this way.

        I said I was going to insert a sentence, but I accidentally inserted a paragraph and started a new paragraph:

        There are three files in nand_spl/board/samsung/smdk6400: config.mk, Makefile and u-boot.lds. By looking at these three files and the makefile in the uboot root directory, you can roughly understand how nand_spl is implemented:

        In the makefile in the uboot root directory there is:

$(obj)u-boot-nand.bin:nand_spl $(obj)u-boot.bin
cat $(obj)nand_spl/u-boot-spl-16k.bin $(obj)u-boot.bin > $( obj)u-boot-nand.bin

        This is how to merge two bin files into one bin file!!!

        To be honest, I had this idea when I was making my own bootloader. I didn't expect that when I transplanted uboot by myself, I found that the new uboot also adopted this method. I was a little proud, ^_^

        More specifically, u-boot-spl.bin in the nand_spl directory does the following:

        1. Set the CPU to svc mode

        2. Turn off the door dog and interrupt

        3. Initialize the system clock

        4. Disable MMU and Cache

        5. Initialize the sdram controller

        6. Set sp and jump to the nand_boot function in nand_boot.c mentioned above. This function initializes the nand controller and loads the u-boot.bin image after 4K from nand to sdram, and then jumps to the beginning of the u-boot.bin image to continue the subsequent work

        To implement this u-boot-spl-16k.bin, you can follow the steps below:

        1. Add a new target in the makefile in the uboot root directory:

################################################ ####################
#TQ2440 by Baikal
########################## ###########################################
TQ2440_config: unconfig
@echo " #define CONFIG_NAND_U_BOOT" > $(obj)include/config.h
#echo "RAM_TEXT = 0x33000000" > $(obj)board/samsung/TQ2400/config.tmp;
@$(MKCONFIG) TQ2440 arm arm920t - samsung s3c24x0
@echo "CONFIG_NAND_U_BOOT = y" >> $(obj)include/config.mk

        2. Create a new folder TQ2440 under nand_spl/board/samsung, copy the three files under the smdk6400 directory and modify them slowly. The biggest modification is the change of makefile:

        start.S uses arch/arm/cpu/arm920t/start.S

        lowlevel_init.S uses board/samsung/smdk2410/lowlevel_init.S

        nand_boot.c uses nand_spl/nand_boot.c

        s3c2440_nand.c uses drivers/mtd/nand/s3c2440_nand.c

        3. Porting the code of s3c2440_nand

        4.Wrap some code in start.S with #ifdef CONFIG_NAND_SPL or #ifndef CONFIG_NAND_SPL according to the specific situation.

        5. The final compilation and linking process is to link a u-boot-spl file, and strip the binary data file u-boot-spl.bin from the u-boot-spl file. In fact, this bin file is only about 1.2k, fill it to 4K size

        

        If you have a certain understanding of bootloader and are familiar with compiling, linking, and makefile scripts, this alone is not a big task. Don't forget to be familiar with nand flash control.

        Finally, let me talk about a problem that delayed me for a long time. I forgot to set sp when jumping nand_boot.c. Because I could only debug through LED, the phenomenon I saw made me mistakenly think that my nand flash driver was not adjusted correctly. Finally, I suddenly understood. At that time, I was also annoyed when looking at those LEDs...

        just go on, stop being impatient

Reference address:GNU ARM Assembly--(XVIII) u-boot-boot method using nand_spl

Previous article:GNU ARM Assembly--(Seventeen) Interpretation of u-boot's makefile and mkconfig
Next article:GNU ARM Assembly--(XIX) u-boot-nand-spl startup process analysis

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号