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