source: mainline/boot/arch/arm32/src/main.c@ 4d02595

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4d02595 was 7e752b2, checked in by Martin Decky <martin@…>, 15 years ago
  • correct printf() formatting strings and corresponding arguments
  • minor cstyle changes and other small fixes
  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * Copyright (c) 2007 Michal Kebrt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup arm32boot
30 * @{
31 */
32/** @file
33 * @brief Bootstrap.
34 */
35
36#include <arch/main.h>
37#include <arch/asm.h>
38#include <arch/mm.h>
39#include <arch/_components.h>
40#include <halt.h>
41#include <printf.h>
42#include <memstr.h>
43#include <version.h>
44#include <macros.h>
45#include <align.h>
46#include <str.h>
47#include <errno.h>
48#include <inflate.h>
49
50#define TOP2ADDR(top) (((void *) PA2KA(BOOT_OFFSET)) + (top))
51
52static bootinfo_t bootinfo;
53
54void bootstrap(void)
55{
56 mmu_start();
57 version_print();
58
59 printf("\nMemory statistics\n");
60 printf(" %p|%p: bootstrap stack\n", &boot_stack, &boot_stack);
61 printf(" %p|%p: bootstrap page table\n", &boot_pt, &boot_pt);
62 printf(" %p|%p: boot info structure\n", &bootinfo, &bootinfo);
63 printf(" %p|%p: kernel entry point\n",
64 (void *) PA2KA(BOOT_OFFSET), (void *) BOOT_OFFSET);
65
66 size_t i;
67 for (i = 0; i < COMPONENTS; i++)
68 printf(" %p|%p: %s image (%u/%u bytes)\n", components[i].start,
69 components[i].start, components[i].name, components[i].inflated,
70 components[i].size);
71
72 void *dest[COMPONENTS];
73 size_t top = 0;
74 size_t cnt = 0;
75 bootinfo.cnt = 0;
76 for (i = 0; i < min(COMPONENTS, TASKMAP_MAX_RECORDS); i++) {
77 top = ALIGN_UP(top, PAGE_SIZE);
78
79 if (i > 0) {
80 bootinfo.tasks[bootinfo.cnt].addr = TOP2ADDR(top);
81 bootinfo.tasks[bootinfo.cnt].size = components[i].inflated;
82
83 str_cpy(bootinfo.tasks[bootinfo.cnt].name,
84 BOOTINFO_TASK_NAME_BUFLEN, components[i].name);
85
86 bootinfo.cnt++;
87 }
88
89 dest[i] = TOP2ADDR(top);
90 top += components[i].inflated;
91 cnt++;
92 }
93
94 printf("\nInflating components ... ");
95
96 for (i = cnt; i > 0; i--) {
97 void *tail = components[i - 1].start + components[i - 1].size;
98 if (tail >= dest[i - 1]) {
99 printf("\n%s: Image too large to fit (%p >= %p), halting.\n",
100 components[i].name, tail, dest[i - 1]);
101 halt();
102 }
103
104 printf("%s ", components[i - 1].name);
105
106 int err = inflate(components[i - 1].start, components[i - 1].size,
107 dest[i - 1], components[i - 1].inflated);
108
109 if (err != EOK) {
110 printf("\n%s: Inflating error %d\n", components[i - 1].name, err);
111 halt();
112 }
113 }
114
115 printf(".\n");
116
117 printf("Booting the kernel... \n");
118 jump_to_kernel((void *) PA2KA(BOOT_OFFSET), &bootinfo);
119}
120
121/** @}
122 */
Note: See TracBrowser for help on using the repository browser.