Reputation: 4567
I am trying to understand ARM Linux Boot Process.
These are the things I understood:
My query is how this Boot ROM Code gets the address of u-boot first instruction ?
Upvotes: 3
Views: 4304
Reputation: 71576
ARM doesn't make chips, it makes IP that chip vendors purchase. It is one block in their chip design, usually they have many other blocks, USB controllers (likely purchased IP), PCIE controller (likely purchased IP), DDR, Ethernet, SATA, eMMC/SD, etc. Plus glue logic, plus whatever their secret sauce is they add to this to make it different and more interesting to the consumer than the competition.
The address space, particularly for the full sized ARMs is fairly wide open, so even if they use the same USB IP as everyone else, doesn't mean it is at the same address as everyone else.
There is no reason to assume that all chips with a cortex-a are centered around the cortex-a, the cortex-a may just be there to boot and manage the real thing the chip was made for. The chips you are asking about are most likely centered around the ARM processor the purpose of the chip is to make a "CPU" that is ARM based. What we have seen in that market is a need to support various non-volatile storage solutions. Some may wish to be RAM heavy and don't care that a slow spi flash is used to get the kernel and root file system over and runtime everything is RAM based including the file system. Some may wish to support traditional hard drives as well as RAM, the file system being on something SATA for example, spinning media or SSD. Some may wish to use eMMC, SD, etc. With the very high cost of chip production, it does not make sense to make one chip for each combination, rather make one chip that supports many combinations. You use several "strap" pins (which are not pins but balls/pads on the BGA) that the customer ties to ground or "high" whatever the definition of that voltage is so that when the chip comes out of reset (whichever of the reset pins for that product are documented as sampling the strap pins) those strap pins tell the "processor" (chip as an entity) how you desire it to boot. I want to you to first look for an sd card on this SPI bus if nothing there then look for a SATA drive on this interface if nothing there then please fall into the xmodem bootloader on uart0.
This leads into Frant's excellent answer. What IP is in the chip, what possible non-volatile storage is supported and what possible solutions of loading a bootloader if the "chip" itself supports it are very much chip specific not just Broadcom does it this way and TI does it another but a specific chip or family of chips within their possibly vast array of products, no reason to assume any two products from a vendor work the same way, you read the documentation for each one you are interested in. Certainly don't assume any two vendors details are remotely the same, it is very likely that they have purchased similar IP for certain technologies (maybe everyone uses the same USB IP for example, or most USB IP conforms to a common set of registers, or maybe not...).
I have not gotten to the ARM core, you could in these designs likely change your mind and pull the ARM out and put a mips in and sell that as a product...
Now does it make sense to say write logic to read a spi flash that loads the contents of that flash into an internal SRAM and then for that boot mode put that SRAM at the ARM processors address zero then reset the ARM? yes that is not a horrible idea to do that in logic only. But does it make sense for example to have logic dig through a file system of a SATA drive to find some bootloader? Maybe not so much, possible sure, but maybe your product will be viable longer if you instead put a ROM in the product that can be aimed at the ARM address zero the ARM boots that, the ARM code in that ROM reads the straps, makes the decision as to what the boot media is spins up that peripheral (SATA, eMMC, spi, etc) wades through the filesystem looking for a filename, copies that file to SRAM, re-maps the ARM address space (not using an MMU but using the logic in the chip) and fakes a reset to that by branching to address zero. (The ROM is mapped in two places at least address zero then some other address so that it can branch to the other address space allowing address zero to be remapped and reused). so that if down the road you find a bug all you have to do is change the image burned into the ROM before you deliver the chips, rather than spin the chip to change the transistors and/or wiring of the transistors (pennies and days/weeks vs millions of dollars and months). So you may actually never see or be the code that the ARM processor boots into on reset. The reset line to the ARM core you might never have any physical nor software access to.
THEN depending on the myriad of boot options for this or any of the many chip offerings, the next step is very much specific to that chip and possibly that boot mode. You as owning all the bootcode for that board level product may have to per the chip and board design, bring up DDR, bring up PCIE, bring up USB. Or perhaps some chip vendor logic/code has done some of that for you (unlikely, but maybe for specific boot cases). Now you have these generic and popular "boot loaders" like u-boot, you as the software designer and implementer may choose to have code that precedes u-boot that does a fair amount of the work because maybe porting u-boot is difficult, maybe not. Also note u-boot is in no way required for Linux, booting Linux is easy, u-boot is a monstrosity, a beast of its own, the easiest way to boot Linux is to not bother porting u-boot. What u-boot gives is an already written bootloader, it is an argument that can go either way is it cheaper to port u-boot or is it cheaper to just roll your own (or port one of the competitors to u-boot)? Depends on the boot options you want, if you want bootp/tftp or anything network stack, well that's a task although there are off the shelf solutions. If you want to access a file system on some media, well that is another strong argument to just use u-boot. But if you don't need all of that, then maybe you don't need u-boot.
You have to walk the list of things that need to happen before Linux boots, the chips tend to not have enough on chip RAM to hold the Linux kernel image and the root file system, so you need to get DDR up before Linux. you probably need to get PCIE up and enumerated and maybe USB I have not looked at that. But Ethernet that can be brought up by the Linux driver for that peripheral as an example.
The requirements to "boot" Linux on ARM ports of Linux and probably others are relatively simple. You copy the Linux kernel to some space in memory ideally aligned or at an agreed offset from an aligned address (say 0x10001000 for example, just pulling that out of the air), you then provide a table of information, how much RAM there is, the ASCII kernel boot string, and these days the device tree information. You branch to the Linux kernel with one of the registers say r0 pointed at this table (search for ATAG ARM Linux or some such combination of words). That's it: booting Linux using a not that old kernel is setting a few dozen bytes in RAM, copy the kernel to RAM, and branch to it, a few dozen lines of code, no need for the u-boot monstrosity. Now it is more than a few dozen bytes but it is still a table generated independent of u-boot, place that in RAM, place the kernel in RAM set one or more registers to point at the table, branch to the address where the kernel lives "booting Linux" is complete or the Linux bootloader is complete.
You still have to port Linux which is a task that requires lots of trial and error and eventually years of experience. particularly since Linux is a constantly evolving beast in and of itself.
How do you get to u-boot code? you may have some pre-u-boot code you have to write to find u-boot and copy it to RAM then branch to it. the chip vendor may have solved this for you and "all you have to do" is put u-boot where they tell you for the media choice, and then u-boot is placed at address zero in the ARM memory space for some internal SRAM, or u-boot is placed at some non-zero address in the ARM memory space and some magic (a ROM based bootloader in the chip) causes your u-boot code to execute from that address.
One I messed with recently is the TI chip used on various Beagle boards, black, green, white, pocket, etc...One of the boot modes it looks at a specific offset on the SD card (not part of a file system yet, a specific logical block if you will or basically specific offset in the SD card address space) for a table, that table includes where in the "processors" address space you want the attached "bootloader" to be copied to, is it compressed, etc. You make your bootloader (roll your own or build a u-boot port) you build the correct table per the documentation with a destination address how much data, possibly a crc/checksum, whatever the docs say. The "chip" magically (probably software but might be pure logic) copies that over and causes the ARM to start executing at that address (likely ARM software that simply branches there). And that is how YOU get u-boot running on that product line with that boot option.
The SAME product line has other strap options, has other SD card boot options to get a u-boot loaded and running.
Other products from other vendors have different solutions.
The Broadcom chip in the raspberry pi, totally different beast, or at least how it is used. It has a Broadcom (invented or purchased) GPU in it, that GPU boots some ROM based code that knows how to find its own first stage bootloader on an SD card, that first stage loader does things like initialize DDR, there isn't PCIE so that doesn't have to happen and I don't think the GPU cares about USB so that doesn't have to get enumerated either. but it does search out a second stage bootloader of GPU code, which is really an RTOS that it is loading, the code the GPU uses to do its graphics features to offload the burden on the ARM. In addition to that that software also looks for a third file on the flash (and fourth and nth) lets just go with third kernel.img which it copies to RAM (the DDR is shared between the GPU and the ARM but with different addressing schemes) at an agreed offset (0x8000 if kernel.img is used without config.txt adjustments to that) the GPU then writes a bootstrap program and ATAGs into ARM's memory at address zero and then releases reset on the ARM core(s). The GPU is the bootloader, with relatively limited options, but for that platform design/solution one media option, a removable SD card, what operating system, etc you run on the ARM is whatever is on that SD card.
I think you will find the lots of straps driving multiple possible non-volatile storage media peripherals being the more common solution. Whether or not one or any of these boot options for a particular SOC can take u-boot (or choose your bootloader or write your own) directly or of a pre-u-boot program is required for any number of reasons (on chip SRAM is too small for a full u-boot lets say for example, sake of argument) is specific to that boot option for that chip from that vendor and is documented somewhere although if you are not part of the company making the board that signed the NDA with that chip vendor you may not get to see that documentation. And/or as you may know or will learn, that doesn't mean the documentation is good or makes sense. Some companies or products do a bad job, some do a good job and most are somewhere in between. If you are paying them for parts and have an NDA you at least have the option of getting or buying tech support and can ask direct questions (again the answers may not be useful, depends on the company and their support).
Just because there is an ARM inside means next to nothing. ARM makes processor cores not IP, depending on the SOC design it may be easy or moderately painful but possible to pull the ARM out and put some other purchased IP (like MIPS) in there or free IP (like risc-v) and re-use the rest of your already tested design/glue. Trying to generalize ARM based processors is like trying to generalize automobiles with V-6 engines, if I have a vehicle with a V-6 engine does that mean the headlight controls are always on the dash to the left of the steering column? Nope!
Upvotes: 2
Reputation: 5925
It depends on the SoC, and the scheme used for booting will differ from one SoC to the other. It is usually documented in the SoC's reference manual, and it does describe the various conventions (where to read u-boot from, specific addresses) the u-boot port specific to this SoC should follow in order to the code in ROM to be able to load u-boot, and ultimately transfer control to u-boot.
This code in the ROM could do something like:
- If pin x is 0, read 64KiB from first sector of the eMMC into the On Chip Static RAM, then transfer control to the code located at offset 256 of the OCRAM for example.
- If pin x is 1, configure the UART for 19200 bauds, 8 bits parity, no stop bits, attempt to read 64KiB from the serial port using the X-MODEM protocol into the OCRAM, then transfer control to the code located at offset 256 of the OCRAM.
This code, which is often named the Secondary Program Loader (SPL) would then be responsible for, say, configuring the SDRAM controller, then read the non-SPL part of u-boot into at the beginnning of the SDRAM, then jump to a specific address in the SDRAM. The SPL for a given SoC should be small enough to fit in the SoC On Chip RAM. The ROM code would be the Primary Boot Loader in this scenario.
In the case of the TI AM335x Cortex-A8 SoCs for example, section 26.1.6 of the Technical Reference Manual, and more specifically figure 26-10, explains the boot process. Some input pins may be used by the ROM code to direct the boot process - see SYSBOOT Configuration Pins in table 26-7. See The AM335x U-Boot User's Guide for more u-boot specific, AM335x-related information.
Upvotes: 4