Booting ARM Linux

來源:linux-2.6.30.4/Documentation/arm/Booting ARM Linuxlinux

 

            Booting ARM Linux
            =================

Author:    Russell King
Date  : 18 May 2002

The following documentation is relevant to 2.4.18-rmk6 and beyond.

In order to boot ARM Linux, you require a boot loader, which is a small
program that runs before the main kernel.  The boot loader is expected
to initialise various devices, and eventually call the Linux kernel,
passing information to the kernel.

Essentially, the boot loader should provide (as a minimum) the
following:

1. Setup and initialise the RAM.
2. Initialise one serial port.
3. Detect the machine type.
4. Setup the kernel tagged list.
5. Call the kernel image.


1. Setup and initialise RAM
---------------------------

Existing boot loaders:        MANDATORY
New boot loaders:        MANDATORY

The boot loader is expected to find and initialise all RAM that the
kernel will use for volatile data storage in the system.  It performs
this in a machine dependent manner.  (It may use internal algorithms
to automatically locate and size all RAM, or it may use knowledge of
the RAM in the machine, or any other method the boot loader designer
sees fit.)


2. Initialise one serial port
-----------------------------

Existing boot loaders:        OPTIONAL, RECOMMENDED
New boot loaders:        OPTIONAL, RECOMMENDED

The boot loader should initialise and enable one serial port on the
target.  This allows the kernel serial driver to automatically detect
which serial port it should use for the kernel console (generally
used for debugging purposes, or communication with the target.)

As an alternative, the boot loader can pass the relevant 'console='
option to the kernel via the tagged lists specifying the port, and
serial format options as described in

       Documentation/kernel-parameters.txt.


3. Detect the machine type
--------------------------

Existing boot loaders:        OPTIONAL
New boot loaders:        MANDATORY

The boot loader should detect the machine type its running on by some
method.  Whether this is a hard coded value or some algorithm that
looks at the connected hardware is beyond the scope of this document.
The boot loader must ultimately be able to provide a MACH_TYPE_xxx
value to the kernel. (see linux/arch/arm/tools/mach-types).


4. Setup the kernel tagged list
-------------------------------

Existing boot loaders:        OPTIONAL, HIGHLY RECOMMENDED
New boot loaders:        MANDATORY

The boot loader must create and initialise the kernel tagged list.
A valid tagged list starts with ATAG_CORE and ends with ATAG_NONE.
The ATAG_CORE tag may or may not be empty.  An empty ATAG_CORE tag
has the size field set to '2' (0x00000002).  The ATAG_NONE must set
the size field to zero.

Any number of tags can be placed in the list.  It is undefined
whether a repeated tag appends to the information carried by the
previous tag, or whether it replaces the information in its
entirety; some tags behave as the former, others the latter.

The boot loader must pass at a minimum the size and location of
the system memory, and root filesystem location.  Therefore, the
minimum tagged list should look:編程


    +-----------+
base ->    | ATAG_CORE |  |
    +-----------+  |
    | ATAG_MEM  |  | increasing address
    +-----------+  |
    | ATAG_NONE |  |
    +-----------+  v

The tagged list should be stored in system RAM.

The tagged list must be placed in a region of memory where neither
the kernel decompressor nor initrd 'bootp' program will overwrite
it.  The recommended placement is in the first 16KiB of RAM.
(好比:我用的是tq2440的板子,內存起始地址是0x30000000,那麼taglist建議放在0x30000000~0x30004000範圍內,app

實際在使用時放在了0x30000100的地方)ide


5. Calling the kernel image
---------------------------

Existing boot loaders:        MANDATORY
New boot loaders:        MANDATORY

There are two options for calling the kernel zImage.  If the zImage
is stored in flash, and is linked correctly to be run from flash,
then it is legal for the boot loader to call the zImage in flash
directly.

The zImage may also be placed in system RAM (at any location) and
called there.  Note that the kernel uses 16K of RAM below the image
to store page tables.  The recommended placement is 32KiB into RAM.ui

