summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chavez <kechavez@google.com>2016-08-05 15:39:54 -0400
committerKevin Chavez <kechavez@google.com>2016-08-05 15:39:54 -0400
commitd77132927e03072d9a48b000102dd329669b2d17 (patch)
tree3f904bb01aa95c1db2ed0506fdc5304d85afb315
parent18ad887beaf6c13d5444150c54f1decabcc5c9c2 (diff)
downloadbrillo-d77132927e03072d9a48b000102dd329669b2d17.tar.gz
Fix Android build breakage caused by uefi boot loader missing bub_ops.h.
Change-Id: Idb8967588020d7c04578d6c8f0dbd30c2cb6bcdd
-rw-r--r--brillo_uefi_x86_64/boot_loader/bub_ops.h152
1 files changed, 152 insertions, 0 deletions
diff --git a/brillo_uefi_x86_64/boot_loader/bub_ops.h b/brillo_uefi_x86_64/boot_loader/bub_ops.h
new file mode 100644
index 0000000..f466459
--- /dev/null
+++ b/brillo_uefi_x86_64/boot_loader/bub_ops.h
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// NOTE: See avb_sysdeps.h
+
+#ifndef BUB_OPS_H_
+#define BUB_OPS_H_
+
+#include "bub_sysdeps.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Return codes used for I/O operations.
+ *
+ * BUB_IO_RESULT_OK is returned if the requested operation was
+ * successful.
+ *
+ * BUB_IO_RESULT_ERROR_NO_SUCH_PARTITION is returned if the requested
+ * partition does not exist.
+ *
+ * BUB_IO_RESULT_ERROR_RANGE_OUTSIDE_PARTITION is returned if the
+ * range of bytes requested to be read or written is outside the range
+ * of the partition.
+ *
+ * BUB_IO_RESULT_ERROR_IO is returned if the underlying disk
+ * encountered an I/O error.
+ */
+typedef enum {
+ BUB_IO_RESULT_OK,
+ BUB_IO_RESULT_ERROR_NO_SUCH_PARTITION,
+ BUB_IO_RESULT_ERROR_RANGE_OUTSIDE_PARTITION,
+ BUB_IO_RESULT_ERROR_IO,
+} BubIOResult;
+
+struct BubOps;
+typedef struct BubOps BubOps;
+
+/* High-level operations/functions/methods that are platform
+ * dependent.
+ */
+struct BubOps {
+ /* Reads |num_bytes| from offset |offset| from partition with name
+ * |partition| (NUL-terminated UTF-8 string). If |offset| is
+ * negative, its absolute value should be interpreted as the number
+ * of bytes from the end of the partition.
+ *
+ * This function returns BUB_IO_RESULT_ERROR_NO_SUCH_PARTITION if
+ * there is no partition with the given name,
+ * BUB_IO_RESULT_ERROR_RANGE_OUTSIDE_PARTITION if the requested
+ * |offset| is outside the partition, and BUB_IO_RESULT_ERROR_IO if
+ * there was an I/O error from the underlying I/O subsystem. If the
+ * operation succeeds as requested BUB_IO_RESULT_OK is returned and
+ * the data is available in |buf|.
+ *
+ * The only time partial I/O may occur is if reading beyond the end
+ * of the partition. In this case the value returned in
+ * |out_num_read| may be smaller than |num_bytes|.
+ */
+ BubIOResult (*read_from_partition)(BubOps* ops, const char* partition,
+ void* buf, int64_t offset,
+ size_t num_bytes, size_t* out_num_read);
+
+ /* Writes |num_bytes| at offset |offset| from partition with name
+ * |partition| (NUL-terminated UTF-8 string). If |offset| is
+ * negative, its absolute value should be interpreted as the number
+ * of bytes from the end of the partition.
+ *
+ * This function returns BUB_IO_RESULT_ERROR_NO_SUCH_PARTITION if
+ * there is no partition with the given name,
+ * BUB_IO_RESULT_ERROR_RANGE_OUTSIDE_PARTITION if the requested
+ * byterange goes outside the partition, and BUB_IO_RESULT_ERROR_IO
+ * if there was an I/O error from the underlying I/O subsystem. If
+ * the operation succeeds as requested BUB_IO_RESULT_OK is
+ * returned.
+ *
+ * This function never does any partial I/O, it either transfers all
+ * of the requested bytes or returns an error.
+ */
+ BubIOResult (*write_to_partition)(BubOps* ops, const char* partition,
+ const void* buf, int64_t offset,
+ size_t num_bytes);
+
+ /* Checks if the given public key is trusted. Return non-zero if
+ * trusted or zero if untrusted.
+ */
+ int (*validate_public_key)(BubOps* ops, const uint8_t* public_key_data,
+ size_t public_key_length);
+
+ /* Gets the rollback index corresponding to the slot given by
+ * |rollback_index_slot|. The value is returned in
+ * |out_rollback_index|. Returns non-zero if the rollback index was
+ * retrieved, zero on error.
+ *
+ * A device may have a limited amount of rollback index slots (say,
+ * one or four) so may error out if |rollback_index_slot| exceeds
+ * this number.
+ */
+ int (*read_rollback_index)(BubOps* ops, size_t rollback_index_slot,
+ uint64_t* out_rollback_index);
+
+ /* Sets the rollback index corresponding to the slot given by
+ * |rollback_index_slot| to |rollback_index|. Returns non-zero if
+ * the rollback index was set, zero on error.
+ *
+ * A device may have a limited amount of rollback index slots (say,
+ * one or four) so may error out if |rollback_index_slot| exceeds
+ * this number.
+ */
+ int (*write_rollback_index)(BubOps* ops, size_t rollback_index_slot,
+ uint64_t rollback_index);
+
+ /* Gets whether the device is unlocked. The value is returned in
+ * |out_is_unlocked| (non-zero if unlocked, zero otherwise). Returns
+ * non-zero if the state was retrieved, zero on error.
+ */
+ int (*read_is_unlocked)(BubOps* ops, int* out_is_unlocked);
+
+ /* Gets the unique partition GUID for a partition with name in
+ * |partition| (NUL-terminated UTF-8 string). The GUID is copied as
+ * a string into |guid_buf| of size |guid_buf_size| and will be NUL
+ * terminated. The string must be lower-case and properly
+ * hyphenated. For example:
+ *
+ * 527c1c6d-6361-4593-8842-3c78fcd39219
+ *
+ * Returns zero if the operation fails (no such partition or
+ * |buf_size| is too small), non-zero if it succeeds.
+ */
+ int (*get_unique_guid_for_partition)(BubOps* ops, const char* partition,
+ char* guid_buf, size_t guid_buf_size);
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BUB_OPS_H_ */ \ No newline at end of file