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