blob: b329faa03190ef0529f62d0e6b9a3e7966a4c3a0 [file] [log] [blame]
Miguel Osorio03f2e232019-09-17 19:44:37 -07001# Copyright lowRISC contributors.
2# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3# SPDX-License-Identifier: Apache-2.0
4
Sam Elliotteed65c62019-12-03 10:28:59 +00005project(
6 'opentitan', 'c', 'cpp',
7 version: '0.1',
Sam Elliott0c157c02019-12-02 19:30:59 +00008 meson_version: '>=0.51.0', # Matches version in python-requirements.txt
Miguel Young de la Sotafa12ce02019-11-26 14:53:55 -06009 default_options: [
10 'c_std=c11',
11 'build.c_std=c11',
Sam Elliott0c157c02019-12-02 19:30:59 +000012 'cpp_std=c++14',
13 'build.cpp_std=c++14',
Sam Elliotte9f25662019-12-02 19:33:19 +000014 'warning_level=1',
Sam Elliotte9f25662019-12-02 19:33:19 +000015 'werror=true',
Sam Elliott5797c562019-12-02 19:40:34 +000016 'debug=true',
Sam Elliott6f30e932020-01-08 15:57:01 +000017 'b_staticpic=false', # Disable PIC for device static libraries
18 'b_pie=false', # Disable PIE for device executables
Sam Elliott0c157c02019-12-02 19:30:59 +000019 ],
Sam Elliotteed65c62019-12-03 10:28:59 +000020)
Miguel Osorio03f2e232019-09-17 19:44:37 -070021
Miguel Young de la Sotab2ef4832019-11-22 12:55:46 -060022ot_version = get_option('ot_version')
23if ot_version == 'undef'
24 error('ot_version option not set. Please run meson with a valid OpenTitan version option.')
25endif
26
Miguel Young de la Sota3c8ab3b2019-11-21 13:59:09 -060027dev_bin_dir = get_option('dev_bin_dir')
28host_bin_dir = get_option('host_bin_dir')
29if dev_bin_dir == 'undef' or host_bin_dir == 'undef'
30 error('dev_bin_dir option not set. Please run meson with a valid binary directory option.')
31endif
Jon Flatleya863a282020-03-03 10:49:39 -050032tock_local = get_option('tock_local')
Miguel Young de la Sota3c8ab3b2019-11-21 13:59:09 -060033
Sam Elliott371c79f2020-06-23 20:06:19 +010034# See the comment in `./util/meson-purge-includes.sh` for why this is necessary.
35if not get_option('keep_includes')
36 meson.add_postconf_script(meson.source_root() + '/util/meson-purge-includes.sh')
37endif
38
39
40# C Arguments to optimize for size, used on cross builds only.
Sam Elliottca894e02019-12-03 10:25:17 +000041optimize_size_args = [
42 '-Os', # General "Optimize for Size" Option
43 '-fvisibility=hidden', # Hide symbols by default
44]
45
Sam Elliott371c79f2020-06-23 20:06:19 +010046if meson.get_compiler('c', native: false).has_argument('-Wa,--no-pad-sections')
Luís Marques1db34ad2020-05-27 13:41:57 +010047 # Don't pad assembly sections. This was originally added to avoid sections
48 # being padded to the alignment size. Specifically, .vectors was being
49 # padded to 256 bytes when aligning to that value, when it only needed to be
50 # 128 bytes long. Clang doesn't do this padding, so restricting this option
51 # to GCC doesn't waste space when compiling with Clang.
52 optimize_size_args += '-Wa,--no-pad-sections'
53endif
54
Sam Elliott371c79f2020-06-23 20:06:19 +010055# The following flags are applied to *all* builds, both cross builds and native
56# builds.
57c_cpp_args = [
58 # We use absolute include paths as much as possible.
Miguel Young de la Sota3fbb28a2019-10-16 15:15:07 -050059 '-I' + meson.source_root(),
60 '-I' + meson.build_root(),
Sam Elliott371c79f2020-06-23 20:06:19 +010061]
62add_project_arguments(c_cpp_args, language: ['c', 'cpp'], native: false)
63add_project_arguments(c_cpp_args, language: ['c', 'cpp'], native: true)
Miguel Osorio03f2e232019-09-17 19:44:37 -070064
Sam Elliott58d285f2019-11-29 11:58:29 +000065# The following flags are applied only to cross builds
Sam Elliott371c79f2020-06-23 20:06:19 +010066c_cpp_cross_args = [
67 # Do not use standard system headers
68 '-nostdinc',
69 # Use OpenTitan's freestanding headers instead
70 '-isystem' + meson.source_root() / 'sw/device/lib/base/freestanding',
71]
Sam Elliott58d285f2019-11-29 11:58:29 +000072add_project_arguments(
Sam Elliott371c79f2020-06-23 20:06:19 +010073 c_cpp_cross_args,
Sam Elliottca894e02019-12-03 10:25:17 +000074 optimize_size_args,
Sam Elliott371c79f2020-06-23 20:06:19 +010075 language: ['c', 'cpp'], native: false)
76
77# The following flags are applied only to cross builds
78c_cpp_cross_link_args = [
79 # Do not use standard system startup files or libraries
80 '-nostartfiles',
81 '-nostdlib',
82 # Only link static files
83 '-static',
84]
Sam Elliott58d285f2019-11-29 11:58:29 +000085add_project_link_arguments(
Sam Elliott371c79f2020-06-23 20:06:19 +010086 c_cpp_cross_link_args,
87 language: ['c', 'cpp'], native: false)
88
Sam Elliott58d285f2019-11-29 11:58:29 +000089
Miguel Osorio03f2e232019-09-17 19:44:37 -070090# Common program references.
91prog_python = import('python').find_installation('python3')
Timothy Chen5f7b9c42019-10-30 22:27:16 -070092prog_objdump = find_program('objdump')
Miguel Osorio03f2e232019-09-17 19:44:37 -070093prog_objcopy = find_program('objcopy')
94prog_srec_cat = find_program('srec_cat')
95prog_git = find_program('git')
96
Miguel Young de la Sota3fbb28a2019-10-16 15:15:07 -050097# Hardware register headers. These are generated from HJSON files, and accesible
98# in C via |#include "{IP_NAME}_regs.h"|.
Miguel Osorio03f2e232019-09-17 19:44:37 -070099gen_hw_hdr = generator(
100 prog_python,
101 output: '@BASENAME@_regs.h',
102 arguments: [
103 '@SOURCE_DIR@/util/regtool.py', '-D', '-o', '@BUILD_DIR@/@BASENAME@_regs.h',
104 '@INPUT@',
105 ],
106)
107
108# TODO: Considering moving these into hw/ip directories.
Pirmin Vogeldef712f2019-10-24 18:57:36 +0100109hw_ip_aes_reg_h = gen_hw_hdr.process('hw/ip/aes/data/aes.hjson')
Sam Elliott390e4702020-04-03 15:29:01 +0100110hw_ip_flash_ctrl_reg_h = gen_hw_hdr.process('hw/ip/flash_ctrl/data/flash_ctrl.hjson')
Tobias Wölfel4c5fbec2019-10-23 12:43:17 +0200111hw_ip_gpio_reg_h = gen_hw_hdr.process('hw/ip/gpio/data/gpio.hjson')
112hw_ip_hmac_reg_h = gen_hw_hdr.process('hw/ip/hmac/data/hmac.hjson')
Miguel Young de la Sota92bc4cc2020-04-09 12:32:43 -0400113hw_ip_i2c_reg_h = gen_hw_hdr.process('hw/ip/i2c/data/i2c.hjson')
Philipp Wagner5c2d2942020-06-22 11:34:00 +0100114hw_ip_otbn_reg_h = gen_hw_hdr.process('hw/ip/otbn/data/otbn.hjson')
Tobias Wölfel4c5fbec2019-10-23 12:43:17 +0200115hw_ip_spi_device_reg_h = gen_hw_hdr.process('hw/ip/spi_device/data/spi_device.hjson')
116hw_ip_rv_timer_reg_h = gen_hw_hdr.process('hw/ip/rv_timer/data/rv_timer.hjson')
117hw_ip_uart_reg_h = gen_hw_hdr.process('hw/ip/uart/data/uart.hjson')
118hw_ip_usbdev_reg_h = gen_hw_hdr.process('hw/ip/usbdev/data/usbdev.hjson')
Sam Elliott390e4702020-04-03 15:29:01 +0100119hw_top_earlgrey_pinmux_reg_h = gen_hw_hdr.process('hw/top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson')
120hw_top_earlgrey_rv_plic_reg_h = gen_hw_hdr.process('hw/top_earlgrey/ip/rv_plic/data/autogen/rv_plic.hjson')
Miguel Osorio03f2e232019-09-17 19:44:37 -0700121
Sam Elliott7e36bd72020-04-22 14:05:49 +0100122# Top Earlgrey library (top_earlgrey)
123# The sources for this are generated into the hw hierarchy.
124top_earlgrey = declare_dependency(
125 link_with: static_library(
126 'top_earlgrey_ot',
127 sources: [
128 'hw/top_earlgrey/sw/autogen/top_earlgrey.c',
129 ],
130 )
131)
132
Miguel Osorio03f2e232019-09-17 19:44:37 -0700133subdir('sw')