Miguel Osorio | 03f2e23 | 2019-09-17 19:44:37 -0700 | [diff] [blame] | 1 | # 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 Elliott | eed65c6 | 2019-12-03 10:28:59 +0000 | [diff] [blame] | 5 | project( |
| 6 | 'opentitan', 'c', 'cpp', |
| 7 | version: '0.1', |
Sam Elliott | 0c157c0 | 2019-12-02 19:30:59 +0000 | [diff] [blame] | 8 | meson_version: '>=0.51.0', # Matches version in python-requirements.txt |
Miguel Young de la Sota | fa12ce0 | 2019-11-26 14:53:55 -0600 | [diff] [blame] | 9 | default_options: [ |
| 10 | 'c_std=c11', |
| 11 | 'build.c_std=c11', |
Sam Elliott | 0c157c0 | 2019-12-02 19:30:59 +0000 | [diff] [blame] | 12 | 'cpp_std=c++14', |
| 13 | 'build.cpp_std=c++14', |
Sam Elliott | e9f2566 | 2019-12-02 19:33:19 +0000 | [diff] [blame] | 14 | 'warning_level=1', |
Sam Elliott | e9f2566 | 2019-12-02 19:33:19 +0000 | [diff] [blame] | 15 | 'werror=true', |
Sam Elliott | 5797c56 | 2019-12-02 19:40:34 +0000 | [diff] [blame] | 16 | 'debug=true', |
Sam Elliott | 6f30e93 | 2020-01-08 15:57:01 +0000 | [diff] [blame] | 17 | 'b_staticpic=false', # Disable PIC for device static libraries |
| 18 | 'b_pie=false', # Disable PIE for device executables |
Sam Elliott | 0c157c0 | 2019-12-02 19:30:59 +0000 | [diff] [blame] | 19 | ], |
Sam Elliott | eed65c6 | 2019-12-03 10:28:59 +0000 | [diff] [blame] | 20 | ) |
Miguel Osorio | 03f2e23 | 2019-09-17 19:44:37 -0700 | [diff] [blame] | 21 | |
Miguel Young de la Sota | b2ef483 | 2019-11-22 12:55:46 -0600 | [diff] [blame] | 22 | ot_version = get_option('ot_version') |
| 23 | if ot_version == 'undef' |
| 24 | error('ot_version option not set. Please run meson with a valid OpenTitan version option.') |
| 25 | endif |
| 26 | |
Miguel Young de la Sota | 3c8ab3b | 2019-11-21 13:59:09 -0600 | [diff] [blame] | 27 | dev_bin_dir = get_option('dev_bin_dir') |
| 28 | host_bin_dir = get_option('host_bin_dir') |
| 29 | if 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.') |
| 31 | endif |
Jon Flatley | a863a28 | 2020-03-03 10:49:39 -0500 | [diff] [blame] | 32 | tock_local = get_option('tock_local') |
Miguel Young de la Sota | 3c8ab3b | 2019-11-21 13:59:09 -0600 | [diff] [blame] | 33 | |
Sam Elliott | 371c79f | 2020-06-23 20:06:19 +0100 | [diff] [blame] | 34 | # See the comment in `./util/meson-purge-includes.sh` for why this is necessary. |
| 35 | if not get_option('keep_includes') |
| 36 | meson.add_postconf_script(meson.source_root() + '/util/meson-purge-includes.sh') |
| 37 | endif |
| 38 | |
| 39 | |
| 40 | # C Arguments to optimize for size, used on cross builds only. |
Sam Elliott | ca894e0 | 2019-12-03 10:25:17 +0000 | [diff] [blame] | 41 | optimize_size_args = [ |
| 42 | '-Os', # General "Optimize for Size" Option |
| 43 | '-fvisibility=hidden', # Hide symbols by default |
| 44 | ] |
| 45 | |
Sam Elliott | 371c79f | 2020-06-23 20:06:19 +0100 | [diff] [blame] | 46 | if meson.get_compiler('c', native: false).has_argument('-Wa,--no-pad-sections') |
Luís Marques | 1db34ad | 2020-05-27 13:41:57 +0100 | [diff] [blame] | 47 | # 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' |
| 53 | endif |
| 54 | |
Sam Elliott | 371c79f | 2020-06-23 20:06:19 +0100 | [diff] [blame] | 55 | # The following flags are applied to *all* builds, both cross builds and native |
| 56 | # builds. |
| 57 | c_cpp_args = [ |
| 58 | # We use absolute include paths as much as possible. |
Miguel Young de la Sota | 3fbb28a | 2019-10-16 15:15:07 -0500 | [diff] [blame] | 59 | '-I' + meson.source_root(), |
| 60 | '-I' + meson.build_root(), |
Sam Elliott | 371c79f | 2020-06-23 20:06:19 +0100 | [diff] [blame] | 61 | ] |
| 62 | add_project_arguments(c_cpp_args, language: ['c', 'cpp'], native: false) |
| 63 | add_project_arguments(c_cpp_args, language: ['c', 'cpp'], native: true) |
Miguel Osorio | 03f2e23 | 2019-09-17 19:44:37 -0700 | [diff] [blame] | 64 | |
Sam Elliott | 58d285f | 2019-11-29 11:58:29 +0000 | [diff] [blame] | 65 | # The following flags are applied only to cross builds |
Sam Elliott | 371c79f | 2020-06-23 20:06:19 +0100 | [diff] [blame] | 66 | c_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 Elliott | 58d285f | 2019-11-29 11:58:29 +0000 | [diff] [blame] | 72 | add_project_arguments( |
Sam Elliott | 371c79f | 2020-06-23 20:06:19 +0100 | [diff] [blame] | 73 | c_cpp_cross_args, |
Sam Elliott | ca894e0 | 2019-12-03 10:25:17 +0000 | [diff] [blame] | 74 | optimize_size_args, |
Sam Elliott | 371c79f | 2020-06-23 20:06:19 +0100 | [diff] [blame] | 75 | language: ['c', 'cpp'], native: false) |
| 76 | |
| 77 | # The following flags are applied only to cross builds |
| 78 | c_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 Elliott | 58d285f | 2019-11-29 11:58:29 +0000 | [diff] [blame] | 85 | add_project_link_arguments( |
Sam Elliott | 371c79f | 2020-06-23 20:06:19 +0100 | [diff] [blame] | 86 | c_cpp_cross_link_args, |
| 87 | language: ['c', 'cpp'], native: false) |
| 88 | |
Sam Elliott | 58d285f | 2019-11-29 11:58:29 +0000 | [diff] [blame] | 89 | |
Miguel Osorio | 03f2e23 | 2019-09-17 19:44:37 -0700 | [diff] [blame] | 90 | # Common program references. |
| 91 | prog_python = import('python').find_installation('python3') |
Timothy Chen | 5f7b9c4 | 2019-10-30 22:27:16 -0700 | [diff] [blame] | 92 | prog_objdump = find_program('objdump') |
Miguel Osorio | 03f2e23 | 2019-09-17 19:44:37 -0700 | [diff] [blame] | 93 | prog_objcopy = find_program('objcopy') |
| 94 | prog_srec_cat = find_program('srec_cat') |
| 95 | prog_git = find_program('git') |
| 96 | |
Miguel Young de la Sota | 3fbb28a | 2019-10-16 15:15:07 -0500 | [diff] [blame] | 97 | # Hardware register headers. These are generated from HJSON files, and accesible |
| 98 | # in C via |#include "{IP_NAME}_regs.h"|. |
Miguel Osorio | 03f2e23 | 2019-09-17 19:44:37 -0700 | [diff] [blame] | 99 | gen_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 Vogel | def712f | 2019-10-24 18:57:36 +0100 | [diff] [blame] | 109 | hw_ip_aes_reg_h = gen_hw_hdr.process('hw/ip/aes/data/aes.hjson') |
Sam Elliott | 390e470 | 2020-04-03 15:29:01 +0100 | [diff] [blame] | 110 | hw_ip_flash_ctrl_reg_h = gen_hw_hdr.process('hw/ip/flash_ctrl/data/flash_ctrl.hjson') |
Tobias Wölfel | 4c5fbec | 2019-10-23 12:43:17 +0200 | [diff] [blame] | 111 | hw_ip_gpio_reg_h = gen_hw_hdr.process('hw/ip/gpio/data/gpio.hjson') |
| 112 | hw_ip_hmac_reg_h = gen_hw_hdr.process('hw/ip/hmac/data/hmac.hjson') |
Miguel Young de la Sota | 92bc4cc | 2020-04-09 12:32:43 -0400 | [diff] [blame] | 113 | hw_ip_i2c_reg_h = gen_hw_hdr.process('hw/ip/i2c/data/i2c.hjson') |
Philipp Wagner | 5c2d294 | 2020-06-22 11:34:00 +0100 | [diff] [blame] | 114 | hw_ip_otbn_reg_h = gen_hw_hdr.process('hw/ip/otbn/data/otbn.hjson') |
Tobias Wölfel | 4c5fbec | 2019-10-23 12:43:17 +0200 | [diff] [blame] | 115 | hw_ip_spi_device_reg_h = gen_hw_hdr.process('hw/ip/spi_device/data/spi_device.hjson') |
| 116 | hw_ip_rv_timer_reg_h = gen_hw_hdr.process('hw/ip/rv_timer/data/rv_timer.hjson') |
| 117 | hw_ip_uart_reg_h = gen_hw_hdr.process('hw/ip/uart/data/uart.hjson') |
| 118 | hw_ip_usbdev_reg_h = gen_hw_hdr.process('hw/ip/usbdev/data/usbdev.hjson') |
Sam Elliott | 390e470 | 2020-04-03 15:29:01 +0100 | [diff] [blame] | 119 | hw_top_earlgrey_pinmux_reg_h = gen_hw_hdr.process('hw/top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson') |
| 120 | hw_top_earlgrey_rv_plic_reg_h = gen_hw_hdr.process('hw/top_earlgrey/ip/rv_plic/data/autogen/rv_plic.hjson') |
Miguel Osorio | 03f2e23 | 2019-09-17 19:44:37 -0700 | [diff] [blame] | 121 | |
Sam Elliott | 7e36bd7 | 2020-04-22 14:05:49 +0100 | [diff] [blame] | 122 | # Top Earlgrey library (top_earlgrey) |
| 123 | # The sources for this are generated into the hw hierarchy. |
| 124 | top_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 Osorio | 03f2e23 | 2019-09-17 19:44:37 -0700 | [diff] [blame] | 133 | subdir('sw') |