對於tq2440,zImage被加載到內存的0x30008000的地方,其中未來0x30004000~0x30008000的地址範圍被用來存放一級頁表,this

一級頁表的大小固定爲16KiB(能夠參考《ARM體系結構與編程》P179)。上面建議將zImage放到距離物理內存起始地址偏移32KiB的地方,spa

對於tq2440,物理內存起始地址是0x30000000,因此zImage應該放到0x30008000處。以前因爲不知道這個知識點,嘗試將zImage讀到小於debug

0x30008000的地方,發現內核沒法啓動,可是若是將zImage加載到大於0x30008000的地方是能夠啓動的,好比0x3000A000,我是這麼作的:3d

因爲我在NandFlash中燒寫的是uImage(64B+zImage),code

 

nand read 0x30009fc0 0x200000 0x300000  (因爲NandFlash的0x200000處存放的是uImage,這樣的話,正好將zImage加載到0x3000a000處)

go2 0x3000a000  (go2這個命令是我加的,

 

#include <common.h> #include <command.h> static struct tag *params; static void setup_start_tag(void) { params = (struct tag *)0x30000100; params->hdr.tag = ATAG_CORE; params->hdr.size = tag_size (tag_core); params->u.core.flags = 0; params->u.core.pagesize = 0; params->u.core.rootdev = 0; params = tag_next (params); } static void setup_memory_tags(void) { params->hdr.tag = ATAG_MEM; params->hdr.size = tag_size (tag_mem32); params->u.mem.start = 0x30000000; params->u.mem.size = 64*1024*1024; params = tag_next (params); } static void setup_commandline_tag(char *cmdline) { int len = strlen(cmdline) + 1; params->hdr.tag = ATAG_CMDLINE; params->hdr.size = (sizeof (struct tag_header) + len + 3) >> 2; strcpy (params->u.cmdline.cmdline, cmdline); params = tag_next (params); } static void setup_end_tag(void) { params->hdr.tag = ATAG_NONE; params->hdr.size = 0; } static int do_go2 (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { ulong addr, rc; int rcode = 0; void (*theKernel)(int zero, int arch, uint params); if (argc < 2) { cmd_usage(cmdtp); return 1; } addr = simple_strtoul(argv[1], NULL, 16); printf ("## Starting application at 0x%08lX ...\n", addr); setup_start_tag(); setup_memory_tags(); /*setup_commandline_tag("noinitrd root=/dev/mtdblock2 rootfstype=yaffs init=/linuxrc mem=64M console=ttySAC0,115200");*/ setup_commandline_tag(getenv("bootargs")); /*printf("bootargs = %s\n", getenv("bootargs"));*/ setup_end_tag(); /*run_command("nand read 0x30008000 0x200000 0x300000", 0);*/ printf ("##pengdonglin ##\n"); theKernel = (void (*)(int, int, uint))addr; theKernel(0, 168, 0x30000100); /***************/ printf ("## Application terminated, rc = 0x%lX\n", rc); return rcode; } /* -------------------------------------------------------------------- */ U_BOOT_CMD( go2, CONFIG_SYS_MAXARGS, 1, do_go2, "start application at address 'addr'", "addr [arg ...]\n - start application at address 'addr'\n" " passing 'arg' as arguments" );
View Code

 能夠參考韋東山的視頻教程。

)

 


In either case, the following conditions must be met:

- Quiesce all DMA capable devices so that memory does not get
  corrupted by bogus network packets or disk data. This will save
  you many hours of debug.

- CPU register settings
  r0 = 0,
  r1 = machine type number discovered in (3) above.
  r2 = physical address of tagged list in system RAM.

- CPU mode
  All forms of interrupts must be disabled (IRQs and FIQs)
  The CPU must be in SVC mode.  (A special exception exists for Angel)

- Caches, MMUs
  The MMU must be off.
  Instruction cache may be on or off.
  Data cache must be off.

- The boot loader is expected to call the kernel image by jumping
  directly to the first instruction of the kernel image.

相關文章
相關標籤/搜索