1//
2// Copyright (C) 2015 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
17// AIDL interface between libupdate_engine and framework.jar
18filegroup {
19    name: "libupdate_engine_aidl",
20    srcs: [
21        "binder_bindings/android/os/IUpdateEngine.aidl",
22        "binder_bindings/android/os/IUpdateEngineCallback.aidl",
23    ],
24    path: "binder_bindings",
25}
26
27cc_defaults {
28    name: "ue_defaults",
29
30    cflags: [
31        "-DBASE_VER=576279",
32        "-DUSE_BINDER=1",
33        "-DUSE_CHROME_NETWORK_PROXY=0",
34        "-DUSE_CHROME_KIOSK_APP=0",
35        "-DUSE_HWID_OVERRIDE=0",
36        "-DUSE_MTD=0",
37        "-DUSE_OMAHA=0",
38        "-D_FILE_OFFSET_BITS=64",
39        "-D_POSIX_C_SOURCE=199309L",
40        "-Wa,--noexecstack",
41        "-Wall",
42        "-Werror",
43        "-Wextra",
44        "-Wformat=2",
45        "-Wno-psabi",
46        "-Wno-unused-parameter",
47        "-ffunction-sections",
48        "-fstack-protector-strong",
49        "-fvisibility=hidden",
50    ],
51    cppflags: [
52        "-Wnon-virtual-dtor",
53        "-fno-strict-aliasing",
54    ],
55    include_dirs: ["system"],
56    local_include_dirs: ["client_library/include"],
57    static_libs: ["libgtest_prod"],
58    shared_libs: [
59        "libbrillo-stream",
60        "libbrillo",
61        "libchrome",
62    ],
63    ldflags: ["-Wl,--gc-sections"],
64
65    product_variables: {
66        pdk: {
67            enabled: false,
68        },
69    },
70
71    target: {
72        android: {
73            cflags: [
74                "-DUSE_FEC=1",
75            ],
76        },
77        host: {
78            cflags: [
79                "-DUSE_FEC=0",
80            ],
81        },
82        darwin: {
83            enabled: false,
84        },
85    },
86}
87
88// update_metadata-protos (type: static_library)
89// ========================================================
90// Protobufs.
91cc_defaults {
92    name: "update_metadata-protos_exports",
93
94    shared_libs: ["libprotobuf-cpp-lite"],
95}
96
97cc_library_static {
98    name: "update_metadata-protos",
99    host_supported: true,
100    recovery_available: true,
101
102    srcs: ["update_engine/update_metadata.proto"],
103    cflags: [
104        "-Wall",
105        "-Werror",
106    ],
107    proto: {
108        canonical_path_from_root: false,
109        export_proto_headers: true,
110    },
111}
112
113// libpayload_consumer (type: static_library)
114// ========================================================
115// The payload application component and common dependencies.
116cc_defaults {
117    name: "libpayload_consumer_exports",
118    defaults: ["update_metadata-protos_exports"],
119
120    static_libs: [
121        "update_metadata-protos",
122        "libxz",
123        "libbz",
124        "libbspatch",
125        "libbrotli",
126        "libfec_rs",
127        "libpuffpatch",
128        "libverity_tree",
129    ],
130    shared_libs: [
131        "libziparchive",
132        "libbase",
133        "libcrypto",
134        "libfec",
135    ],
136}
137
138cc_library_static {
139    name: "libpayload_consumer",
140    defaults: [
141        "ue_defaults",
142        "libpayload_consumer_exports",
143    ],
144    host_supported: true,
145    recovery_available: true,
146
147    srcs: [
148        "common/action_processor.cc",
149        "common/boot_control_stub.cc",
150        "common/clock.cc",
151        "common/constants.cc",
152        "common/cpu_limiter.cc",
153        "common/dynamic_partition_control_stub.cc",
154        "common/error_code_utils.cc",
155        "common/file_fetcher.cc",
156        "common/hash_calculator.cc",
157        "common/http_common.cc",
158        "common/http_fetcher.cc",
159        "common/hwid_override.cc",
160        "common/multi_range_http_fetcher.cc",
161        "common/platform_constants_android.cc",
162        "common/prefs.cc",
163        "common/proxy_resolver.cc",
164        "common/subprocess.cc",
165        "common/terminator.cc",
166        "common/utils.cc",
167        "payload_consumer/bzip_extent_writer.cc",
168        "payload_consumer/cached_file_descriptor.cc",
169        "payload_consumer/certificate_parser_android.cc",
170        "payload_consumer/delta_performer.cc",
171        "payload_consumer/download_action.cc",
172        "payload_consumer/extent_reader.cc",
173        "payload_consumer/extent_writer.cc",
174        "payload_consumer/file_descriptor.cc",
175        "payload_consumer/file_descriptor_utils.cc",
176        "payload_consumer/file_writer.cc",
177        "payload_consumer/filesystem_verifier_action.cc",
178        "payload_consumer/install_plan.cc",
179        "payload_consumer/mount_history.cc",
180        "payload_consumer/payload_constants.cc",
181        "payload_consumer/payload_metadata.cc",
182        "payload_consumer/payload_verifier.cc",
183        "payload_consumer/postinstall_runner_action.cc",
184        "payload_consumer/verity_writer_android.cc",
185        "payload_consumer/xz_extent_writer.cc",
186        "payload_consumer/fec_file_descriptor.cc",
187    ],
188}
189
190// libupdate_engine_boot_control (type: static_library)
191// ========================================================
192// A BootControl class implementation using Android's HIDL boot_control HAL.
193cc_defaults {
194    name: "libupdate_engine_boot_control_exports",
195    defaults: ["update_metadata-protos_exports"],
196
197    static_libs: [
198        "libcutils",
199        "libfs_mgr_binder",
200        "libgsi",
201        "libpayload_consumer",
202        "libsnapshot",
203        "update_metadata-protos",
204    ],
205    shared_libs: [
206        "libbootloader_message",
207        "libhidlbase",
208        "liblp",
209        "libstatslog",
210        "libutils",
211        "[email protected]",
212        "[email protected]",
213    ],
214    header_libs: [
215        "avb_headers",
216    ],
217    target: {
218        recovery: {
219            static_libs: [
220                "libfs_mgr",
221                "libsnapshot_nobinder",
222            ],
223            exclude_static_libs: [
224                "libfs_mgr_binder",
225                "libsnapshot",
226            ],
227            exclude_shared_libs: [
228                "libstatslog",
229            ],
230        },
231    },
232}
233
234cc_library_static {
235    name: "libupdate_engine_boot_control",
236    defaults: [
237        "ue_defaults",
238        "libupdate_engine_boot_control_exports",
239        "libpayload_consumer_exports",
240    ],
241    recovery_available: true,
242
243    srcs: [
244        "boot_control_android.cc",
245        "cleanup_previous_update_action.cc",
246        "dynamic_partition_control_android.cc",
247        "dynamic_partition_utils.cc",
248    ],
249}
250
251// libupdate_engine_android (type: static_library)
252// ========================================================
253// The main daemon static_library used in Android (non-Brillo). This only has a
254// loop to apply payloads provided by the upper layer via a Binder interface.
255cc_defaults {
256    name: "libupdate_engine_android_exports",
257    defaults: [
258        "ue_defaults",
259        "libpayload_consumer_exports",
260        "libupdate_engine_boot_control_exports",
261    ],
262
263    static_libs: [
264        "libpayload_consumer",
265        "libupdate_engine_boot_control",
266    ],
267    shared_libs: [
268        "libandroid_net",
269        "libbase",
270        "libbinder",
271        "libbinderwrapper",
272        "libbootloader_message",
273        "libbrillo-binder",
274        "libcurl",
275        "libcutils",
276        "liblog",
277        "libssl",
278        "libstatslog",
279        "libutils",
280    ],
281}
282
283cc_library_static {
284    name: "libupdate_engine_android",
285    defaults: [
286        "ue_defaults",
287        "libupdate_engine_android_exports",
288    ],
289
290    // TODO(deymo): Remove external/cros/system_api/dbus once the strings are moved
291    // out of the DBus interface.
292    include_dirs: ["external/cros/system_api/dbus"],
293
294    aidl: {
295        local_include_dirs: ["binder_bindings"],
296        export_aidl_headers: true,
297    },
298
299    srcs: [
300        ":libupdate_engine_aidl",
301        "binder_service_android.cc",
302        "certificate_checker.cc",
303        "daemon.cc",
304        "daemon_state_android.cc",
305        "hardware_android.cc",
306        "libcurl_http_fetcher.cc",
307        "logging_android.cc",
308        "metrics_reporter_android.cc",
309        "metrics_utils.cc",
310        "network_selector_android.cc",
311        "update_attempter_android.cc",
312        "update_boot_flags_action.cc",
313        "update_status_utils.cc",
314    ],
315}
316
317// update_engine (type: executable)
318// ========================================================
319// update_engine daemon.
320cc_binary {
321    name: "update_engine",
322    defaults: [
323        "ue_defaults",
324        "libupdate_engine_android_exports",
325    ],
326
327    static_libs: ["libupdate_engine_android"],
328    required: [
329        "cacerts_google",
330        "otacerts",
331    ],
332
333    srcs: ["main.cc"],
334    init_rc: ["update_engine.rc"],
335}
336
337// update_engine_sideload (type: executable)
338// ========================================================
339// A binary executable equivalent to update_engine daemon that installs an update
340// from a local file directly instead of running in the background. Used in
341// recovery image.
342cc_binary {
343    name: "update_engine_sideload",
344    defaults: [
345        "ue_defaults",
346        "update_metadata-protos_exports",
347        "libupdate_engine_boot_control_exports",
348        "libpayload_consumer_exports",
349    ],
350    recovery: true,
351
352    cflags: ["-D_UE_SIDELOAD"],
353    // TODO(deymo): Remove external/cros/system_api/dbus once the strings are moved
354    // out of the DBus interface.
355    include_dirs: ["external/cros/system_api/dbus"],
356
357    srcs: [
358        "hardware_android.cc",
359        "logging_android.cc",
360        "metrics_reporter_stub.cc",
361        "metrics_utils.cc",
362        "network_selector_stub.cc",
363        "sideload_main.cc",
364        "update_attempter_android.cc",
365        "update_boot_flags_action.cc",
366        "update_status_utils.cc",
367    ],
368
369    // Use commonly used shared libraries. libprotobuf-cpp-lite.so is filtered out,
370    // as it doesn't look beneficial to be installed separately due to its size. Note
371    // that we explicitly request their recovery variants, so that the expected files
372    // will be used and installed.
373    shared_libs: [
374        "libbase",
375        "liblog",
376    ],
377    static_libs: [
378        "libpayload_consumer",
379        "libupdate_engine_boot_control",
380        "update_metadata-protos",
381
382        // We add the static versions of the shared libraries that are not installed to
383        // recovery image due to size concerns. Need to include all the static library
384        // dependencies of these static libraries.
385        "libevent",
386        "libmodpb64",
387        "libgtest_prod",
388        "libprotobuf-cpp-lite",
389        "libbrillo-stream",
390        "libbrillo",
391        "libchrome",
392    ],
393    target: {
394        recovery: {
395            exclude_shared_libs: [
396                "libprotobuf-cpp-lite",
397                "libbrillo-stream",
398                "libbrillo",
399                "libchrome",
400            ],
401        },
402    },
403
404    required: [
405        "otacerts.recovery",
406    ],
407}
408
409// libupdate_engine_client (type: shared_library)
410// ========================================================
411cc_library_shared {
412    name: "libupdate_engine_client",
413
414    cflags: [
415        "-Wall",
416        "-Werror",
417        "-Wno-unused-parameter",
418        "-DUSE_BINDER=1",
419    ],
420    export_include_dirs: ["client_library/include"],
421    include_dirs: [
422        // TODO(deymo): Remove "external/cros/system_api/dbus" when dbus is not used.
423        "external/cros/system_api/dbus",
424        "system",
425    ],
426
427    aidl: {
428        local_include_dirs: ["binder_bindings"],
429    },
430
431    shared_libs: [
432        "libchrome",
433        "libbrillo",
434        "libbinder",
435        "libbrillo-binder",
436        "libutils",
437    ],
438
439    srcs: [
440        ":libupdate_engine_client_aidl",
441        "client_library/client.cc",
442        "client_library/client_binder.cc",
443        "parcelable_update_engine_status.cc",
444        "update_status_utils.cc",
445    ],
446}
447
448filegroup {
449    name: "libupdate_engine_client_aidl",
450    srcs: [
451        "binder_bindings/android/brillo/IUpdateEngine.aidl",
452        "binder_bindings/android/brillo/IUpdateEngineStatusCallback.aidl",
453    ],
454    path: "binder_bindings",
455}
456
457// update_engine_client (type: executable)
458// ========================================================
459// update_engine console client.
460cc_binary {
461    name: "update_engine_client",
462    defaults: ["ue_defaults"],
463
464    // TODO(deymo): Remove external/cros/system_api/dbus once the strings are moved
465    // out of the DBus interface.
466    include_dirs: ["external/cros/system_api/dbus"],
467
468    shared_libs: [
469        "libbinder",
470        "libbinderwrapper",
471        "libbrillo-binder",
472        "libutils",
473    ],
474
475    aidl: {
476        local_include_dirs: ["binder_bindings"],
477    },
478
479    srcs: [
480        ":libupdate_engine_aidl",
481        "common/error_code_utils.cc",
482        "update_engine_client_android.cc",
483        "update_status_utils.cc",
484    ],
485}
486
487// libpayload_generator (type: static_library)
488// ========================================================
489// server-side code. This is used for delta_generator and unittests but not
490// for any client code.
491cc_defaults {
492    name: "libpayload_generator_exports",
493    defaults: [
494        "libpayload_consumer_exports",
495        "update_metadata-protos_exports",
496    ],
497
498    header_libs: [
499        "bootimg_headers",
500    ],
501    static_libs: [
502        "libavb",
503        "libbrotli",
504        "libbsdiff",
505        "libdivsufsort",
506        "libdivsufsort64",
507        "liblzma",
508        "libpayload_consumer",
509        "libpuffdiff",
510        "libverity_tree",
511        "update_metadata-protos",
512    ],
513    shared_libs: [
514        "libbase",
515        "libext2fs",
516    ],
517}
518
519cc_library_static {
520    name: "libpayload_generator",
521    defaults: [
522        "ue_defaults",
523        "libpayload_generator_exports",
524    ],
525    host_supported: true,
526
527    srcs: [
528        "payload_generator/ab_generator.cc",
529        "payload_generator/annotated_operation.cc",
530        "payload_generator/blob_file_writer.cc",
531        "payload_generator/block_mapping.cc",
532        "payload_generator/boot_img_filesystem.cc",
533        "payload_generator/bzip.cc",
534        "payload_generator/cycle_breaker.cc",
535        "payload_generator/deflate_utils.cc",
536        "payload_generator/delta_diff_generator.cc",
537        "payload_generator/delta_diff_utils.cc",
538        "payload_generator/ext2_filesystem.cc",
539        "payload_generator/extent_ranges.cc",
540        "payload_generator/extent_utils.cc",
541        "payload_generator/full_update_generator.cc",
542        "payload_generator/graph_types.cc",
543        "payload_generator/graph_utils.cc",
544        "payload_generator/inplace_generator.cc",
545        "payload_generator/mapfile_filesystem.cc",
546        "payload_generator/payload_file.cc",
547        "payload_generator/payload_generation_config_android.cc",
548        "payload_generator/payload_generation_config.cc",
549        "payload_generator/payload_signer.cc",
550        "payload_generator/raw_filesystem.cc",
551        "payload_generator/squashfs_filesystem.cc",
552        "payload_generator/tarjan.cc",
553        "payload_generator/topological_sort.cc",
554        "payload_generator/xz_android.cc",
555    ],
556}
557
558// delta_generator (type: executable)
559// ========================================================
560// server-side delta generator.
561cc_binary_host {
562    name: "delta_generator",
563    defaults: [
564        "ue_defaults",
565        "libpayload_generator_exports",
566        "libpayload_consumer_exports",
567    ],
568
569    static_libs: [
570        "libavb_host_sysdeps",
571        "libpayload_consumer",
572        "libpayload_generator",
573    ],
574
575    srcs: ["payload_generator/generate_delta_main.cc"],
576}
577
578cc_test {
579    name: "ue_unittest_delta_generator",
580    defaults: [
581        "ue_defaults",
582        "libpayload_generator_exports",
583        "libpayload_consumer_exports",
584    ],
585
586    static_libs: [
587        "libpayload_consumer",
588        "libpayload_generator",
589    ],
590
591    srcs: ["payload_generator/generate_delta_main.cc"],
592
593    gtest: false,
594    stem: "delta_generator",
595}
596
597// test_http_server (type: executable)
598// ========================================================
599// Test HTTP Server.
600cc_test {
601    name: "test_http_server",
602    defaults: ["ue_defaults"],
603    srcs: [
604        "common/http_common.cc",
605        "test_http_server.cc",
606    ],
607
608    gtest: false,
609}
610
611// test_subprocess (type: executable)
612// ========================================================
613// Test helper subprocess program.
614cc_test {
615    name: "test_subprocess",
616    defaults: ["ue_defaults"],
617    srcs: ["test_subprocess.cc"],
618
619    gtest: false,
620}
621
622// Public keys for unittests.
623// ========================================================
624genrule {
625    name: "ue_unittest_keys",
626    cmd: "openssl rsa -in $(location unittest_key.pem) -pubout -out $(location unittest_key.pub.pem) &&" +
627        "openssl rsa -in $(location unittest_key2.pem) -pubout -out $(location unittest_key2.pub.pem) &&" +
628        "openssl rsa -in $(location unittest_key_RSA4096.pem) -pubout -out $(location unittest_key_RSA4096.pub.pem) &&" +
629        "openssl pkey -in $(location unittest_key_EC.pem) -pubout -out $(location unittest_key_EC.pub.pem)",
630    srcs: [
631        "unittest_key.pem",
632        "unittest_key2.pem",
633        "unittest_key_RSA4096.pem",
634        "unittest_key_EC.pem",
635    ],
636    out: [
637        "unittest_key.pub.pem",
638        "unittest_key2.pub.pem",
639        "unittest_key_RSA4096.pub.pem",
640        "unittest_key_EC.pub.pem",
641    ],
642}
643
644// Sample images for unittests.
645// ========================================================
646// Extract sample image from the compressed sample_images.tar.bz2 file used by
647// the unittests.
648genrule {
649    name: "ue_unittest_disk_imgs",
650    cmd: "tar -jxf $(in) -C $(genDir)/gen disk_ext2_1k.img disk_ext2_4k.img disk_ext2_4k_empty.img disk_ext2_unittest.img",
651    srcs: ["sample_images/sample_images.tar.bz2"],
652    out: [
653        "gen/disk_ext2_1k.img",
654        "gen/disk_ext2_4k.img",
655        "gen/disk_ext2_4k_empty.img",
656        "gen/disk_ext2_unittest.img",
657    ],
658}
659
660// update_engine_unittests (type: executable)
661// ========================================================
662// Main unittest file.
663cc_test {
664    name: "update_engine_unittests",
665    defaults: [
666        "ue_defaults",
667        "libpayload_generator_exports",
668        "libupdate_engine_android_exports",
669    ],
670
671    static_libs: [
672        "libpayload_generator",
673        "libbrillo-test-helpers",
674        "libgmock",
675        "libchrome_test_helpers",
676        "libupdate_engine_android",
677        "libdm",
678    ],
679
680    header_libs: [
681        "libstorage_literals_headers",
682    ],
683
684    data: [
685        ":test_http_server",
686        ":test_subprocess",
687        ":ue_unittest_delta_generator",
688        ":ue_unittest_disk_imgs",
689        ":ue_unittest_keys",
690        "otacerts.zip",
691        "unittest_key.pem",
692        "unittest_key2.pem",
693        "unittest_key_RSA4096.pem",
694        "unittest_key_EC.pem",
695        "update_engine.conf",
696    ],
697
698    // We cannot use the default generated AndroidTest.xml because of the use of helper modules
699    // (i.e. test_http_server, test_subprocess, ue_unittest_delta_generator).
700    test_config: "test_config.xml",
701    test_suites: ["device-tests"],
702
703    srcs: [
704        "certificate_checker_unittest.cc",
705        "common/action_pipe_unittest.cc",
706        "common/action_processor_unittest.cc",
707        "common/action_unittest.cc",
708        "common/cpu_limiter_unittest.cc",
709        "common/fake_prefs.cc",
710        "common/file_fetcher_unittest.cc",
711        "common/hash_calculator_unittest.cc",
712        "common/http_fetcher_unittest.cc",
713        "common/hwid_override_unittest.cc",
714        "common/mock_http_fetcher.cc",
715        "common/prefs_unittest.cc",
716        "common/proxy_resolver_unittest.cc",
717        "common/subprocess_unittest.cc",
718        "common/terminator_unittest.cc",
719        "common/test_utils.cc",
720        "common/utils_unittest.cc",
721        "dynamic_partition_control_android_unittest.cc",
722        "payload_consumer/bzip_extent_writer_unittest.cc",
723        "payload_consumer/cached_file_descriptor_unittest.cc",
724        "payload_consumer/certificate_parser_android_unittest.cc",
725        "payload_consumer/delta_performer_integration_test.cc",
726        "payload_consumer/delta_performer_unittest.cc",
727        "payload_consumer/extent_reader_unittest.cc",
728        "payload_consumer/extent_writer_unittest.cc",
729        "payload_consumer/fake_file_descriptor.cc",
730        "payload_consumer/file_descriptor_utils_unittest.cc",
731        "payload_consumer/file_writer_unittest.cc",
732        "payload_consumer/filesystem_verifier_action_unittest.cc",
733        "payload_consumer/postinstall_runner_action_unittest.cc",
734        "payload_consumer/verity_writer_android_unittest.cc",
735        "payload_consumer/xz_extent_writer_unittest.cc",
736        "payload_generator/ab_generator_unittest.cc",
737        "payload_generator/blob_file_writer_unittest.cc",
738        "payload_generator/block_mapping_unittest.cc",
739        "payload_generator/boot_img_filesystem_unittest.cc",
740        "payload_generator/cycle_breaker_unittest.cc",
741        "payload_generator/deflate_utils_unittest.cc",
742        "payload_generator/delta_diff_utils_unittest.cc",
743        "payload_generator/ext2_filesystem_unittest.cc",
744        "payload_generator/extent_ranges_unittest.cc",
745        "payload_generator/extent_utils_unittest.cc",
746        "payload_generator/fake_filesystem.cc",
747        "payload_generator/full_update_generator_unittest.cc",
748        "payload_generator/graph_utils_unittest.cc",
749        "payload_generator/inplace_generator_unittest.cc",
750        "payload_generator/mapfile_filesystem_unittest.cc",
751        "payload_generator/payload_file_unittest.cc",
752        "payload_generator/payload_generation_config_android_unittest.cc",
753        "payload_generator/payload_generation_config_unittest.cc",
754        "payload_generator/payload_signer_unittest.cc",
755        "payload_generator/squashfs_filesystem_unittest.cc",
756        "payload_generator/tarjan_unittest.cc",
757        "payload_generator/topological_sort_unittest.cc",
758        "payload_generator/zip_unittest.cc",
759        "testrunner.cc",
760        "update_attempter_android_unittest.cc",
761    ],
762}
763
764// Brillo update payload generation script
765// ========================================================
766cc_prebuilt_binary {
767    name: "brillo_update_payload",
768    device_supported: false,
769    host_supported: true,
770
771    srcs: ["scripts/brillo_update_payload"],
772    required: [
773        "delta_generator",
774        "shflags",
775        "simg2img",
776    ],
777
778    target: {
779        darwin: {
780            enabled: false,
781        },
782    },
783}
784
785// AIDL interface between libupdate_engine and the Things jar.
786filegroup {
787    name: "things_update_engine_aidl",
788    srcs: [
789        "binder_bindings/android/brillo/IUpdateEngine.aidl",
790        "binder_bindings/android/brillo/IUpdateEngineStatusCallback.aidl",
791    ],
792}
793