source: mainline/boot/arch/ia64/src/main.c@ 9286475

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9286475 was 63a045c, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Unify handling of compressed init data and use regular tar + gzip to achieve it

There are two issues this commit solves.

First is that architecture-specific code duplicates most of the init binary
handling in each architecture, each with miniscule and confusing variations.
After this commit, the init binary expansion is almost entirely handled by
unified generic code.

Second is that the way we used to generate the incorporated data is somewhat
convoluted. Previously we have a Python script which generates a zip archive
with individual deflate-compressed files and accompanying header and C files
which contain structures describing the archive contents.
The zip file is then extracted and the individual deflate-compressed files are
included in the binary via assembler code.
Since gas doesn't take particular care to be consistent between architectures,
the assembly portions are also not uniform and the build script needs to know
particulars of the architecture's assembly.

Instead of doing that, after this commit we first gzip each included file, then
we pack the gzipped files into a tar archive, and then we include the archive
into the binary using objcopy.
Linker script provides symbols for the start and end of the archive,
and the payload is in a self-describing format, so there is no need for any
generated code.

Note that we are doing the opposite of the conventional .tar.gz format.
It would be somewhat inconvenient to use .tar.gz since the uncompressed files
need to be aligned to page size, so we'd have to first decompress the entire
payload to determine the final position of the files (and hence the required
amount of memory).

  • Property mode set to 100644
File size: 5.5 KB
Line 
1/*
2 * Copyright (c) 2005 Martin Decky
3 * Copyright (c) 2006 Jakub Jermar
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <arch/main.h>
31#include <arch/types.h>
32#include <arch/arch.h>
33#include <arch/asm.h>
34#include <genarch/efi.h>
35#include <arch/sal.h>
36#include <arch/pal.h>
37#include <halt.h>
38#include <printf.h>
39#include <memstr.h>
40#include <version.h>
41#include <macros.h>
42#include <align.h>
43#include <str.h>
44#include <errno.h>
45#include <payload.h>
46
47#define DEFAULT_MEMORY_BASE 0x4000000ULL
48#define DEFAULT_MEMORY_SIZE (256 * 1024 * 1024)
49#define DEFAULT_LEGACY_IO_BASE 0x00000FFFFC000000ULL
50#define DEFAULT_LEGACY_IO_SIZE 0x4000000ULL
51
52#define DEFAULT_FREQ_SCALE 0x0000000100000001ULL /* 1/1 */
53#define DEFAULT_SYS_FREQ 100000000ULL /* 100MHz */
54
55#define MEMMAP_FREE_MEM 0
56#define MEMMAP_IO 1
57#define MEMMAP_IO_PORTS 2
58
59extern boot_param_t *bootpar;
60
61static bootinfo_t bootinfo;
62
63static void read_efi_memmap(void)
64{
65 memmap_item_t *memmap = bootinfo.memmap;
66 size_t items = 0;
67
68 if (!bootpar) {
69 /* Fake-up a memory map for simulators. */
70 memmap[items].base = DEFAULT_MEMORY_BASE;
71 memmap[items].size = DEFAULT_MEMORY_SIZE;
72 memmap[items].type = MEMMAP_FREE_MEM;
73 items++;
74
75 memmap[items].base = DEFAULT_LEGACY_IO_BASE;
76 memmap[items].size = DEFAULT_LEGACY_IO_SIZE;
77 memmap[items].type = MEMMAP_IO_PORTS;
78 items++;
79 } else {
80 char *cur, *mm_base = (char *) bootpar->efi_memmap;
81 size_t mm_size = bootpar->efi_memmap_sz;
82 size_t md_size = bootpar->efi_memdesc_sz;
83
84 /*
85 * Walk the EFI memory map using the V1 memory descriptor
86 * format. The actual memory descriptor can use newer format,
87 * but it must always be backwards compatible with the V1
88 * format.
89 */
90 for (cur = mm_base;
91 (cur < mm_base + (mm_size - md_size)) &&
92 (items < MEMMAP_ITEMS);
93 cur += md_size) {
94 efi_v1_memdesc_t *md = (efi_v1_memdesc_t *) cur;
95
96 switch ((efi_memory_type_t) md->type) {
97 case EFI_CONVENTIONAL_MEMORY:
98 memmap[items].type = MEMMAP_FREE_MEM;
99 break;
100 case EFI_MEMORY_MAPPED_IO:
101 memmap[items].type = MEMMAP_IO;
102 break;
103 case EFI_MEMORY_MAPPED_IO_PORT_SPACE:
104 memmap[items].type = MEMMAP_IO_PORTS;
105 break;
106 default:
107 continue;
108 }
109
110 memmap[items].base = md->phys_start;
111 memmap[items].size = md->pages * EFI_PAGE_SIZE;
112 items++;
113 }
114 }
115
116 bootinfo.memmap_items = items;
117}
118
119static void read_pal_configuration(void)
120{
121 if (bootpar) {
122 bootinfo.freq_scale = pal_proc_freq_ratio();
123 } else {
124 /* Configure default values for simulators. */
125 bootinfo.freq_scale = DEFAULT_FREQ_SCALE;
126 }
127}
128
129static void read_sal_configuration(void)
130{
131 if (bootpar && bootpar->efi_system_table) {
132 efi_guid_t sal_guid = SAL_SYSTEM_TABLE_GUID;
133 sal_system_table_header_t *sal_st;
134
135 sal_st = efi_vendor_table_find(
136 (efi_system_table_t *) bootpar->efi_system_table, sal_guid);
137
138 sal_system_table_parse(sal_st);
139
140 bootinfo.sys_freq = sal_base_clock_frequency();
141 } else {
142 /* Configure default values for simulators. */
143 bootinfo.sys_freq = DEFAULT_SYS_FREQ;
144 }
145}
146
147void bootstrap(void)
148{
149 version_print();
150
151 printf("Boot loader: %p -> %p\n", loader_start, loader_end);
152 printf(" %p|%p: boot info structure\n", &bootinfo, &bootinfo);
153 printf(" %p|%p: kernel entry point\n",
154 (void *) KERNEL_ADDRESS, (void *) KERNEL_ADDRESS);
155 printf(" %p|%p: loader entry point\n",
156 (void *) LOADER_ADDRESS, (void *) LOADER_ADDRESS);
157
158 read_efi_memmap();
159 read_sal_configuration();
160 read_pal_configuration();
161
162 uint8_t *kernel_start = (uint8_t *) KERNEL_ADDRESS;
163 uint8_t *ram_end = NULL;
164
165 /* Find the end of the memory area occupied by the kernel. */
166 for (unsigned i = 0; i < bootinfo.memmap_items; i++) {
167 memmap_item_t m = bootinfo.memmap[i];
168 if (m.type == MEMMAP_FREE_MEM &&
169 m.base <= (uintptr_t) kernel_start &&
170 m.base + m.size > (uintptr_t) kernel_start) {
171 ram_end = (uint8_t *) (m.base + m.size);
172 }
173 }
174
175 if (ram_end == NULL) {
176 printf("Memory map doesn't contain usable area at kernel's address.\n");
177 halt();
178 }
179
180 // FIXME: Correct kernel's logical address.
181 extract_payload(&bootinfo.taskmap, kernel_start, ram_end,
182 (uintptr_t) kernel_start, NULL);
183
184 printf("Booting the kernel ...\n");
185 jump_to_kernel(&bootinfo);
186}
Note: See TracBrowser for help on using the repository browser.