Arm startup code (2): at91sam9260 startup details

Source: Internet
Author: User

(For Original Articles, please indicate the source. Thank you)

Well, there have been too many accounts owed to blogs recently. This type of serialization will continue. Let's talk about the startup code of arm today. I have many friends who write code, but I am confused when starting the arm code. In fact, most of them do not understand the working mechanism of arm.

I talked a lot about this serialization, but remember that the first code executed by the arm powered on started from 0x0. No one can change this. However, the address 0x0 can be mapped in many ways to execute different codes. Some manufacturers have added a small boot code on the bare arm chip. To load code from a special device and start arm. This situation is rare. Some well-designed ARM chips can be loaded from SPI flash and UART, which greatly simplifies the complexity of the first program burning on the arm board. This requires a detailed explanation of the datasheet chip.

Take at91sam9260 as an example to analyze how to write the startup code.

At91sam9260 is a well-designed ARM chip. It can be started from nandflash and spiflash. According to the chip manual, spiflash can be started from the npcs0 or npcs1 port of spi0, or from other devices. At91sam9260 is best used with at45dbxxx chip. The at91sam9260 public board is the startup storage made of at45. The chip is connected to the npcs1 port of spi0. The code of the system solidified in 9260 follows the following procedure:




The boot program in the system cannot be regarded as a qualified bootloader. There are mainly the following reasons:

1. First, the startup Code does not know what hardware 9260 is connected. Generally, the customer connects the chip according to their own needs. For example, the startup Code cannot know the access time sequence and the size of the SDRAM. This is closely related to the customer's choice. Or the customer receives their own SRAM, and so on ...... The startup Code cannot be known in advance. Therefore, these hardware cannot be initialized, let alone those hardware.

2. the startup Code cannot be too large. Because too many resources are required to run the code in a chip, not only the ROM of the Code is stored, but also the large enough SRAM needs to be integrated in the chip. This increases the cost of chips. This is not necessary because it can be solved in a better way. The startup Code cannot be too large, which means it is not complicated and has a single function.

Therefore, you can only use your mind to start the code loading program. The program loaded by the boot program is called Bootstrap and not bootloader. Why is Bootstrap not called bootloader? It's not that Atmel wants to be unconventional and find a selling point. Boot Program loads Bootstrap, and bootstrap then loads the bootloader or your application.

Because boot program can only initialize the internal resources of known chips. Two SRAM registers, including the internal PLL, are available. All are the internal resources of the chip. The boot program code is stored in ROM, and it must take up some data to run, either in sram0 or in sram1. BOOT program can only load Bootstrap to 9260 or sram1 in sram0. Sram0 and sram1 each have 4 K. Note: During Bootstrap loading, boot program still needs to work properly. If the boot
Program uses sram1 to store runtime variables and other data ...... Therefore, the boot program cannot destroy the data in sram1 and can only copy the bootstrap code to sram0 for execution.

Some children's shoes asked, can I use the useless boot program section in sram1 for bootstrap? The answer is no. But you must understand that theoretically there is no problem at all. To implement this function, bootstrap must divide the code into two parts, one of 4 kb, and the rest of the code into sram1 (it may only be 2 kb, depending on how much the boot program occupies ). This will inevitably complicate boot program and increase chip costs. In addition, to implement multipart loading, you must modify the link file during Bootstrap compilation to generate an elf file with loading information. Alternatively, you can generate two binfiles. This operation is too complex and proved to be unnecessary. Therefore, the at91sam9260 hardware limits the bootstrap size, which can only be 4 kb, and the data size cannot exceed 4 kb. :-).

What can the 4 kb arm code do? The Atmel designer gave us a solution. Bootstrap initializes the hardware and loads OS or applications from the specified device. Since this code can be changed, we can make some modifications to the hardware. For example, you can initialize SDRAM. If there is no SDRAM, only the extended SRAM can be used, or the system bus can be initialized to adapt to this extended SRAM.

After initialization, you can load the next code from any device. It can be loaded from the network, UART, and Flash. To load data from the network, you need to integrate the network protocol stack. If UART is used, you also need to integrate the corresponding protocol. You must consider a problem, can I store a 4 kb code space? Therefore, in actual use, the code is generally obtained from the position specified by flash. It is also easy to get the code format, that is, the Code image loaded into the memory (raw binary ). Three problems are involved:

1. Where does Bootstrap load the application from flash? How big is loading?

2. Where does Bootstrap load these programs?

3. After Bootstrap loads the code, who does it control? In other words, where does the PC pointer point to and start executing the loaded code?


ATMEL provides some configuration macros to change the first two addresses. In the official code, configure the third address. The third address is the same as the second address. Of course, you can modify this Code. The third address is different from the second address. You can use macro configuration.

We must be clear about the three addresses:

1. where does Bootstrap load the application from flash? The address may be the internal address of the flash chip. For the ARM chip, it is impossible to access it in a simple way (that is, a Data command can be accessed ). It is necessary to use a complex method to access dozens or even hundreds of thousands of Assembly commands.

2. Where does Bootstrap load this application? The address must be the address that the ARM chip can access with a data access command! No more than one command can be accessed. Otherwise, this address cannot be used as the code storage for runtime.

3. Where does Bootstrap jump to? This is the first instruction of the application. This is determined by the link script of the application, not by bootstrap. Bootstrap does not have the right to decide the first instruction location of the application. It must know this location, in order to make the application run smoothly.


This application can be a real bootloader or user code. At this point, arm has basically said goodbye to the absurd primitive society. The three addresses are clearly understood, so you can write code freely ...... Next time, let's talk about how to practice ......

(For Original Articles, please indicate the source. Thank you)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.