[avb] Add gn option to opt out using posix sysdeps
The existing implementation in avb_sysdeps_posix.cc does things like
"fprintf(stderr,..." which is not supported in physboot efi toolchain.
The CL adds a gn option to opt out of using it. This allows applications
built by non-supporting toolchains to implement their own sysdeps.
Bug: b/236039205
Change-Id: Icd891b724ae77c5699a72a82d56724de4c660023
diff --git a/BUILD.gn b/BUILD.gn
index d15b3be..2e6bf5f 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -3,6 +3,7 @@
# found in the LICENSE file.
import("//build/zircon/zx_library.gni")
+import("//third_party/android/platform/external/avb/sysdeps.gni")
# SDK library.
zx_library("avb") {
@@ -45,7 +46,6 @@
"libavb/avb_slot_verify.c",
"libavb/avb_slot_verify.h",
"libavb/avb_sysdeps.h",
- "libavb/avb_sysdeps_posix.c",
"libavb/avb_util.c",
"libavb/avb_util.h",
"libavb/avb_vbmeta_image.c",
@@ -57,6 +57,15 @@
"libavb_atx/avb_atx_validate.c",
"libavb_atx/avb_atx_validate.h",
]
+
+ if (use_posix_libavb_sysdeps) {
+ sources += [ "libavb/avb_sysdeps_posix.c" ]
+ } else {
+ # Allow avb_sysdeps.h to be included since depending targets will need to implement
+ # them.
+ public += [ "libavb/avb_sysdeps.h" ]
+ }
+
cflags_c = [
"-DAVB_COMPILATION",
"-Wno-implicit-int-conversion",
diff --git a/sysdeps.gni b/sysdeps.gni
new file mode 100644
index 0000000..a114ab4
--- /dev/null
+++ b/sysdeps.gni
@@ -0,0 +1,11 @@
+# Copyright 2022 The Fuchsia Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+declare_args() {
+ # Specify whether to use the posix sysdeps implementation provided by
+ # by libavb. This assumes that toolchain has support for stderr, stdin,
+ # malloc()/free() etc. See libavb/avb_sysdeps_posix.c for detail.
+ # If set to false, application must provide an implementation.
+ use_posix_libavb_sysdeps = true
+}