1// 2// Copyright (C) 2017 The Android Open Source Project 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15// 16 17package { 18 default_applicable_licenses: ["system_core_init_license"], 19} 20 21// Added automatically by a large-scale-change 22// See: http://go/android-license-faq 23license { 24 name: "system_core_init_license", 25 visibility: [":__subpackages__"], 26 license_kinds: [ 27 "SPDX-license-identifier-Apache-2.0", 28 ], 29 license_text: [ 30 "NOTICE", 31 ], 32} 33 34init_common_sources = [ 35 "action.cpp", 36 "action_manager.cpp", 37 "action_parser.cpp", 38 "capabilities.cpp", 39 "epoll.cpp", 40 "import_parser.cpp", 41 "interface_utils.cpp", 42 "interprocess_fifo.cpp", 43 "keychords.cpp", 44 "parser.cpp", 45 "property_type.cpp", 46 "rlimit_parser.cpp", 47 "service.cpp", 48 "service_list.cpp", 49 "service_parser.cpp", 50 "service_utils.cpp", 51 "subcontext.cpp", 52 "subcontext.proto", 53 "tokenizer.cpp", 54 "util.cpp", 55] 56init_device_sources = [ 57 "apex_init_util.cpp", 58 "block_dev_initializer.cpp", 59 "bootchart.cpp", 60 "builtins.cpp", 61 "devices.cpp", 62 "firmware_handler.cpp", 63 "first_stage_console.cpp", 64 "first_stage_init.cpp", 65 "first_stage_mount.cpp", 66 "fscrypt_init_extensions.cpp", 67 "init.cpp", 68 "lmkd_service.cpp", 69 "modalias_handler.cpp", 70 "mount_handler.cpp", 71 "mount_namespace.cpp", 72 "persistent_properties.cpp", 73 "persistent_properties.proto", 74 "property_service.cpp", 75 "property_service.proto", 76 "reboot.cpp", 77 "reboot_utils.cpp", 78 "security.cpp", 79 "selabel.cpp", 80 "selinux.cpp", 81 "sigchld_handler.cpp", 82 "snapuserd_transition.cpp", 83 "switch_root.cpp", 84 "uevent_listener.cpp", 85 "ueventd.cpp", 86 "ueventd_parser.cpp", 87] 88init_host_sources = [ 89 "check_builtins.cpp", 90 "host_import_parser.cpp", 91 "host_init_verifier.cpp", 92] 93 94soong_config_module_type { 95 name: "libinit_cc_defaults", 96 module_type: "cc_defaults", 97 config_namespace: "ANDROID", 98 bool_variables: [ 99 "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT", 100 ], 101 properties: [ 102 "cflags", 103 ], 104} 105 106libinit_cc_defaults { 107 name: "init_defaults", 108 sanitize: { 109 misc_undefined: ["signed-integer-overflow"], 110 }, 111 cflags: [ 112 "-DALLOW_FIRST_STAGE_CONSOLE=0", 113 "-DALLOW_LOCAL_PROP_OVERRIDE=0", 114 "-DALLOW_PERMISSIVE_SELINUX=0", 115 "-DANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION", 116 "-DDUMP_ON_UMOUNT_FAILURE=0", 117 "-DINIT_FULL_SOURCES", 118 "-DINSTALL_DEBUG_POLICY_TO_SYSTEM_EXT=0", 119 "-DLOG_UEVENTS=0", 120 "-DREBOOT_BOOTLOADER_ON_PANIC=0", 121 "-DSHUTDOWN_ZERO_TIMEOUT=0", 122 "-DWORLD_WRITABLE_KMSG=0", 123 "-Wall", 124 "-Werror", 125 "-Wextra", 126 "-Wno-unused-parameter", 127 "-Wthread-safety", 128 ], 129 product_variables: { 130 debuggable: { 131 cppflags: [ 132 "-UALLOW_FIRST_STAGE_CONSOLE", 133 "-DALLOW_FIRST_STAGE_CONSOLE=1", 134 "-UALLOW_LOCAL_PROP_OVERRIDE", 135 "-DALLOW_LOCAL_PROP_OVERRIDE=1", 136 "-UALLOW_PERMISSIVE_SELINUX", 137 "-DALLOW_PERMISSIVE_SELINUX=1", 138 "-UREBOOT_BOOTLOADER_ON_PANIC", 139 "-DREBOOT_BOOTLOADER_ON_PANIC=1", 140 "-UWORLD_WRITABLE_KMSG", 141 "-DWORLD_WRITABLE_KMSG=1", 142 "-UDUMP_ON_UMOUNT_FAILURE", 143 "-DDUMP_ON_UMOUNT_FAILURE=1", 144 ], 145 }, 146 eng: { 147 cppflags: [ 148 "-USHUTDOWN_ZERO_TIMEOUT", 149 "-DSHUTDOWN_ZERO_TIMEOUT=1", 150 ], 151 }, 152 uml: { 153 cppflags: ["-DUSER_MODE_LINUX"], 154 }, 155 }, 156 soong_config_variables: { 157 PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT: { 158 cflags: [ 159 "-UINSTALL_DEBUG_POLICY_TO_SYSTEM_EXT", 160 "-DINSTALL_DEBUG_POLICY_TO_SYSTEM_EXT=1", 161 ], 162 }, 163 }, 164 static_libs: [ 165 "libavb", 166 "libbootloader_message", 167 "libc++fs", 168 "libcgrouprc_format", 169 "libfsverity_init", 170 "liblmkd_utils", 171 "liblz4", 172 "libmini_keyctl_static", 173 "libmodprobe", 174 "libprocinfo", 175 "libprotobuf-cpp-lite", 176 "libpropertyinfoserializer", 177 "libpropertyinfoparser", 178 "libsigningutils", 179 "libsnapshot_cow", 180 "libsnapshot_init", 181 "libxml2", 182 "lib_apex_manifest_proto_lite", 183 "update_metadata-protos", 184 ], 185 shared_libs: [ 186 "libbase", 187 "libcrypto", 188 "libcutils", 189 "libdl", 190 "libext4_utils", 191 "libfs_mgr", 192 "libgsi", 193 "libhidl-gen-utils", 194 "libkeyutils", 195 "liblog", 196 "liblogwrap", 197 "liblp", 198 "libprocessgroup", 199 "libprocessgroup_setup", 200 "libselinux", 201 "libunwindstack", 202 "libutils", 203 "libziparchive", 204 ], 205 header_libs: ["bionic_libc_platform_headers"], 206 bootstrap: true, 207 visibility: [":__subpackages__"], 208} 209 210cc_library_headers { 211 name: "libinit_headers", 212 export_include_dirs: ["."], 213 visibility: [":__subpackages__"], 214} 215 216cc_library_static { 217 name: "libinit", 218 recovery_available: true, 219 defaults: [ 220 "init_defaults", 221 "selinux_policy_version", 222 ], 223 srcs: init_common_sources + init_device_sources, 224 export_include_dirs: ["."], 225 generated_sources: [ 226 "apex-info-list", 227 ], 228 whole_static_libs: [ 229 "libcap", 230 "libcom.android.sysprop.apex", 231 "libcom.android.sysprop.init", 232 ], 233 header_libs: ["bootimg_headers"], 234 proto: { 235 type: "lite", 236 export_proto_headers: true, 237 }, 238 239 target: { 240 recovery: { 241 cflags: ["-DRECOVERY"], 242 exclude_static_libs: [ 243 "libxml2", 244 ], 245 exclude_generated_sources: [ 246 "apex-info-list", 247 ], 248 exclude_shared_libs: [ 249 "libbinder", 250 "libutils", 251 ], 252 }, 253 }, 254 visibility: [ 255 "//system/apex/apexd", 256 "//frameworks/native/cmds/installd", 257 ], 258} 259 260phony { 261 name: "init", 262 required: [ 263 "init_second_stage", 264 ], 265} 266 267cc_binary { 268 name: "init_second_stage", 269 recovery_available: true, 270 stem: "init", 271 defaults: ["init_defaults"], 272 static_libs: ["libinit"], 273 srcs: ["main.cpp"], 274 symlinks: ["ueventd"], 275 target: { 276 platform: { 277 required: [ 278 "init.rc", 279 "ueventd.rc", 280 "e2fsdroid", 281 "extra_free_kbytes", 282 "make_f2fs", 283 "mke2fs", 284 "sload_f2fs", 285 ], 286 }, 287 recovery: { 288 cflags: ["-DRECOVERY"], 289 exclude_static_libs: [ 290 "libxml2", 291 ], 292 exclude_shared_libs: [ 293 "libbinder", 294 "libutils", 295 ], 296 required: [ 297 "init_recovery.rc", 298 "ueventd.rc.recovery", 299 "e2fsdroid.recovery", 300 "make_f2fs.recovery", 301 "mke2fs.recovery", 302 "sload_f2fs.recovery", 303 ], 304 }, 305 }, 306 visibility: ["//packages/modules/Virtualization/microdroid"], 307} 308 309soong_config_module_type { 310 name: "init_first_stage_cc_defaults", 311 module_type: "cc_defaults", 312 config_namespace: "ANDROID", 313 bool_variables: ["BOARD_USES_RECOVERY_AS_BOOT"], 314 properties: ["installable"], 315} 316 317// Do not install init_first_stage even with mma if we're system-as-root. 318// Otherwise, it will overwrite the symlink. 319init_first_stage_cc_defaults { 320 name: "init_first_stage_defaults", 321 soong_config_variables: { 322 BOARD_USES_RECOVERY_AS_BOOT: { 323 installable: false, 324 }, 325 }, 326} 327 328cc_binary { 329 name: "init_first_stage", 330 stem: "init", 331 defaults: ["init_first_stage_defaults"], 332 333 srcs: [ 334 "block_dev_initializer.cpp", 335 "devices.cpp", 336 "first_stage_console.cpp", 337 "first_stage_init.cpp", 338 "first_stage_main.cpp", 339 "first_stage_mount.cpp", 340 "reboot_utils.cpp", 341 "selabel.cpp", 342 "service_utils.cpp", 343 "snapuserd_transition.cpp", 344 "switch_root.cpp", 345 "uevent_listener.cpp", 346 "util.cpp", 347 ], 348 349 static_libs: [ 350 "libc++fs", 351 "libfs_avb", 352 "libfs_mgr", 353 "libfec", 354 "libfec_rs", 355 "libsquashfs_utils", 356 "libcrypto_utils", 357 "libavb", 358 "liblp", 359 "libcutils", 360 "libbase", 361 "liblog", 362 "libcrypto_static", 363 "libselinux", 364 "libcap", 365 "libgsi", 366 "liblzma", 367 "libunwindstack_no_dex", 368 "libmodprobe", 369 "libext2_uuid", 370 "libprotobuf-cpp-lite", 371 "libsnapshot_cow", 372 "liblz4", 373 "libsnapshot_init", 374 "update_metadata-protos", 375 "libprocinfo", 376 ], 377 378 static_executable: true, 379 system_shared_libs: [], 380 381 cflags: [ 382 "-Wall", 383 "-Wextra", 384 "-Wno-unused-parameter", 385 "-Werror", 386 "-DALLOW_FIRST_STAGE_CONSOLE=0", 387 "-DALLOW_LOCAL_PROP_OVERRIDE=0", 388 "-DALLOW_PERMISSIVE_SELINUX=0", 389 "-DREBOOT_BOOTLOADER_ON_PANIC=0", 390 "-DWORLD_WRITABLE_KMSG=0", 391 "-DDUMP_ON_UMOUNT_FAILURE=0", 392 "-DSHUTDOWN_ZERO_TIMEOUT=0", 393 "-DLOG_UEVENTS=0", 394 "-DSEPOLICY_VERSION=30", // TODO(jiyong): externalize the version number 395 ], 396 397 product_variables: { 398 debuggable: { 399 cflags: [ 400 "-UALLOW_FIRST_STAGE_CONSOLE", 401 "-DALLOW_FIRST_STAGE_CONSOLE=1", 402 403 "-UALLOW_LOCAL_PROP_OVERRIDE", 404 "-DALLOW_LOCAL_PROP_OVERRIDE=1", 405 406 "-UALLOW_PERMISSIVE_SELINUX", 407 "-DALLOW_PERMISSIVE_SELINUX=1", 408 409 "-UREBOOT_BOOTLOADER_ON_PANIC", 410 "-DREBOOT_BOOTLOADER_ON_PANIC=1", 411 412 "-UWORLD_WRITABLE_KMSG", 413 "-DWORLD_WRITABLE_KMSG=1", 414 415 "-UDUMP_ON_UMOUNT_FAILURE", 416 "-DDUMP_ON_UMOUNT_FAILURE=1", 417 ], 418 }, 419 420 eng: { 421 cflags: [ 422 "-USHUTDOWN_ZERO_TIMEOUT", 423 "-DSHUTDOWN_ZERO_TIMEOUT=1", 424 ], 425 }, 426 }, 427 428 sanitize: { 429 misc_undefined: ["signed-integer-overflow"], 430 431 // First stage init is weird: it may start without stdout/stderr, and no /proc. 432 hwaddress: false, 433 }, 434 435 // Install adb_debug.prop into debug ramdisk. 436 // This allows adb root on a user build, when debug ramdisk is used. 437 required: ["adb_debug.prop"], 438 439 ramdisk: true, 440 441 install_in_root: true, 442} 443 444phony { 445 name: "init_system", 446 required: ["init_second_stage"], 447} 448 449// Tests 450// ------------------------------------------------------------------------------ 451 452cc_test { 453 name: "CtsInitTestCases", 454 defaults: ["init_defaults"], 455 require_root: true, 456 457 compile_multilib: "first", 458 459 srcs: [ 460 "devices_test.cpp", 461 "epoll_test.cpp", 462 "firmware_handler_test.cpp", 463 "init_test.cpp", 464 "interprocess_fifo_test.cpp", 465 "keychords_test.cpp", 466 "oneshot_on_test.cpp", 467 "persistent_properties_test.cpp", 468 "property_service_test.cpp", 469 "property_type_test.cpp", 470 "reboot_test.cpp", 471 "rlimit_parser_test.cpp", 472 "service_test.cpp", 473 "subcontext_test.cpp", 474 "tokenizer_test.cpp", 475 "ueventd_parser_test.cpp", 476 "ueventd_test.cpp", 477 "util_test.cpp", 478 ], 479 static_libs: [ 480 "libgmock", 481 "libinit", 482 ], 483 484 test_suites: [ 485 "cts", 486 "device-tests", 487 ], 488} 489 490cc_benchmark { 491 name: "init_benchmarks", 492 defaults: ["init_defaults"], 493 srcs: [ 494 "subcontext_benchmark.cpp", 495 ], 496 static_libs: ["libinit"], 497} 498 499cc_defaults { 500 name: "libinit_test_utils_libraries_defaults", 501 shared_libs: [ 502 "libbase", 503 "libcutils", 504 "libselinux", 505 "liblog", 506 "libprocessgroup", 507 "libprotobuf-cpp-lite", 508 ], 509 static_libs: [ 510 "libhidl-gen-utils", 511 ], 512} 513 514cc_library_static { 515 name: "libinit_test_utils", 516 defaults: ["libinit_test_utils_libraries_defaults"], 517 cflags: [ 518 "-Wall", 519 "-Wextra", 520 "-Wno-unused-parameter", 521 "-Werror", 522 ], 523 srcs: init_common_sources + [ 524 "test_utils/service_utils.cpp", 525 ], 526 whole_static_libs: [ 527 "libcap", 528 ], 529 export_include_dirs: ["test_utils/include"], // for tests 530 header_libs: ["bionic_libc_platform_headers"], 531} 532 533// Host Verifier 534// ------------------------------------------------------------------------------ 535 536genrule { 537 name: "generated_stub_builtin_function_map", 538 tool_files: ["host_builtin_map.py"], 539 out: ["generated_stub_builtin_function_map.h"], 540 srcs: [ 541 "builtins.cpp", 542 "check_builtins.cpp", 543 ], 544 cmd: "$(location host_builtin_map.py) --builtins $(location builtins.cpp) --check_builtins $(location check_builtins.cpp) > $(out)", 545} 546 547cc_defaults { 548 name: "init_host_defaults", 549 host_supported: true, 550 cflags: [ 551 "-Wall", 552 "-Wextra", 553 "-Wno-unused-parameter", 554 "-Werror", 555 ], 556 static_libs: [ 557 "libbase", 558 "libselinux", 559 "libpropertyinfoserializer", 560 "libpropertyinfoparser", 561 ], 562 whole_static_libs: ["libcap"], 563 shared_libs: [ 564 "libcutils", 565 "libhidl-gen-utils", 566 "libhidlmetadata", 567 "liblog", 568 "libprocessgroup", 569 "libprotobuf-cpp-lite", 570 ], 571 proto: { 572 type: "lite", 573 }, 574 generated_headers: [ 575 "generated_stub_builtin_function_map", 576 "generated_android_ids", 577 ], 578 target: { 579 android: { 580 enabled: false, 581 }, 582 darwin: { 583 enabled: false, 584 }, 585 }, 586} 587 588cc_binary { 589 name: "host_init_verifier", 590 defaults: ["init_host_defaults"], 591 srcs: init_common_sources + init_host_sources, 592} 593 594cc_library_host_static { 595 name: "libinit_host", 596 defaults: ["init_host_defaults"], 597 srcs: init_common_sources, 598 export_include_dirs: ["."], 599 proto: { 600 export_proto_headers: true, 601 }, 602 visibility: [ 603 // host_apex_verifier performs a subset of init.rc validation 604 "//system/apex/tools", 605 ], 606} 607 608sh_binary { 609 name: "extra_free_kbytes", 610 src: "extra_free_kbytes.sh", 611 filename_from_src: true, 612} 613