4 * Copyright (c) 2006 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licenced under the GPL.
12 #define KERNEL_ARGS_ADDR 0x100
13 #define KERNEL_LOAD_ADDR 0x00010000
14 #define INITRD_LOAD_ADDR 0x00800000
16 /* The worlds second smallest bootloader. Set r0-r2, then jump to kernel. */
17 static uint32_t bootloader
[] = {
18 0xe3a00000, /* mov r0, #0 */
19 0xe3a01000, /* mov r1, #0x?? */
20 0xe3811c00, /* orr r1, r1, #0x??00 */
21 0xe59f2000, /* ldr r2, [pc, #0] */
22 0xe59ff000, /* ldr pc, [pc, #0] */
23 0, /* Address of kernel args. Set by integratorcp_init. */
24 0 /* Kernel entry point. Set by integratorcp_init. */
27 static void set_kernel_args(uint32_t ram_size
, int initrd_size
,
28 const char *kernel_cmdline
)
32 p
= (uint32_t *)(phys_ram_base
+ KERNEL_ARGS_ADDR
);
35 stl_raw(p
++, 0x54410001);
41 stl_raw(p
++, 0x54410002);
42 stl_raw(p
++, ram_size
);
47 stl_raw(p
++, 0x54420005);
48 stl_raw(p
++, INITRD_LOAD_ADDR
);
49 stl_raw(p
++, initrd_size
);
51 if (kernel_cmdline
&& *kernel_cmdline
) {
55 cmdline_size
= strlen(kernel_cmdline
);
56 memcpy (p
+ 2, kernel_cmdline
, cmdline_size
+ 1);
57 cmdline_size
= (cmdline_size
>> 2) + 1;
58 stl_raw(p
++, cmdline_size
+ 2);
59 stl_raw(p
++, 0x54410009);
67 void arm_load_kernel(int ram_size
, const char *kernel_filename
,
68 const char *kernel_cmdline
, const char *initrd_filename
,
75 /* Load the kernel. */
76 if (!kernel_filename
) {
77 fprintf(stderr
, "Kernel image must be specified\n");
80 kernel_size
= load_image(kernel_filename
,
81 phys_ram_base
+ KERNEL_LOAD_ADDR
);
82 if (kernel_size
< 0) {
83 fprintf(stderr
, "qemu: could not load kernel '%s'\n", kernel_filename
);
86 if (initrd_filename
) {
87 initrd_size
= load_image(initrd_filename
,
88 phys_ram_base
+ INITRD_LOAD_ADDR
);
89 if (initrd_size
< 0) {
90 fprintf(stderr
, "qemu: could not load initrd '%s'\n",
97 bootloader
[1] |= board_id
& 0xff;
98 bootloader
[2] |= (board_id
>> 8) & 0xff;
99 bootloader
[5] = KERNEL_ARGS_ADDR
;
100 bootloader
[6] = KERNEL_LOAD_ADDR
;
101 for (n
= 0; n
< sizeof(bootloader
) / 4; n
++)
102 stl_raw(phys_ram_base
+ (n
* 4), bootloader
[n
]);
103 set_kernel_args(ram_size
, initrd_size
, kernel_cmdline
);