xref: /aosp_15_r20/system/core/init/Android.bp (revision 00c7fec1bb09f3284aad6a6f96d2f63dfc3650ad)
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    "interprocess_fifo.cpp",
42    "keychords.cpp",
43    "parser.cpp",
44    "property_type.cpp",
45    "rlimit_parser.cpp",
46    "service.cpp",
47    "service_list.cpp",
48    "service_parser.cpp",
49    "service_utils.cpp",
50    "subcontext.cpp",
51    "subcontext.proto",
52    "tokenizer.cpp",
53    "util.cpp",
54]
55init_device_sources = [
56    "apex_init_util.cpp",
57    "block_dev_initializer.cpp",
58    "bootchart.cpp",
59    "builtins.cpp",
60    "devices.cpp",
61    "firmware_handler.cpp",
62    "first_stage_console.cpp",
63    "first_stage_init.cpp",
64    "first_stage_mount.cpp",
65    "fscrypt_init_extensions.cpp",
66    "init.cpp",
67    "lmkd_service.cpp",
68    "modalias_handler.cpp",
69    "mount_handler.cpp",
70    "mount_namespace.cpp",
71    "persistent_properties.cpp",
72    "persistent_properties.proto",
73    "property_service.cpp",
74    "property_service.proto",
75    "reboot.cpp",
76    "reboot_utils.cpp",
77    "security.cpp",
78    "selabel.cpp",
79    "selinux.cpp",
80    "sigchld_handler.cpp",
81    "snapuserd_transition.cpp",
82    "switch_root.cpp",
83    "uevent_listener.cpp",
84    "ueventd.cpp",
85    "ueventd_parser.cpp",
86]
87
88soong_config_module_type {
89    name: "libinit_cc_defaults",
90    module_type: "cc_defaults",
91    config_namespace: "ANDROID",
92    bool_variables: [
93        "PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT",
94        "release_write_appcompat_override_system_properties",
95    ],
96    properties: [
97        "cflags",
98    ],
99}
100
101libinit_cc_defaults {
102    name: "init_defaults",
103    sanitize: {
104        misc_undefined: ["signed-integer-overflow"],
105    },
106    cflags: [
107        "-DALLOW_FIRST_STAGE_CONSOLE=0",
108        "-DALLOW_LOCAL_PROP_OVERRIDE=0",
109        "-DALLOW_PERMISSIVE_SELINUX=0",
110        "-DANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION",
111        "-DDUMP_ON_UMOUNT_FAILURE=0",
112        "-DINIT_FULL_SOURCES",
113        "-DINSTALL_DEBUG_POLICY_TO_SYSTEM_EXT=0",
114        "-DLOG_UEVENTS=0",
115        "-DREBOOT_BOOTLOADER_ON_PANIC=0",
116        "-DSHUTDOWN_ZERO_TIMEOUT=0",
117        "-DWORLD_WRITABLE_KMSG=0",
118        "-Wall",
119        "-Werror",
120        "-Wextra",
121        "-Wno-unused-parameter",
122        "-Wthread-safety",
123    ],
124    product_variables: {
125        debuggable: {
126            cppflags: [
127                "-UALLOW_FIRST_STAGE_CONSOLE",
128                "-DALLOW_FIRST_STAGE_CONSOLE=1",
129                "-UALLOW_LOCAL_PROP_OVERRIDE",
130                "-DALLOW_LOCAL_PROP_OVERRIDE=1",
131                "-UALLOW_PERMISSIVE_SELINUX",
132                "-DALLOW_PERMISSIVE_SELINUX=1",
133                "-UREBOOT_BOOTLOADER_ON_PANIC",
134                "-DREBOOT_BOOTLOADER_ON_PANIC=1",
135                "-UWORLD_WRITABLE_KMSG",
136                "-DWORLD_WRITABLE_KMSG=1",
137                "-UDUMP_ON_UMOUNT_FAILURE",
138                "-DDUMP_ON_UMOUNT_FAILURE=1",
139            ],
140        },
141        eng: {
142            cppflags: [
143                "-USHUTDOWN_ZERO_TIMEOUT",
144                "-DSHUTDOWN_ZERO_TIMEOUT=1",
145            ],
146        },
147        uml: {
148            cppflags: ["-DUSER_MODE_LINUX"],
149        },
150    },
151    soong_config_variables: {
152        PRODUCT_INSTALL_DEBUG_POLICY_TO_SYSTEM_EXT: {
153            cflags: [
154                "-UINSTALL_DEBUG_POLICY_TO_SYSTEM_EXT",
155                "-DINSTALL_DEBUG_POLICY_TO_SYSTEM_EXT=1",
156            ],
157        },
158        release_write_appcompat_override_system_properties: {
159            cflags: ["-DWRITE_APPCOMPAT_OVERRIDE_SYSTEM_PROPERTIES"],
160        },
161    },
162    static_libs: [
163        "libavb",
164        "libavf_cc_flags",
165        "libbootloader_message",
166        "liblmkd_utils",
167        "liblz4",
168        "libzstd",
169        "libmodprobe",
170        "libprocinfo",
171        "libprotobuf-cpp-lite",
172        "libpropertyinfoserializer",
173        "libpropertyinfoparser",
174        "libsnapshot_cow",
175        "libsnapshot_init",
176        "libxml2",
177        "lib_apex_manifest_proto_lite",
178        "update_metadata-protos",
179        "libgenfslabelsversion.ffi",
180    ],
181    shared_libs: [
182        "libbase",
183        "libcutils",
184        "libdl",
185        "libext4_utils",
186        "libfs_mgr",
187        "libgsi",
188        "liblog",
189        "liblogwrap",
190        "liblp",
191        "libprocessgroup",
192        "libprocessgroup_setup",
193        "libselinux",
194        "libunwindstack",
195        "libutils",
196        "libvendorsupport",
197    ],
198    header_libs: ["bionic_libc_platform_headers"],
199    bootstrap: true,
200    visibility: [":__subpackages__"],
201}
202
203cc_library_headers {
204    name: "libinit_headers",
205    export_include_dirs: ["."],
206    visibility: [":__subpackages__"],
207}
208
209cc_defaults {
210    name: "libinit_defaults",
211    recovery_available: true,
212    defaults: [
213        "init_defaults",
214        "selinux_policy_version",
215    ],
216    srcs: init_common_sources + init_device_sources,
217    export_include_dirs: ["."],
218    generated_sources: [
219        "apex-info-list",
220    ],
221    whole_static_libs: [
222        "libcap",
223    ],
224    header_libs: ["bootimg_headers"],
225    proto: {
226        type: "lite",
227        export_proto_headers: true,
228    },
229
230    target: {
231        recovery: {
232            cflags: ["-DRECOVERY"],
233            exclude_static_libs: [
234                "libxml2",
235            ],
236            exclude_generated_sources: [
237                "apex-info-list",
238            ],
239            exclude_shared_libs: [
240                "libbinder",
241                "libutils",
242            ],
243        },
244    },
245}
246
247cc_library_static {
248    name: "libinit",
249    defaults: ["libinit_defaults"],
250}
251
252cc_library_static {
253    name: "libinit.microdroid",
254    defaults: [
255        "avf_build_flags_cc",
256        "libinit_defaults",
257    ],
258    recovery_available: false,
259    cflags: ["-DMICRODROID=1"],
260}
261
262phony {
263    name: "init",
264    required: [
265        "init_second_stage",
266    ],
267}
268
269cc_defaults {
270    name: "init_second_stage_defaults",
271    stem: "init",
272    defaults: ["init_defaults"],
273    srcs: ["main.cpp"],
274    symlinks: ["ueventd"],
275}
276
277cc_binary {
278    name: "init_second_stage",
279    defaults: ["init_second_stage_defaults"],
280    static_libs: ["libinit"],
281    visibility: ["//visibility:any_system_partition"],
282    required: [
283        "init.rc",
284        "ueventd.rc",
285        "e2fsdroid",
286        "extra_free_kbytes",
287        "make_f2fs",
288        "mke2fs",
289        "sload_f2fs",
290    ],
291}
292
293cc_binary {
294    name: "init_second_stage.recovery",
295    defaults: ["init_second_stage_defaults"],
296    static_libs: ["libinit"],
297    recovery: true,
298    cflags: ["-DRECOVERY"],
299    exclude_static_libs: [
300        "libxml2",
301    ],
302    exclude_shared_libs: [
303        "libbinder",
304        "libutils",
305    ],
306    required: [
307        "init_recovery.rc",
308        "ueventd.rc.recovery",
309        "e2fsdroid.recovery",
310        "make_f2fs.recovery",
311        "mke2fs.recovery",
312        "sload_f2fs.recovery",
313    ],
314}
315
316cc_binary {
317    name: "init_second_stage.microdroid",
318    defaults: [
319        "avf_build_flags_cc",
320        "init_second_stage_defaults",
321    ],
322    static_libs: ["libinit.microdroid"],
323    cflags: ["-DMICRODROID=1"],
324    no_full_install: true,
325    visibility: ["//packages/modules/Virtualization/build/microdroid"],
326}
327
328soong_config_module_type {
329    name: "init_first_stage_cc_defaults",
330    module_type: "cc_defaults",
331    config_namespace: "ANDROID",
332    bool_variables: ["BOARD_USES_RECOVERY_AS_BOOT"],
333    properties: ["no_full_install"],
334}
335
336// Do not install init_first_stage even with mma if we're system-as-root.
337// Otherwise, it will overwrite the symlink.
338init_first_stage_cc_defaults {
339    name: "init_first_stage_defaults",
340    soong_config_variables: {
341        BOARD_USES_RECOVERY_AS_BOOT: {
342            no_full_install: true,
343        },
344    },
345
346    stem: "init",
347
348    srcs: [
349        "block_dev_initializer.cpp",
350        "devices.cpp",
351        "first_stage_console.cpp",
352        "first_stage_init.cpp",
353        "first_stage_main.cpp",
354        "first_stage_mount.cpp",
355        "reboot_utils.cpp",
356        "selabel.cpp",
357        "service_utils.cpp",
358        "snapuserd_transition.cpp",
359        "switch_root.cpp",
360        "uevent_listener.cpp",
361        "util.cpp",
362    ],
363
364    static_libs: [
365        "libfs_avb",
366        "libavf_cc_flags",
367        "libfs_mgr",
368        "libfec",
369        "libfec_rs",
370        "libsquashfs_utils",
371        "libcrypto_utils",
372        "libavb",
373        "liblp",
374        "libcutils",
375        "libbase",
376        "liblog",
377        "libcrypto_static",
378        "libselinux",
379        "libcap",
380        "libgsi",
381        "liblzma",
382        "libunwindstack_no_dex",
383        "libmodprobe",
384        "libext2_uuid",
385        "libprotobuf-cpp-lite",
386        "libsnapshot_cow",
387        "liblz4",
388        "libzstd",
389        "libsnapshot_init",
390        "update_metadata-protos",
391        "libprocinfo",
392        "libbootloader_message",
393    ],
394
395    static_executable: true,
396    system_shared_libs: [],
397
398    cflags: [
399        "-Wall",
400        "-Wextra",
401        "-Wno-unused-parameter",
402        "-Werror",
403        "-DALLOW_FIRST_STAGE_CONSOLE=0",
404        "-DALLOW_LOCAL_PROP_OVERRIDE=0",
405        "-DALLOW_PERMISSIVE_SELINUX=0",
406        "-DREBOOT_BOOTLOADER_ON_PANIC=0",
407        "-DWORLD_WRITABLE_KMSG=0",
408        "-DDUMP_ON_UMOUNT_FAILURE=0",
409        "-DSHUTDOWN_ZERO_TIMEOUT=0",
410        "-DLOG_UEVENTS=0",
411        "-DSEPOLICY_VERSION=30", // TODO(jiyong): externalize the version number
412    ],
413
414    product_variables: {
415        debuggable: {
416            cflags: [
417                "-UALLOW_FIRST_STAGE_CONSOLE",
418                "-DALLOW_FIRST_STAGE_CONSOLE=1",
419
420                "-UALLOW_LOCAL_PROP_OVERRIDE",
421                "-DALLOW_LOCAL_PROP_OVERRIDE=1",
422
423                "-UALLOW_PERMISSIVE_SELINUX",
424                "-DALLOW_PERMISSIVE_SELINUX=1",
425
426                "-UREBOOT_BOOTLOADER_ON_PANIC",
427                "-DREBOOT_BOOTLOADER_ON_PANIC=1",
428
429                "-UWORLD_WRITABLE_KMSG",
430                "-DWORLD_WRITABLE_KMSG=1",
431
432                "-UDUMP_ON_UMOUNT_FAILURE",
433                "-DDUMP_ON_UMOUNT_FAILURE=1",
434            ],
435        },
436
437        eng: {
438            cflags: [
439                "-USHUTDOWN_ZERO_TIMEOUT",
440                "-DSHUTDOWN_ZERO_TIMEOUT=1",
441            ],
442        },
443    },
444
445    sanitize: {
446        misc_undefined: ["signed-integer-overflow"],
447
448        // First stage init is weird: it may start without stdout/stderr, and no /proc.
449        hwaddress: false,
450        memtag_stack: false,
451    },
452
453    // Install adb_debug.prop into debug ramdisk.
454    // This allows adb root on a user build, when debug ramdisk is used.
455    required: ["adb_debug.prop"],
456
457    ramdisk: true,
458
459    install_in_root: true,
460}
461
462cc_binary {
463    name: "init_first_stage",
464    defaults: ["init_first_stage_defaults"],
465}
466
467cc_binary {
468    name: "init_first_stage.microdroid",
469    defaults: [
470        "avf_build_flags_cc",
471        "init_first_stage_defaults",
472    ],
473    cflags: ["-DMICRODROID=1"],
474    no_full_install: true,
475}
476
477phony {
478    name: "init_system",
479    required: ["init_second_stage"],
480}
481
482// Tests
483// ------------------------------------------------------------------------------
484
485cc_test {
486    // Note: This is NOT a CTS test. See b/320800872
487    name: "CtsInitTestCases",
488    defaults: ["init_defaults"],
489    require_root: true,
490
491    compile_multilib: "first",
492
493    srcs: [
494        "devices_test.cpp",
495        "epoll_test.cpp",
496        "firmware_handler_test.cpp",
497        "init_test.cpp",
498        "interprocess_fifo_test.cpp",
499        "keychords_test.cpp",
500        "oneshot_on_test.cpp",
501        "persistent_properties_test.cpp",
502        "property_service_test.cpp",
503        "property_type_test.cpp",
504        "reboot_test.cpp",
505        "rlimit_parser_test.cpp",
506        "service_test.cpp",
507        "subcontext_test.cpp",
508        "tokenizer_test.cpp",
509        "ueventd_parser_test.cpp",
510        "ueventd_test.cpp",
511        "util_test.cpp",
512    ],
513    static_libs: [
514        "libgmock",
515        "libinit",
516    ],
517
518    test_suites: [
519        "device-tests",
520    ],
521}
522
523cc_benchmark {
524    name: "init_benchmarks",
525    defaults: ["init_defaults"],
526    srcs: [
527        "subcontext_benchmark.cpp",
528    ],
529    static_libs: ["libinit"],
530}
531
532cc_defaults {
533    name: "libinit_test_utils_libraries_defaults",
534    shared_libs: [
535        "libbase",
536        "libcutils",
537        "libselinux",
538        "liblog",
539        "libprocessgroup",
540        "libprotobuf-cpp-lite",
541    ],
542    static_libs: [
543        "libfs_mgr",
544        "libhidl-gen-utils",
545    ],
546}
547
548cc_library_static {
549    name: "libinit_test_utils",
550    defaults: ["libinit_test_utils_libraries_defaults"],
551    cflags: [
552        "-Wall",
553        "-Wextra",
554        "-Wno-unused-parameter",
555        "-Werror",
556    ],
557    srcs: init_common_sources + [
558        "test_utils/service_utils.cpp",
559    ],
560    whole_static_libs: [
561        "libcap",
562    ],
563    export_include_dirs: ["test_utils/include"], // for tests
564    header_libs: ["bionic_libc_platform_headers"],
565    product_variables: {
566        shipping_api_level: {
567            cflags: ["-DBUILD_SHIPPING_API_LEVEL=%s"],
568        },
569    },
570}
571
572// Host Verifier
573// ------------------------------------------------------------------------------
574
575genrule {
576    name: "generated_stub_builtin_function_map",
577    tool_files: ["host_builtin_map.py"],
578    out: ["generated_stub_builtin_function_map.h"],
579    srcs: [
580        "builtins.cpp",
581        "check_builtins.cpp",
582    ],
583    cmd: "$(location host_builtin_map.py) --builtins $(location builtins.cpp) --check_builtins $(location check_builtins.cpp) > $(out)",
584}
585
586cc_defaults {
587    name: "init_host_defaults",
588    host_supported: true,
589    cflags: [
590        "-Wall",
591        "-Wextra",
592        "-Wno-unused-parameter",
593        "-Werror",
594    ],
595    static_libs: [
596        "libbase",
597        "libselinux",
598        "libpropertyinfoserializer",
599        "libpropertyinfoparser",
600    ],
601    whole_static_libs: ["libcap"],
602    shared_libs: [
603        "libcutils",
604        "liblog",
605        "libprocessgroup",
606        "libprotobuf-cpp-lite",
607    ],
608    proto: {
609        type: "lite",
610    },
611    target: {
612        android: {
613            enabled: false,
614        },
615        darwin: {
616            enabled: false,
617        },
618    },
619    product_variables: {
620        shipping_api_level: {
621            cflags: ["-DBUILD_SHIPPING_API_LEVEL=%s"],
622        },
623    },
624}
625
626cc_binary {
627    name: "host_init_verifier",
628    defaults: ["init_host_defaults"],
629    srcs: [
630        "check_builtins.cpp",
631        "host_import_parser.cpp",
632        "host_init_verifier.cpp",
633        "interface_utils.cpp",
634    ] + init_common_sources,
635    generated_headers: [
636        "generated_android_ids",
637        "generated_stub_builtin_function_map",
638    ],
639    shared_libs: [
640        "libhidl-gen-utils",
641        "libhidlmetadata",
642    ],
643}
644
645genrule {
646    name: "noop_builtin_function_map",
647    tool_files: ["host_builtin_map.py"],
648    out: ["noop_builtin_function_map.h"],
649    srcs: [
650        "builtins.cpp",
651        "noop_builtins.cpp",
652    ],
653    cmd: "$(location host_builtin_map.py) --builtins $(location builtins.cpp) --check_builtins $(location noop_builtins.cpp) > $(out)",
654}
655
656cc_library_host_static {
657    name: "libinit_host",
658    defaults: ["init_host_defaults"],
659    srcs: [
660        "noop_builtins.cpp",
661    ] + init_common_sources,
662    export_include_dirs: ["."],
663    generated_headers: [
664        "noop_builtin_function_map",
665    ],
666    proto: {
667        export_proto_headers: true,
668    },
669    visibility: [
670        // host_apex_verifier performs a subset of init.rc validation
671        "//system/apex/tools",
672    ],
673}
674
675sh_binary {
676    name: "extra_free_kbytes",
677    src: "extra_free_kbytes.sh",
678    filename_from_src: true,
679}
680
681phony {
682    name: "init_vendor",
683    required: select(soong_config_variable("ANDROID", "BOARD_USES_RECOVERY_AS_BOOT"), {
684        true: [],
685        default: ["init_first_stage"],
686    }),
687}
688