1// Copyright (C) 2018 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// This is required because no Android.bp can include a library defined in an
16// Android.mk. Eventually should kill libfastboot (defined in Android.mk)
17package {
18    default_applicable_licenses: [
19        "system_core_fastboot_license",
20        "Android-Apache-2.0",
21    ],
22}
23
24// Added automatically by a large-scale-change that took the approach of
25// 'apply every license found to every target'. While this makes sure we respect
26// every license restriction, it may not be entirely correct.
27//
28// e.g. GPL in an MIT project might only apply to the contrib/ directory.
29//
30// Please consider splitting the single license below into multiple licenses,
31// taking care not to lose any license_kind information, and overriding the
32// default license using the 'licenses: [...]' property on targets as needed.
33//
34// For unused files, consider creating a 'fileGroup' with "//visibility:private"
35// to attach the license to, and including a comment whether the files may be
36// used in the current project.
37// See: http://go/android-license-faq
38license {
39    name: "system_core_fastboot_license",
40    visibility: [":__subpackages__"],
41    license_kinds: [
42        "SPDX-license-identifier-BSD",
43    ],
44    license_text: ["LICENSE"],
45}
46
47cc_library_host_static {
48    name: "libfastboot2",
49
50    //host_supported: true,
51
52    compile_multilib: "first",
53    srcs: [
54        "bootimg_utils.cpp",
55        "fs.cpp",
56        "socket.cpp",
57        "tcp.cpp",
58        "udp.cpp",
59        "util.cpp",
60        "vendor_boot_img_utils.cpp",
61        "fastboot_driver.cpp",
62    ],
63
64    static_libs: [
65        "libziparchive",
66        "libsparse",
67        "libutils",
68        "liblog",
69        "libz",
70        "libdiagnose_usb",
71        "libbase",
72        "libcutils",
73        "libgtest",
74        "libgtest_main",
75        "libbase",
76        "libadb_host",
77        "liblp",
78    ],
79
80    header_libs: [
81        "avb_headers",
82        "bootimg_headers",
83        "libstorage_literals_headers",
84    ],
85
86    export_header_lib_headers: [
87        "bootimg_headers",
88    ],
89
90    target: {
91        linux: {
92            srcs: ["usb_linux.cpp"],
93        },
94
95        darwin: {
96            srcs: ["usb_osx.cpp"],
97
98            host_ldlibs: [
99                "-framework CoreFoundation",
100                "-framework IOKit",
101            ],
102        },
103
104        windows: {
105            srcs: ["usb_windows.cpp"],
106
107            host_ldlibs: [
108                "-lws2_32",
109            ],
110        },
111    },
112
113    cflags: [
114        "-Wall",
115        "-Wextra",
116        "-Werror",
117        "-Wunreachable-code",
118    ],
119
120    export_include_dirs: ["."],
121
122}
123
124cc_defaults {
125    name: "fastboot_defaults",
126
127    cflags: [
128        "-Wall",
129        "-Wextra",
130        "-Werror",
131        "-Wvla",
132        "-DANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION",
133        "-Wthread-safety",
134    ],
135    rtti: true,
136
137}
138
139cc_binary {
140    name: "fastbootd",
141    defaults: ["fastboot_defaults"],
142
143    recovery: true,
144
145    product_variables: {
146        debuggable: {
147            cppflags: ["-DFB_ENABLE_FETCH"],
148        },
149    },
150
151    srcs: [
152        "device/commands.cpp",
153        "device/fastboot_device.cpp",
154        "device/flashing.cpp",
155        "device/main.cpp",
156        "device/usb.cpp",
157        "device/usb_iouring.cpp",
158        "device/usb_client.cpp",
159        "device/tcp_client.cpp",
160        "device/utility.cpp",
161        "device/variables.cpp",
162        "socket.cpp",
163    ],
164
165    shared_libs: [
166        "android.hardware.boot@1.0",
167        "android.hardware.boot@1.1",
168        "android.hardware.boot-V1-ndk",
169        "libboot_control_client",
170        "android.hardware.fastboot@1.1",
171        "android.hardware.fastboot-V1-ndk",
172        "android.hardware.health@2.0",
173        "android.hardware.health-V2-ndk",
174        "libasyncio",
175        "libbase",
176        "libbinder_ndk",
177        "libbootloader_message",
178        "libcutils",
179        "libext2_uuid",
180        "libext4_utils",
181        "libfs_mgr",
182        "libgsi",
183        "libhidlbase",
184        "liblog",
185        "liblp",
186        "libprotobuf-cpp-lite",
187        "libsparse",
188        "libutils",
189    ],
190
191    static_libs: [
192        "android.hardware.health-translate-ndk",
193        "libc++fs",
194        "libhealthhalutils",
195        "libhealthshim",
196        "libfastbootshim",
197        "libsnapshot_cow",
198        "liblz4",
199        "libsnapshot_nobinder",
200        "update_metadata-protos",
201        "liburing",
202    ],
203    include_dirs: ["bionic/libc/kernel"],
204
205    header_libs: [
206        "avb_headers",
207        "libgtest_prod_headers",
208        "libsnapshot_headers",
209        "libstorage_literals_headers",
210    ],
211}
212
213cc_defaults {
214    name: "fastboot_host_defaults",
215
216    use_version_lib: true,
217
218    cflags: [
219        "-Wall",
220        "-Wextra",
221        "-Werror",
222        "-Wunreachable-code",
223        "-DANDROID_BASE_UNIQUE_FD_DISABLE_IMPLICIT_CONVERSION",
224        "-D_FILE_OFFSET_BITS=64",
225    ],
226
227    target: {
228        darwin: {
229            cflags: ["-Wno-unused-parameter"],
230            host_ldlibs: [
231                "-lpthread",
232                "-framework CoreFoundation",
233                "-framework IOKit",
234            ],
235        },
236        windows: {
237            enabled: true,
238
239            host_ldlibs: ["-lws2_32"],
240        },
241        not_windows: {
242            static_libs: [
243                "libext4_utils",
244            ],
245        },
246    },
247
248    stl: "libc++_static",
249
250    // Don't add anything here, we don't want additional shared dependencies
251    // on the host fastboot tool, and shared libraries that link against libc++
252    // will violate ODR.
253    shared_libs: [],
254
255    header_libs: [
256        "avb_headers",
257        "bootimg_headers",
258    ],
259
260    static_libs: [
261        "libziparchive",
262        "libsparse",
263        "libutils",
264        "liblog",
265        "liblz4",
266        "libz",
267        "libdiagnose_usb",
268        "libbase",
269        "libcutils",
270        "libgtest_host",
271        "liblp",
272        "libcrypto",
273    ],
274}
275
276//
277// Build host libfastboot.
278//
279
280cc_library_host_static {
281    name: "libfastboot",
282    defaults: ["fastboot_host_defaults"],
283
284    srcs: [
285        "bootimg_utils.cpp",
286        "fastboot_driver.cpp",
287        "fastboot.cpp",
288        "filesystem.cpp",
289        "fs.cpp",
290        "socket.cpp",
291        "storage.cpp",
292        "super_flash_helper.cpp",
293        "tcp.cpp",
294        "udp.cpp",
295        "util.cpp",
296        "vendor_boot_img_utils.cpp",
297        "task.cpp",
298    ],
299
300    // Only version the final binaries
301    use_version_lib: false,
302    static_libs: ["libbuildversion"],
303    header_libs: [
304        "avb_headers",
305        "libstorage_literals_headers",
306    ],
307
308    generated_headers: ["platform_tools_version"],
309
310    tidy_flags: [
311        // DO NOT add quotes around header-filter flag regex argument,
312        // because build/soong will add quotes around the whole flag.
313        "-header-filter=(system/core/fastboot/|development/host/windows/usb/api/)",
314    ],
315
316    target: {
317        windows: {
318            srcs: ["usb_windows.cpp"],
319
320            include_dirs: ["development/host/windows/usb/api"],
321        },
322        darwin: {
323            srcs: ["usb_osx.cpp"],
324        },
325        linux: {
326            srcs: ["usb_linux.cpp"],
327        },
328    },
329}
330
331//
332// Build host fastboot / fastboot.exe
333//
334
335cc_binary_host {
336    name: "fastboot",
337    defaults: ["fastboot_host_defaults"],
338
339    srcs: ["main.cpp"],
340    static_libs: ["libfastboot"],
341
342    required: [
343        "mke2fs",
344        "make_f2fs",
345        "make_f2fs_casefold",
346    ],
347    dist: {
348        targets: [
349            "dist_files",
350            "sdk",
351            "sdk-repo-platform-tools",
352            "sdk_repo",
353            "win_sdk",
354        ],
355    },
356
357    target: {
358        not_windows: {
359            required: [
360                "mke2fs.conf",
361            ],
362        },
363        windows: {
364            required: ["AdbWinUsbApi"],
365            shared_libs: ["AdbWinApi"],
366        },
367    },
368}
369
370//
371// Build host fastboot_test.
372//
373
374cc_test_host {
375    name: "fastboot_test",
376    defaults: ["fastboot_host_defaults"],
377
378    srcs: [
379        "fastboot_driver_test.cpp",
380        "fastboot_test.cpp",
381        "socket_mock.cpp",
382        "socket_test.cpp",
383        "super_flash_helper_test.cpp",
384        "task_test.cpp",
385        "tcp_test.cpp",
386        "udp_test.cpp",
387    ],
388
389    static_libs: [
390        "libfastboot",
391        "libgmock",
392    ],
393
394    target: {
395        windows: {
396            shared_libs: ["AdbWinApi"],
397        },
398        windows_x86_64: {
399            // Avoid trying to build for win64
400            enabled: false,
401        },
402    },
403
404    test_suites: ["general-tests"],
405
406    data: [
407        "testdata/super.img",
408        "testdata/super_empty.img",
409        "testdata/system.img",
410    ],
411}
412
413cc_test_host {
414    name: "fastboot_vendor_boot_img_utils_test",
415    srcs: ["vendor_boot_img_utils_test.cpp"],
416    static_libs: [
417        "libbase",
418        "libc++fs",
419        "libfastboot",
420        "libgmock",
421        "liblog",
422    ],
423    header_libs: [
424        "avb_headers",
425        "bootimg_headers",
426    ],
427    cflags: [
428        "-Wall",
429        "-Werror",
430    ],
431    data: [
432        ":fastboot_test_dtb",
433        ":fastboot_test_bootconfig",
434        ":fastboot_test_vendor_ramdisk_none",
435        ":fastboot_test_vendor_ramdisk_platform",
436        ":fastboot_test_vendor_ramdisk_replace",
437        ":fastboot_test_vendor_boot_v3",
438        ":fastboot_test_vendor_boot_v4_without_frag",
439        ":fastboot_test_vendor_boot_v4_with_frag",
440    ],
441}
442
443cc_library_headers {
444    name: "fastboot_headers",
445    host_supported: true,
446    export_include_dirs: ["."],
447}
448