1# Copyright 2022 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15import("//build_overrides/pigweed.gni") 16 17import("$dir_pw_build/linker_script.gni") 18import("$dir_pw_build/target_types.gni") 19import("$dir_pw_docgen/docs.gni") 20import("$dir_pw_malloc/backend.gni") 21import("$dir_pw_system/system_target.gni") 22import("$dir_pw_third_party/smartfusion_mss/mss.gni") 23import("$dir_pw_toolchain/generate_toolchain.gni") 24 25config("pw_malloc_active") { 26 if (pw_malloc_BACKEND != "") { 27 defines = [ "PW_MALLOC_ACTIVE=1" ] 28 } 29} 30 31config("emcraft_ddr_init") { 32 # Emcraft's DDR config must be manually set by a custom init function. This 33 # conflicts with the built-in MSS init function. I have not looked into this 34 # myself to see if it's absoutely needed or not. 35 defines = [ "MSS_SYS_MDDR_CONFIG_BY_CORTEX=0" ] 36} 37 38if (current_toolchain != default_toolchain) { 39 pw_linker_script("mddr_debug_linker_script") { 40 defines = [ 41 "PW_BOOT_CODE_BEGIN=0x00000200", # After vector table. 42 43 # TODO(skeys) Bootloader is capable of loading 16M of uncompressed code 44 # from SPI flash to external RAM. For now use the allocated eNVM flash 45 # (256K - Bootloader - InSystemProgrammer = 192K) 46 "PW_BOOT_CODE_SIZE=0x30000", 47 48 # TODO: b/235348465 - Currently "pw_tokenizer/detokenize_test" requires at 49 # least 6K bytes in heap when using pw_malloc:bucket_block_allocator. 50 # The heap size required for tests should be investigated. 51 "PW_BOOT_HEAP_SIZE=4M", 52 53 # With external RAM remapped, we use the entire internal ram for the 54 # stack (64K). 55 "PW_BOOT_MIN_STACK_SIZE=64K", 56 57 # Using external DDR RAM, we just need to make sure we go past our ROM 58 # sections. 59 "PW_BOOT_RAM_BEGIN=0xA1000000", 60 61 # We assume that the bootloader loaded all 16M of text. 62 "PW_BOOT_RAM_SIZE=48M", 63 "PW_BOOT_VECTOR_TABLE_BEGIN=0x00000000", 64 "PW_BOOT_VECTOR_TABLE_SIZE=512", 65 ] 66 linker_script = "emcraft_sf2_som_mddr_debug.ld" 67 } 68 pw_linker_script("mddr_production_linker_script") { 69 defines = [ 70 "PW_BOOT_FLASH_BEGIN=0x00000200", # After vector table. 71 72 # TODO(skeys) Bootloader is capable of loading 16M of uncompressed code 73 # from SPI flash to external RAM. For now use the allocated eNVM flash 74 # (256K - Bootloader - InSystemProgrammer = 192K) 75 "PW_BOOT_FLASH_SIZE=0x30000", 76 77 # TODO: b/235348465 - Currently "pw_tokenizer/detokenize_test" requires at 78 # least 6K bytes in heap when using pw_malloc:bucket_block_allocator. 79 # The heap size required for tests should be investigated. 80 "PW_BOOT_HEAP_SIZE=4M", 81 82 # With external RAM remapped, we use the entire internal ram for the 83 # stack (64K). 84 "PW_BOOT_MIN_STACK_SIZE=1024K", 85 86 # Using external DDR RAM, we just need to make sure we go past our ROM 87 # sections. 88 "PW_BOOT_RAM_BEGIN=0xA1000000", 89 90 # We assume that the bootloader loaded all 16M of text. 91 "PW_BOOT_RAM_SIZE=48M", 92 "PW_BOOT_VECTOR_TABLE_BEGIN=0x00000000", 93 "PW_BOOT_VECTOR_TABLE_SIZE=512", 94 ] 95 linker_script = "$dir_pw_boot_cortex_m/basic_cortex_m.ld" 96 } 97 98 pw_source_set("pre_init") { 99 configs = [ ":pw_malloc_active" ] 100 deps = [ 101 "$dir_pw_boot", 102 "$dir_pw_boot_cortex_m", 103 "$dir_pw_malloc", 104 "$dir_pw_preprocessor", 105 "$dir_pw_string", 106 "$dir_pw_sys_io_emcraft_sf2", 107 "$dir_pw_system", 108 "$dir_pw_third_party/freertos", 109 "$dir_pw_third_party/freertos:support", 110 ] 111 sources = [ 112 "boot.cc", 113 "vector_table.c", 114 ] 115 } 116 117 config("config_includes") { 118 include_dirs = [ "config" ] 119 configs = [ ":emcraft_ddr_init" ] 120 } 121 122 pw_source_set("sf2_mss_hal_config") { 123 public_configs = [ ":config_includes" ] 124 public = 125 [ "config/sf2_mss_hal_conf.h" ] # SKEYS likely want to put the MDDR 126 # config by cortex etc stuff here 127 } 128 129 pw_source_set("sf2_freertos_config") { 130 public_configs = [ ":config_includes" ] 131 public_deps = [ "$dir_pw_third_party/freertos:config_assert" ] 132 public = [ "config/FreeRTOSConfig.h" ] 133 } 134} 135 136# Configured for use with a first stage boot loader to configure DDR and 137# perform memory remapping. 138pw_system_target("emcraft_sf2_som") { 139 cpu = PW_SYSTEM_CPU.CORTEX_M3 140 scheduler = PW_SYSTEM_SCHEDULER.FREERTOS 141 link_deps = [ "$dir_pigweed/targets/emcraft_sf2_som:pre_init" ] 142 143 build_args = { 144 pw_log_BACKEND = dir_pw_log_tokenized 145 pw_log_tokenized_HANDLER_BACKEND = "$dir_pw_system:log_backend.impl" 146 pw_third_party_freertos_CONFIG = 147 "$dir_pigweed/targets/emcraft_sf2_som:sf2_freertos_config" 148 pw_third_party_freertos_PORT = "$dir_pw_third_party/freertos:arm_cm3" 149 pw_sys_io_BACKEND = dir_pw_sys_io_emcraft_sf2 150 151 pw_boot_cortex_m_LINKER_SCRIPT = 152 "//targets/emcraft_sf2_som:mddr_production_linker_script" 153 } 154} 155 156# Debug target configured to work with MSS linker script and startup code. 157# TODO(skeys) Add linker script and config for debug builds using SoftConsole. 158pw_system_target("emcraft_sf2_som_debug") { 159 cpu = PW_SYSTEM_CPU.CORTEX_M3 160 scheduler = PW_SYSTEM_SCHEDULER.FREERTOS 161 link_deps = [ "$dir_pigweed/targets/emcraft_sf2_som:pre_init" ] 162 163 build_args = { 164 pw_log_BACKEND = dir_pw_log_tokenized 165 pw_log_tokenized_HANDLER_BACKEND = "$dir_pw_system:log_backend.impl" 166 pw_third_party_freertos_CONFIG = 167 "$dir_pigweed/targets/emcraft_sf2_som:sf2_freertos_config" 168 pw_third_party_freertos_PORT = "$dir_pw_third_party/freertos:arm_cm3" 169 pw_sys_io_BACKEND = dir_pw_sys_io_emcraft_sf2 170 171 # Override the default pw_boot_cortex_m linker script and set the memory 172 # regions for the target. 173 pw_boot_cortex_m_LINKER_SCRIPT = 174 "//targets/emcraft_sf2_som:mddr_debug_linker_script" 175 pw_third_party_smartfusion_mss_CONFIG = "debug" 176 } 177} 178 179pw_doc_group("docs") { 180 sources = [ "target_docs.rst" ] 181} 182