aboutsummaryrefslogtreecommitdiff
path: root/targets/emcraft_sf2_som/BUILD.gn
blob: 36bd46b70607263814fb0137e9e3e1e61620394f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Copyright 2022 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

import("//build_overrides/pigweed.gni")

import("$dir_pw_build/linker_script.gni")
import("$dir_pw_build/target_types.gni")
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_malloc/backend.gni")
import("$dir_pw_system/system_target.gni")
import("$dir_pw_third_party/smartfusion_mss/mss.gni")
import("$dir_pw_tokenizer/backend.gni")
import("$dir_pw_toolchain/generate_toolchain.gni")

config("pw_malloc_active") {
  if (pw_malloc_BACKEND != "") {
    defines = [ "PW_MALLOC_ACTIVE=1" ]
  }
}

config("emcraft_ddr_init") {
  # Emcraft's DDR config must be manually set by a custom init function. This
  # conflicts with the built-in MSS init function. I have not looked into this
  # myself to see if it's absoutely needed or not.
  defines = [ "MSS_SYS_MDDR_CONFIG_BY_CORTEX=0" ]
}

if (current_toolchain != default_toolchain) {
  pw_linker_script("mddr_debug_linker_script") {
    defines = [
      "PW_BOOT_CODE_BEGIN=0x00000200",  # After vector table.

      # TODO(skeys) Bootloader is capable of loading 16M of uncompressed code
      # from SPI flash to external RAM. For now use the allocated eNVM flash
      # (256K - Bootloader - InSystemProgrammer = 192K)
      "PW_BOOT_CODE_SIZE=0x30000",

      # TODO(b/235348465): Currently "pw_tokenizer/detokenize_test" requires at
      # least 6K bytes in heap when using pw_malloc_freelist. The heap size
      # required for tests should be investigated.
      "PW_BOOT_HEAP_SIZE=4M",

      # With external RAM remapped, we use the entire internal ram for the
      # stack (64K).
      "PW_BOOT_MIN_STACK_SIZE=64K",

      # Using external DDR RAM, we just need to make sure we go past our ROM
      # sections.
      "PW_BOOT_RAM_BEGIN=0xA1000000",

      # We assume that the bootloader loaded all 16M of text.
      "PW_BOOT_RAM_SIZE=48M",
      "PW_BOOT_VECTOR_TABLE_BEGIN=0x00000000",
      "PW_BOOT_VECTOR_TABLE_SIZE=512",
    ]
    linker_script = "emcraft_sf2_som_mddr_debug.ld"
  }
  pw_linker_script("mddr_production_linker_script") {
    defines = [
      "PW_BOOT_FLASH_BEGIN=0x00000200",  # After vector table.

      # TODO(skeys) Bootloader is capable of loading 16M of uncompressed code
      # from SPI flash to external RAM. For now use the allocated eNVM flash
      # (256K - Bootloader - InSystemProgrammer = 192K)
      "PW_BOOT_FLASH_SIZE=0x30000",

      # TODO(b/235348465): Currently "pw_tokenizer/detokenize_test" requires at
      # least 6K bytes in heap when using pw_malloc_freelist. The heap size
      # required for tests should be investigated.
      "PW_BOOT_HEAP_SIZE=4M",

      # With external RAM remapped, we use the entire internal ram for the
      # stack (64K).
      "PW_BOOT_MIN_STACK_SIZE=1024K",

      # Using external DDR RAM, we just need to make sure we go past our ROM
      # sections.
      "PW_BOOT_RAM_BEGIN=0xA1000000",

      # We assume that the bootloader loaded all 16M of text.
      "PW_BOOT_RAM_SIZE=48M",
      "PW_BOOT_VECTOR_TABLE_BEGIN=0x00000000",
      "PW_BOOT_VECTOR_TABLE_SIZE=512",
    ]
    linker_script = "$dir_pw_boot_cortex_m/basic_cortex_m.ld"
  }

  pw_source_set("pre_init") {
    configs = [ ":pw_malloc_active" ]
    deps = [
      "$dir_pw_boot",
      "$dir_pw_boot_cortex_m",
      "$dir_pw_malloc",
      "$dir_pw_preprocessor",
      "$dir_pw_string",
      "$dir_pw_sys_io_emcraft_sf2",
      "$dir_pw_system",
      "$dir_pw_third_party/freertos",
    ]
    sources = [
      "boot.cc",
      "vector_table.c",
    ]
  }

  config("config_includes") {
    include_dirs = [ "config" ]
    configs = [ ":emcraft_ddr_init" ]
  }

  pw_source_set("sf2_mss_hal_config") {
    public_configs = [ ":config_includes" ]
    public =
        [ "config/sf2_mss_hal_conf.h" ]  # SKEYS likely want to put the MDDR
                                         # config by cortex etc stuff here
  }

  pw_source_set("sf2_freertos_config") {
    public_configs = [ ":config_includes" ]
    public_deps = [ "$dir_pw_third_party/freertos:config_assert" ]
    public = [ "config/FreeRTOSConfig.h" ]
  }
}

# Configured for use with a first stage boot loader to configure DDR and
# perform memory remapping.
pw_system_target("emcraft_sf2_som") {
  cpu = PW_SYSTEM_CPU.CORTEX_M3
  scheduler = PW_SYSTEM_SCHEDULER.FREERTOS
  link_deps = [ "$dir_pigweed/targets/emcraft_sf2_som:pre_init" ]

  build_args = {
    pw_log_BACKEND = dir_pw_log_tokenized
    pw_log_tokenized_HANDLER_BACKEND = "$dir_pw_system:log_backend.impl"
    pw_third_party_freertos_CONFIG =
        "$dir_pigweed/targets/emcraft_sf2_som:sf2_freertos_config"
    pw_third_party_freertos_PORT = "$dir_pw_third_party/freertos:arm_cm3"
    pw_sys_io_BACKEND = dir_pw_sys_io_emcraft_sf2

    pw_boot_cortex_m_LINKER_SCRIPT =
        "//targets/emcraft_sf2_som:mddr_production_linker_script"
  }
}

# Debug target configured to work with MSS linker script and startup code.
# TODO(skeys) Add linker script and config for debug builds using SoftConsole.
pw_system_target("emcraft_sf2_som_debug") {
  cpu = PW_SYSTEM_CPU.CORTEX_M3
  scheduler = PW_SYSTEM_SCHEDULER.FREERTOS
  link_deps = [ "$dir_pigweed/targets/emcraft_sf2_som:pre_init" ]

  build_args = {
    pw_log_BACKEND = dir_pw_log_tokenized
    pw_log_tokenized_HANDLER_BACKEND = "$dir_pw_system:log_backend.impl"
    pw_third_party_freertos_CONFIG =
        "$dir_pigweed/targets/emcraft_sf2_som:sf2_freertos_config"
    pw_third_party_freertos_PORT = "$dir_pw_third_party/freertos:arm_cm3"
    pw_sys_io_BACKEND = dir_pw_sys_io_emcraft_sf2

    # Override the default pw_boot_cortex_m linker script and set the memory
    # regions for the target.
    pw_boot_cortex_m_LINKER_SCRIPT =
        "//targets/emcraft_sf2_som:mddr_debug_linker_script"
    pw_third_party_smartfusion_mss_CONFIG = "debug"
  }
}

pw_doc_group("docs") {
  sources = [ "target_docs.rst" ]
}