1 | subdir('arch' / BARCH)
|
---|
2 |
|
---|
3 | if POSTBUILD == 'uboot'
|
---|
4 | boot_image_format = 'binary'
|
---|
5 | endif
|
---|
6 |
|
---|
7 | if BUILD
|
---|
8 | # Order matters.
|
---|
9 | modules = [ 'boot/kernel.elf' ] + rd_init + [ 'boot/initrd.img' ]
|
---|
10 | moddeps = []
|
---|
11 | name_transform = ''
|
---|
12 |
|
---|
13 | # Collect binary references in the correct order.
|
---|
14 | foreach m : modules
|
---|
15 | found = false
|
---|
16 | foreach bin : rd_init_binaries
|
---|
17 | if bin[1] == m
|
---|
18 | _dep = bin[0]
|
---|
19 | _newname = run_command(basename, bin[1], check: true).stdout().strip()
|
---|
20 | _oldname = run_command(basename, bin[0].full_path(), check: true).stdout().strip()
|
---|
21 |
|
---|
22 | if CONFIG_COMPRESSED_INIT
|
---|
23 | _dep = custom_target(_newname + '.gz',
|
---|
24 | output: _newname + '.gz',
|
---|
25 | input: _dep,
|
---|
26 | command: gzip,
|
---|
27 | capture: true,
|
---|
28 | )
|
---|
29 | _newname += '.gz'
|
---|
30 | _oldname = _newname
|
---|
31 | endif
|
---|
32 |
|
---|
33 | moddeps += _dep
|
---|
34 | name_transform += 's:.*/@0@:@1@:;'.format(_oldname, _newname)
|
---|
35 | found = true
|
---|
36 | break
|
---|
37 | endif
|
---|
38 | endforeach
|
---|
39 |
|
---|
40 | if not found
|
---|
41 | error('Could not find dependency ' + m)
|
---|
42 | endif
|
---|
43 | endforeach
|
---|
44 |
|
---|
45 |
|
---|
46 | boot_include_dirs = include_directories(
|
---|
47 | 'generic/include',
|
---|
48 | 'arch'/BARCH/'include',
|
---|
49 | 'genarch/include',
|
---|
50 | '../abi/arch'/BARCH/'include',
|
---|
51 | '../abi/include',
|
---|
52 | )
|
---|
53 |
|
---|
54 | boot_defs = [
|
---|
55 | '-imacros', meson.build_root() / 'config.h',
|
---|
56 | '-D_HELENOS_SOURCE',
|
---|
57 | '-DBOOT',
|
---|
58 | '-DRELEASE=' + HELENOS_RELEASE,
|
---|
59 | '-DCOPYRIGHT=' + HELENOS_COPYRIGHT,
|
---|
60 | '-DNAME=' + HELENOS_NAME,
|
---|
61 | '-D__@0@_BITS__'.format(meson.get_cross_property('bits')),
|
---|
62 | ]
|
---|
63 |
|
---|
64 | boot_c_args = arch_boot_c_args + boot_defs + [
|
---|
65 | '-ffreestanding',
|
---|
66 | ]
|
---|
67 |
|
---|
68 | boot_link_args = arch_boot_link_args + [
|
---|
69 | '-nostdlib',
|
---|
70 | '-Wl,--nmagic',
|
---|
71 | '-T', meson.current_build_dir()/'_link.ld',
|
---|
72 | '-Wl,--no-gc-sections',
|
---|
73 | ]
|
---|
74 |
|
---|
75 | if cc.get_id() == 'clang'
|
---|
76 | boot_c_args += [
|
---|
77 | '-fno-stack-protector',
|
---|
78 | '-fno-PIC',
|
---|
79 | # '-mllvm', '-asm-macro-max-nesting-depth=1000',
|
---|
80 | ]
|
---|
81 | endif
|
---|
82 |
|
---|
83 | boot_files = static_library('bootfiles', boot_src,
|
---|
84 | include_directories: boot_include_dirs,
|
---|
85 | implicit_include_directories: false,
|
---|
86 | c_args: boot_c_args,
|
---|
87 | pic: false,
|
---|
88 | build_by_default: true,
|
---|
89 | )
|
---|
90 |
|
---|
91 | # Preprocess linker script using C preprocessor.
|
---|
92 | boot_ldscript = custom_target('_link.ld',
|
---|
93 | input: 'arch'/KARCH/'_link.ld.in',
|
---|
94 | output: '_link.ld',
|
---|
95 | command: [
|
---|
96 | cc.cmd_array(),
|
---|
97 | boot_c_args,
|
---|
98 | '-I' + meson.current_source_dir()/'arch'/KARCH/'include',
|
---|
99 | '-D__ASSEMBLER__',
|
---|
100 | '-D__LINKER__',
|
---|
101 | '-E',
|
---|
102 | '-P',
|
---|
103 | '-x', 'c',
|
---|
104 | '@INPUT@',
|
---|
105 | ],
|
---|
106 | capture: true,
|
---|
107 | build_by_default: true
|
---|
108 | )
|
---|
109 |
|
---|
110 | # Create empty object file.
|
---|
111 | boot_empty_o = custom_target('empty.o',
|
---|
112 | output: 'empty.o',
|
---|
113 | command: [
|
---|
114 | cc.cmd_array(),
|
---|
115 | boot_c_args,
|
---|
116 | '-x', 'c',
|
---|
117 | '-c',
|
---|
118 | '-o', '@OUTPUT@',
|
---|
119 | '-',
|
---|
120 | ],
|
---|
121 | )
|
---|
122 |
|
---|
123 | boot_comps_tar = custom_target('components.tar',
|
---|
124 | input: moddeps,
|
---|
125 | output: 'components.tar',
|
---|
126 | command: [ tar, '--transform', name_transform ],
|
---|
127 | )
|
---|
128 |
|
---|
129 | # Add .payload section to the empty object.
|
---|
130 | boot_comps_o = custom_target('components.o',
|
---|
131 | output: 'components.o',
|
---|
132 | input: [ boot_comps_tar, boot_empty_o ],
|
---|
133 | command: [
|
---|
134 | objcopy,
|
---|
135 | '--add-section', '.payload=@INPUT0@',
|
---|
136 | '@INPUT1@',
|
---|
137 | '@OUTPUT@',
|
---|
138 | ],
|
---|
139 | )
|
---|
140 |
|
---|
141 | boot_image_name = 'image.boot'
|
---|
142 | boot_image_map_path = meson.current_build_dir()/boot_image_name + '.map'
|
---|
143 |
|
---|
144 | boot_elf = executable(boot_image_name + '.elf', boot_comps_o,
|
---|
145 | include_directories: boot_include_dirs,
|
---|
146 | c_args: boot_c_args,
|
---|
147 | link_args: boot_c_args + boot_link_args + [
|
---|
148 | '-Wl,-Map,' + boot_image_map_path,
|
---|
149 | ],
|
---|
150 | link_depends: boot_ldscript,
|
---|
151 | link_whole: boot_files,
|
---|
152 | pie: false,
|
---|
153 | build_by_default: false,
|
---|
154 | )
|
---|
155 |
|
---|
156 | if boot_image_format == 'elf'
|
---|
157 | boot_image = boot_elf
|
---|
158 | endif
|
---|
159 |
|
---|
160 | if boot_image_format == 'binary'
|
---|
161 | # Some platforms can't ELF.
|
---|
162 | boot_image = custom_target(boot_image_name + '.bin',
|
---|
163 | input: boot_elf,
|
---|
164 | output: boot_image_name + '.bin',
|
---|
165 | command: [ objcopy, '-O', 'binary', '@INPUT@', '@OUTPUT@' ],
|
---|
166 | )
|
---|
167 | endif
|
---|
168 | endif
|
---|
169 |
|
---|
170 | if POSTBUILD == 'raw'
|
---|
171 | POST_INPUT = boot_image
|
---|
172 | endif
|
---|
173 |
|
---|
174 | if POSTBUILD == 'grub'
|
---|
175 | subdir('grub')
|
---|
176 | endif
|
---|
177 |
|
---|
178 | if POSTBUILD == 'yaboot'
|
---|
179 | subdir('yaboot')
|
---|
180 | endif
|
---|
181 |
|
---|
182 | if POSTBUILD == 'silo'
|
---|
183 | subdir('silo')
|
---|
184 | endif
|
---|
185 |
|
---|
186 | if POSTBUILD == 'uboot'
|
---|
187 | IMAGE_NAME = 'HelenOS-' + HELENOS_RELEASE
|
---|
188 |
|
---|
189 | POST_INPUT = custom_target('uboot-image',
|
---|
190 | output: 'uboot-image.bin',
|
---|
191 | input: boot_image,
|
---|
192 | command: [
|
---|
193 | mkuimage,
|
---|
194 | '-name', IMAGE_NAME,
|
---|
195 | '-laddr', LADDR,
|
---|
196 | '-saddr', SADDR,
|
---|
197 | '-ostype', UIMAGE_OS,
|
---|
198 | '@INPUT@',
|
---|
199 | '@OUTPUT@',
|
---|
200 | ],
|
---|
201 | )
|
---|
202 | endif
|
---|