1# Copyright (C) 2019 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://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, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15#=============================================================================== 16# 17# CHRE builder scons 18# 19# GENERAL DESCRIPTION 20# Build script used to build the CHRE library for use on SLPI 21# 22#------------------------------------------------------------------------------- 23 24Import('env') 25import os 26 27#------------------------------------------------------------------------------- 28# Configure optional features 29#------------------------------------------------------------------------------- 30 31# There are two options to configure the optional features that CHRE bundles in: 32# 1. Set the flags below to True/False depending on which features are desired 33# 2. Set the command-line flag -f USES_CHRE_BUILD_FLAGS to ignore the defaults 34# and control the features by presence of -f USES_CHRE_WIFI, etc. in the 35# command line flags 36USE_CHRE_AUDIO = False # not currently supported 37if 'USES_CHRE_BUILD_FLAGS' not in env: 38 # Option 1 39 USE_CHRE_GNSS = True 40 USE_CHRE_WIFI = True 41 USE_CHRE_WWAN = True 42else: 43 # Option 2 44 USE_CHRE_GNSS = 'USES_CHRE_GNSS' in env 45 USE_CHRE_WIFI = 'USES_CHRE_WIFI' in env 46 USE_CHRE_WWAN = 'USES_CHRE_WWAN' in env 47 48#------------------------------------------------------------------------------- 49# Configure testing nanoapps 50#------------------------------------------------------------------------------- 51 52# CHRE provides several nanoapps that can be used to verify that APIs are 53# working as expected. To use these nanoapps, set 1 or more of the following 54# flags to True and recompile CHRE. Once restarted, CHRE will load the enabled 55# nanoapps 56LOAD_GNSS_WORLD = False 57LOAD_SENSOR_WORLD = False 58LOAD_WIFI_WORLD = False 59LOAD_WWAN_WORLD = False 60 61TESTING_NANOAPPS_ENABLED = False 62if LOAD_GNSS_WORLD or LOAD_SENSOR_WORLD or LOAD_WIFI_WORLD or LOAD_WWAN_WORLD: 63 TESTING_NANOAPPS_ENABLED = True 64 65#------------------------------------------------------------------------------- 66# Setup source and tooling paths 67#------------------------------------------------------------------------------- 68SRCPATH = "${BUILD_ROOT}/chre/chre/src" 69LIBNAME = 'libchre_slpi_skel' 70env.VariantDir('${BUILDPATH}', SRCPATH, duplicate=0) 71LIB_ROOT = "${BUILD_ROOT}/chre/chre" 72 73target_so = '${BUILDPATH}/'+LIBNAME+'.so' 74hexagon_root = env.get('HEXAGON_ROOT') 75hexgaon_rtos_release = env.get('HEXAGON_RTOS_RELEASE') 76hexagon_version = env.get('Q6VERSION') 77HEXAGON_LIB_PATH = "{0}/{1}/Tools/target/hexagon/lib/{2}/G0/pic".format(hexagon_root, 78 hexgaon_rtos_release,hexagon_version) 79 80#------------------------------------------------------------------------------- 81# Setup various env flags 82#------------------------------------------------------------------------------- 83env.Replace(ASM_DFLAGS = '-D__V_DYNAMIC__') 84env.Replace(CC_DFLAGS = '-D__V_DYNAMIC__') 85env.Replace(HEXAGONCC_OPT = ' -Os ') 86env.Replace(CFLAGS = ' -G0') 87 88env.Replace(HEXAGONCC_WARN = '-Wall -Wno-cast-align -Wpointer-arith -Wno-missing-braces' \ 89 ' -Wno-strict-aliasing -Wstrict-prototypes -Wnested-externs -Werror') 90env.Replace(HEXAGON_UNDEF = ' ') 91env.Replace(HEXAGON_LANIND = '-fno-exceptions -fno-strict-aliasing -fno-zero-initialized-in-bss' \ 92 ' -fdata-sections -fno-signed-char -fdiagnostics-show-option ') 93env.Append(SHCXXFLAGS = ' -std=c++11 ') 94env.Append(SHLINKFLAGS = '-G0 --wrap=malloc --wrap=calloc --wrap=free --wrap=realloc --wrap=memalign' \ 95 ' --wrap=__stack_chk_fail -call_shared ') 96 97env['SKEL_DEP'] = '' 98if USE_CHRE_GNSS: 99 env['SKEL_DEP'] += ' ${BUILD_ROOT}/chre/chre_drv_loc/build/${BUILDPATH}/chre_drv_loc.so ' 100 env.Depends(target_so,'${BUILD_ROOT}/chre/chre_drv_loc/build/${BUILDPATH}/chre_drv_loc.so') 101 102if USE_CHRE_WIFI: 103 env['SKEL_DEP'] += ' ${BUILD_ROOT}/chre/chre_drv_wifi/build/${BUILDPATH}/chre_drv_wifi.so ' \ 104 ' ${BUILD_ROOT}/chre/lowi_client/build/${BUILDPATH}/lowi_client.so ' 105 env.Depends(target_so,'${BUILD_ROOT}/chre/chre_drv_wifi/build/${BUILDPATH}/chre_drv_wifi.so') 106 env.Depends(target_so,'${BUILD_ROOT}/chre/lowi_client/build/${BUILDPATH}/lowi_client.so') 107 108if USE_CHRE_WWAN: 109 env['SKEL_DEP'] += ' ${BUILD_ROOT}/chre/chre_drv_modem/build/${BUILDPATH}/chre_drv_modem.so ' 110 env.Depends(target_so,'${BUILD_ROOT}/chre/chre_drv_modem/build/${BUILDPATH}/chre_drv_modem.so') 111 112env.Replace(QDSP6OBJS1= '${QDSP6_RELEASE_DIR}/Tools/target/hexagon/lib/${Q6VERSION}/G0/pic/initS.o') 113env.Replace(QDSP6OBJS3= ['${QDSP6_RELEASE_DIR}/Tools/target/hexagon/lib/${Q6VERSION}/G0/pic/libgcc.a', 114 '${QDSP6_RELEASE_DIR}/Tools/target/hexagon/lib/${Q6VERSION}/G0/pic/libstdc++.a', 115 '${QDSP6_RELEASE_DIR}/Tools/target/hexagon/lib/${Q6VERSION}/G0/pic/libc++.a']) 116env.Replace(QDSP6OBJS4= '${QDSP6_RELEASE_DIR}/Tools/target/hexagon/lib/${Q6VERSION}/G0/pic/finiS.o') 117 118env['SHLINKGRP'] = ' -shared -fPIC -Bsymbolic --start-group $QDSP6OBJS1 $QDSP6OBJS3 $SOURCES.posix' \ 119 ' $QDSP6OBJS4 $SKEL_DEP --end-group ${HEXAGONLD_MAP_CMD} ${TARGET.posix}.map' 120 121# Tells SCons to link various shared libraries against the CHRE library (drivers, various Hexagon libraries). 122env.Replace(SHLINKCOM="${TEMPFILE('$SHLINK $SHLINKFLAGS $HEXAGON_OUTPUT_CMD $TARGET.posix $SHLINKGRP')}") 123 124#------------------------------------------------------------------------------- 125# Ensure required libraries are available to the CHRE source code 126#------------------------------------------------------------------------------- 127core_public_apis = [ 128 'KERNEL', 129 'SERVICES', 130 'DEBUGTOOLS', 131 'ADSPPM', 132 'POWER', 133 'MPROC', 134 'SYSTEMDRIVERS', 135 'DEBUGTRACE', 136 'DAL', 137 'DIAG', 138 'BUSES', 139] 140 141platform_public_apis = [ 142 'PLATFORM_LIBS', 143 'MOD_TABLE', 144 'QAIC', 145 'STDDEF', 146 'REMOTE', 147 'HAPSDK', 148 'DLW', 149 'PLS', 150 'UTILS', 151 'ADSP_MMAP', 152 'A1STD', 153 'RTLD', 154] 155 156qmimsgs_public_apis = [ 157 'COMMON', 158 'SNS_CLIENT_API', 159] 160 161chre_priv_api = [ 162 "${BUILD_ROOT}/chre/chre/src/system/chre/chre_api/include", 163 "${BUILD_ROOT}/chre/chre/src/system/chre/chre_api/include/chre_api", 164 "${BUILD_ROOT}/chre/chre/src/system/chre/core/include", 165 "${BUILD_ROOT}/chre/chre/src/system/chre/external/flatbuffers/include", 166 "${BUILD_ROOT}/chre/chre/src/system/chre/pal/include", 167 "${BUILD_ROOT}/chre/chre/src/system/chre/platform/include", 168 "${BUILD_ROOT}/chre/chre/src/system/chre/platform/shared/include", 169 "${BUILD_ROOT}/chre/chre/src/system/chre/platform/slpi", 170 "${BUILD_ROOT}/chre/chre/src/system/chre/platform/slpi/include", 171 "${BUILD_ROOT}/chre/chre/src/system/chre/platform/slpi/see/include", 172 "${BUILD_ROOT}/chre/chre/src/system/chre/util/include", 173 "${BUILD_ROOT}/core/api/kernel/libstd/stringl", 174 "${BUILD_ROOT}/qmimsgs/common/api", 175 "${BUILD_ROOT}/ssc_api/pb", 176 "${BUILD_ROOT}/ssc/framework/cm/inc", 177 "${BUILD_ROOT}/ssc/inc", 178 "${BUILD_ROOT}/ssc/inc/internal", 179 "${BUILD_ROOT}/ssc/inc/utils/nanopb", 180] 181 182if TESTING_NANOAPPS_ENABLED: 183 chre_priv_api.append("${BUILD_ROOT}/chre/chre/src/system/chre/apps/include") 184 185env.PublishPrivateApi('CHRE', chre_priv_api) 186 187env.RequirePublicApi(core_public_apis, area='core') 188env.RequirePublicApi(platform_public_apis, area='platform') 189env.RequirePublicApi(qmimsgs_public_apis, area='qmimsgs') 190env.RequirePublicApi(['SNS_API_INCLUDES'], area='ssc_api') 191env.RequirePrivateApi('CHRE') 192 193#------------------------------------------------------------------------------- 194# Define various preprocessor definitions needed to compile CHRE 195#------------------------------------------------------------------------------- 196 197oem_ver = os.environ.get('SCONS_OEM_BUILD_VER') 198if oem_ver is not None: 199 oem_ver = str(oem_ver).strip().strip('"') 200else: 201 oem_ver = 'undefined' 202 203CHRE_DEFINES = [ 204 'CHRE_SLPI_DEFAULT_BUILD', 205 'CHRE_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_DEBUG', 206 'NANOAPP_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_DEBUG', 207 'CHRE_ASSERTIONS_DISABLED', 208 'CHRE_NANOAPP_INTERNAL', 209 'CHRE_VERSION_STRING=\\\"' + oem_ver + '\\\"', 210 'CHRE_PATCH_VERSION=1', 211 'CHRE_FILENAME=__FILE__', 212 'CHRE_PLATFORM_ID=0x476f6f676c000005', 213 'CHRE_SEE_NUM_TEMP_SENSORS=1', 214 'FLATBUFFERS_CHRE', 215 'SSC_TARGET_HEXAGON', 216 'CHRE_SLPI_SEE', 217 'PB_FIELD_16BIT', 218 'CHRE_MESSAGE_TO_HOST_MAX_SIZE=4000', 219 'QDSP6', 220 'CHRE_USE_FARF_LOGGING', 221] 222 223if USE_CHRE_GNSS: 224 CHRE_DEFINES.append('CHRE_GNSS_SUPPORT_ENABLED') 225if USE_CHRE_WIFI: 226 CHRE_DEFINES.append('CHRE_WIFI_SUPPORT_ENABLED') 227if USE_CHRE_WWAN: 228 CHRE_DEFINES.append('CHRE_WWAN_SUPPORT_ENABLED') 229 230if TESTING_NANOAPPS_ENABLED: 231 CHRE_DEFINES.append('CHRE_INCLUDE_DEFAULT_STATIC_NANOAPPS') 232if LOAD_GNSS_WORLD: 233 CHRE_DEFINES.append('CHRE_LOAD_GNSS_WORLD') 234if LOAD_SENSOR_WORLD: 235 CHRE_DEFINES.append('CHRE_LOAD_SENSOR_WORLD') 236if LOAD_WIFI_WORLD: 237 CHRE_DEFINES.append('CHRE_LOAD_WIFI_WORLD') 238if LOAD_WWAN_WORLD: 239 CHRE_DEFINES.append('CHRE_LOAD_WWAN_WORLD') 240 241env.Append(CPPDEFINES = CHRE_DEFINES) 242 243#------------------------------------------------------------------------------- 244# Setup source files to be built 245#------------------------------------------------------------------------------- 246 247# Define path to the IDL file used to communicate with the host via FastRPC 248libchre_slpi_skel_idl = "${BUILDPATH}/system/chre/host/msm/daemon/idl/chre_slpi.idl" 249 250# Compile chre_slpi.h from chre_slpi.idl, This is a prereq for the libchre_slpi_skel.so 251prereq = env.HeaderBuilder("${BUILDPATH}/chre_slpi.h", libchre_slpi_skel_idl) 252 253chre_cc_src = [ 254 # QMI interfaces 255 "${BUILD_ROOT}/qmimsgs/common/src/common_v01.c", 256 "${BUILD_ROOT}/qmimsgs/sns_client_api/src/sns_client_api_v01.c", 257 258 # Qualcomm protobufs needed by CHRE code 259 "${BUILD_ROOT}/ssc_api/build/${BUILDPATH}/pb/sns_amd.pb.c", 260 "${BUILD_ROOT}/ssc_api/build/${BUILDPATH}/pb/sns_client.pb.c", 261 "${BUILD_ROOT}/ssc_api/build/${BUILDPATH}/pb/sns_suid.pb.c", 262 "${BUILD_ROOT}/ssc_api/build/${BUILDPATH}/pb/sns_cal.pb.c", 263 "${BUILD_ROOT}/ssc_api/build/${BUILDPATH}/pb/sns_physical_sensor_test.pb.c", 264 "${BUILD_ROOT}/ssc_api/build/${BUILDPATH}/pb/sns_proximity.pb.c", 265 "${BUILD_ROOT}/ssc_api/build/${BUILDPATH}/pb/sns_remote_proc_state.pb.c", 266 "${BUILD_ROOT}/ssc_api/build/${BUILDPATH}/pb/sns_resampler.pb.c", 267 "${BUILD_ROOT}/ssc_api/build/${BUILDPATH}/pb/sns_std.pb.c", 268 "${BUILD_ROOT}/ssc_api/build/${BUILDPATH}/pb/sns_std_sensor.pb.c", 269 "${BUILD_ROOT}/ssc_api/build/${BUILDPATH}/pb/sns_std_type.pb.c", 270 271 # Core CHRE framework code 272 "${BUILDPATH}/system/chre/core/debug_dump_manager.cc", 273 "${BUILDPATH}/system/chre/core/event.cc", 274 "${BUILDPATH}/system/chre/core/event_loop.cc", 275 "${BUILDPATH}/system/chre/core/event_loop_manager.cc", 276 "${BUILDPATH}/system/chre/core/event_ref_queue.cc", 277 "${BUILDPATH}/system/chre/core/host_comms_manager.cc", 278 "${BUILDPATH}/system/chre/core/init.cc", 279 "${BUILDPATH}/system/chre/core/nanoapp.cc", 280 "${BUILDPATH}/system/chre/core/sensor_request.cc", 281 "${BUILDPATH}/system/chre/core/sensor_request_manager.cc", 282 "${BUILDPATH}/system/chre/core/sensor_request_multiplexer.cc", 283 "${BUILDPATH}/system/chre/core/sensor.cc", 284 "${BUILDPATH}/system/chre/core/sensor_type.cc", 285 "${BUILDPATH}/system/chre/core/sensor_type_helpers.cc", 286 "${BUILDPATH}/system/chre/core/static_nanoapps.cc", 287 "${BUILDPATH}/system/chre/core/timer_pool.cc", 288 289 # CHRE platform-specific implementation 290 "${BUILDPATH}/system/chre/platform/shared/chre_api_audio.cc", 291 "${BUILDPATH}/system/chre/platform/shared/chre_api_core.cc", 292 "${BUILDPATH}/system/chre/platform/shared/chre_api_gnss.cc", 293 "${BUILDPATH}/system/chre/platform/shared/chre_api_re.cc", 294 "${BUILDPATH}/system/chre/platform/shared/chre_api_sensor.cc", 295 "${BUILDPATH}/system/chre/platform/shared/chre_api_version.cc", 296 "${BUILDPATH}/system/chre/platform/shared/chre_api_wifi.cc", 297 "${BUILDPATH}/system/chre/platform/shared/chre_api_wwan.cc", 298 "${BUILDPATH}/system/chre/platform/shared/host_protocol_chre.cc", 299 "${BUILDPATH}/system/chre/platform/shared/host_protocol_common.cc", 300 "${BUILDPATH}/system/chre/platform/shared/memory_manager.cc", 301 "${BUILDPATH}/system/chre/platform/shared/nanoapp_load_manager.cc", 302 "${BUILDPATH}/system/chre/platform/shared/nanoapp/nanoapp_dso_util.cc", 303 "${BUILDPATH}/system/chre/platform/shared/pal_system_api.cc", 304 "${BUILDPATH}/system/chre/platform/shared/system_time.cc", 305 "${BUILDPATH}/system/chre/platform/slpi/chre_api_re.cc", 306 "${BUILDPATH}/system/chre/platform/slpi/host_link.cc", 307 "${BUILDPATH}/system/chre/platform/slpi/init.cc", 308 "${BUILDPATH}/system/chre/platform/slpi/memory.cc", 309 "${BUILDPATH}/system/chre/platform/slpi/memory_manager.cc", 310 "${BUILDPATH}/system/chre/platform/slpi/platform_debug_dump_manager.cc", 311 "${BUILDPATH}/system/chre/platform/slpi/platform_nanoapp.cc", 312 "${BUILDPATH}/system/chre/platform/slpi/platform_pal.cc", 313 "${BUILDPATH}/system/chre/platform/slpi/platform_sensor_type_helpers.cc", 314 "${BUILDPATH}/system/chre/platform/slpi/system_time.cc", 315 "${BUILDPATH}/system/chre/platform/slpi/system_time_util.cc", 316 "${BUILDPATH}/system/chre/platform/slpi/system_timer.cc", 317 "${BUILDPATH}/system/chre/platform/slpi/see/island_vote_client.cc", 318 "${BUILDPATH}/system/chre/platform/slpi/see/platform_sensor.cc", 319 "${BUILDPATH}/system/chre/platform/slpi/see/platform_sensor_manager.cc", 320 "${BUILDPATH}/system/chre/platform/slpi/see/power_control_manager.cc", 321 "${BUILDPATH}/system/chre/platform/slpi/see/see_helper.cc", 322 "${BUILDPATH}/system/chre/platform/slpi/see/see_cal_helper.cc", 323 "${BUILDPATH}/system/chre/platform/slpi/see/sns_qmi_client.c", 324 325 # Common utilities 326 "${BUILDPATH}/system/chre/util/system/debug_dump.cc", 327 "${BUILDPATH}/system/chre/util/buffer_base.cc", 328 "${BUILDPATH}/system/chre/util/dynamic_vector_base.cc", 329 "${BUILDPATH}/system/chre/util/nanoapp/audio.cc", 330 "${BUILDPATH}/system/chre/util/nanoapp/callbacks.cc", 331 "${BUILDPATH}/system/chre/util/nanoapp/debug.cc", 332 "${BUILDPATH}/system/chre/util/nanoapp/wifi.cc", 333] 334 335if USE_CHRE_AUDIO: 336 chre_cc_src.extend([ 337 "${BUILDPATH}/system/chre/core/audio_request_manager.cc", 338 "${BUILDPATH}/system/chre/platform/slpi/platform_audio.cc", 339 ]) 340 341if USE_CHRE_GNSS: 342 chre_cc_src.extend([ 343 "${BUILDPATH}/system/chre/core/gnss_manager.cc", 344 "${BUILDPATH}/system/chre/platform/shared/platform_gnss.cc", 345 ]) 346 347if USE_CHRE_WIFI: 348 chre_cc_src.extend([ 349 "${BUILDPATH}/system/chre/core/wifi_request_manager.cc", 350 "${BUILDPATH}/system/chre/core/wifi_scan_request.cc", 351 "${BUILDPATH}/system/chre/platform/shared/platform_wifi.cc", 352 ]) 353 354if USE_CHRE_WWAN: 355 chre_cc_src.extend([ 356 "${BUILDPATH}/system/chre/core/wwan_request_manager.cc", 357 "${BUILDPATH}/system/chre/platform/shared/platform_wwan.cc", 358 ]) 359 360if LOAD_GNSS_WORLD: 361 chre_cc_src.append("${BUILDPATH}/system/chre/apps/gnss_world/gnss_world.cc") 362if LOAD_SENSOR_WORLD: 363 chre_cc_src.append("${BUILDPATH}/system/chre/apps/sensor_world/sensor_world.cc") 364if LOAD_WIFI_WORLD: 365 chre_cc_src.append("${BUILDPATH}/system/chre/apps/wifi_world/wifi_world.cc") 366if LOAD_WWAN_WORLD: 367 chre_cc_src.append("${BUILDPATH}/system/chre/apps/wwan_world/wwan_world.cc") 368 369#------------------------------------------------------------------------------- 370# Add CHRE as a shared library that should be built 371#------------------------------------------------------------------------------- 372 373target = env.AddMySharedLibrary(['ADSP_SHARED_LIBS'], '${BUILDPATH}/'+LIBNAME, chre_cc_src, libchre_slpi_skel_idl) 374env.Requires(target, prereq) 375 376# Clean / pack rules 377CLEAN_LIST=[] 378CLEAN_LIST.extend(env.FindFiles(['*'], LIB_ROOT + '/inc')) 379CLEAN_LIST.extend(env.FindFiles(['*'], LIB_ROOT + '/src')) 380env.CleanPack(['ADSP_SHARED_LIBS'], CLEAN_LIST) 381