1 | subdir('arch' / BARCH)
|
---|
2 |
|
---|
3 | if POSTBUILD == 'uimage'
|
---|
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.source_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 | # Preprocess linker script using C preprocessor.
|
---|
84 | boot_ldscript = custom_target('_link.ld',
|
---|
85 | input: 'arch'/KARCH/'_link.ld.in',
|
---|
86 | output: '_link.ld',
|
---|
87 | command: [
|
---|
88 | cc.cmd_array(),
|
---|
89 | boot_c_args,
|
---|
90 | '-I' + meson.current_source_dir()/'arch'/KARCH/'include',
|
---|
91 | '-D__ASSEMBLER__',
|
---|
92 | '-D__LINKER__',
|
---|
93 | '-E',
|
---|
94 | '-P',
|
---|
95 | '-x', 'c',
|
---|
96 | '@INPUT@',
|
---|
97 | ],
|
---|
98 | capture: true,
|
---|
99 | )
|
---|
100 |
|
---|
101 | # Create empty object file.
|
---|
102 | boot_empty_o = custom_target('empty.o',
|
---|
103 | output: 'empty.o',
|
---|
104 | command: [
|
---|
105 | cc.cmd_array(),
|
---|
106 | boot_c_args,
|
---|
107 | '-x', 'c',
|
---|
108 | '-c',
|
---|
109 | '-o', '@OUTPUT@',
|
---|
110 | '-',
|
---|
111 | ],
|
---|
112 | )
|
---|
113 |
|
---|
114 | boot_comps_tar = custom_target('components.tar',
|
---|
115 | input: moddeps,
|
---|
116 | output: 'components.tar',
|
---|
117 | command: [ tar, '--transform', name_transform ],
|
---|
118 | )
|
---|
119 |
|
---|
120 | # Add .payload section to the empty object.
|
---|
121 | boot_comps_o = custom_target('components.o',
|
---|
122 | output: 'components.o',
|
---|
123 | input: [ boot_comps_tar, boot_empty_o ],
|
---|
124 | command: [
|
---|
125 | objcopy,
|
---|
126 | '--add-section', '.payload=@INPUT0@',
|
---|
127 | '@INPUT1@',
|
---|
128 | '@OUTPUT@',
|
---|
129 | ],
|
---|
130 | )
|
---|
131 |
|
---|
132 | boot_image_name = 'image.boot'
|
---|
133 | boot_image_map_path = meson.current_build_dir()/boot_image_name + '.map'
|
---|
134 |
|
---|
135 | boot_elf = executable(boot_image_name + '.elf', boot_src, boot_comps_o,
|
---|
136 | include_directories: boot_include_dirs,
|
---|
137 | implicit_include_directories: false,
|
---|
138 | c_args: boot_c_args,
|
---|
139 | link_args: boot_c_args + boot_link_args + [
|
---|
140 | '-Wl,-Map,' + boot_image_map_path,
|
---|
141 | ],
|
---|
142 | link_depends: boot_ldscript,
|
---|
143 | install: true,
|
---|
144 | install_dir: 'boot',
|
---|
145 | pie: false,
|
---|
146 | )
|
---|
147 |
|
---|
148 | if boot_image_format == 'elf'
|
---|
149 | boot_image = boot_elf
|
---|
150 | endif
|
---|
151 |
|
---|
152 | if boot_image_format == 'binary'
|
---|
153 | # Some platforms can't ELF.
|
---|
154 | boot_image = custom_target(boot_image_name + '.bin',
|
---|
155 | input: boot_elf,
|
---|
156 | output: boot_image_name + '.bin',
|
---|
157 | command: [ objcopy, '-O', 'binary', '@INPUT@', '@OUTPUT@' ],
|
---|
158 | )
|
---|
159 | endif
|
---|
160 | endif
|
---|
161 |
|
---|
162 | if POSTBUILD == 'raw'
|
---|
163 | POST_INPUT = boot_image
|
---|
164 | endif
|
---|
165 |
|
---|
166 | if POSTBUILD == 'grub'
|
---|
167 | subdir('grub')
|
---|
168 | endif
|
---|
169 |
|
---|
170 | if POSTBUILD == 'uboot'
|
---|
171 | IMAGE_NAME = 'HelenOS-' + HELENOS_RELEASE
|
---|
172 |
|
---|
173 | POST_INPUT = custom_target('uboot-image',
|
---|
174 | output: 'uboot-image.bin',
|
---|
175 | input: boot_image,
|
---|
176 | command: [
|
---|
177 | mkuimage,
|
---|
178 | '-name', IMAGE_NAME,
|
---|
179 | '-laddr', LADDR,
|
---|
180 | '-saddr', SADDR,
|
---|
181 | '-ostype', UIMAGE_OS,
|
---|
182 | '@INPUT@',
|
---|
183 | '@OUTPUT@',
|
---|
184 | ],
|
---|
185 | )
|
---|
186 | endif
|
---|
187 |
|
---|
188 |
|
---|