summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Kitching <kitching@google.com>2020-03-16 16:20:02 +0800
committerCommit Bot <commit-bot@chromium.org>2020-03-31 10:36:57 +0000
commit02f45f51a7e80bf7e62c3fa0926c3e30ccd7124d (patch)
tree655a4ea39d2f2485c369d6175476858d9fac88b8
parente3f71c97d05f5c659a0c2a2186dc62dd0586407f (diff)
downloadvboot-02f45f51a7e80bf7e62c3fa0926c3e30ccd7124d.tar.gz
vboot: stop using StrnAppend and Uint64ToString
Use snprintf instead. Remove utility_string library. Also, prepare VbDisplayDebugInfo to handle 64-byte nvdata. BUG=b:124141368, chromium:968464 TEST=make clean && make runtests TEST=boot with 16-byte nvdata, check <TAB> output (one line) TEST=boot with 64-byte nvdata, check <TAB> output (five lines) BRANCH=none Change-Id: If6c4b3a4e9fa7b71cb2d8ca7ccd37e4f36b97fd6 Signed-off-by: Joel Kitching <kitching@google.com> Cq-Depend: chromium:2122061 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/vboot_reference/+/2104880 Tested-by: Joel Kitching <kitching@chromium.org> Commit-Queue: Joel Kitching <kitching@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
-rw-r--r--Makefile4
-rw-r--r--cgpt/cgpt_add.c79
-rw-r--r--firmware/2lib/include/2sysincludes.h1
-rw-r--r--firmware/include/vboot_api.h2
-rw-r--r--firmware/lib/cgptlib/cgptlib.c1
-rw-r--r--firmware/lib/cgptlib/cgptlib_internal.c1
-rw-r--r--firmware/lib/gpt_misc.c1
-rw-r--r--firmware/lib/include/utility.h39
-rw-r--r--firmware/lib/tpm2_lite/marshaling.c1
-rw-r--r--firmware/lib/tpm2_lite/tlcl.c2
-rw-r--r--firmware/lib/tpm_lite/mocked_tlcl.c1
-rw-r--r--firmware/lib/tpm_lite/tlcl.c1
-rw-r--r--firmware/lib/utility_string.c72
-rw-r--r--firmware/lib/vboot_api_kernel.c1
-rw-r--r--firmware/lib/vboot_audio.c1
-rw-r--r--firmware/lib/vboot_display.c102
-rw-r--r--firmware/lib/vboot_kernel.c1
-rw-r--r--firmware/lib/vboot_ui_legacy_clamshell.c1
-rw-r--r--firmware/lib/vboot_ui_legacy_menu.c1
-rw-r--r--firmware/stub/tpm_lite_stub.c1
-rw-r--r--futility/cmd_update.c1
-rw-r--r--host/arch/x86/lib/crossystem_arch.c1
-rw-r--r--host/lib/crossystem.c1
-rw-r--r--host/lib/host_common.c1
-rw-r--r--host/lib/include/host_common.h1
-rw-r--r--host/lib/include/host_misc.h1
-rw-r--r--host/lib/include/host_signature.h1
-rw-r--r--tests/cgptlib_test.c1
-rw-r--r--tests/crc32_test.c1
-rw-r--r--tests/tpm_lite/readonly.c1
-rw-r--r--tests/tpm_lite/tpmtest_earlynvram.c1
-rw-r--r--tests/tpm_lite/tpmtest_earlynvram2.c1
-rw-r--r--tests/tpm_lite/tpmtest_testsetup.c1
-rw-r--r--tests/tpm_lite/tpmtest_timing.c1
-rw-r--r--tests/utility_string_tests.c123
-rw-r--r--tests/vb20_rsa_padding_tests.c1
-rw-r--r--tests/vb2_rsa_utility_tests.c1
-rw-r--r--tests/vboot_api_kernel_tests.c1
-rw-r--r--tests/verify_kernel.c5
-rw-r--r--utility/load_kernel_test.c1
40 files changed, 66 insertions, 393 deletions
diff --git a/Makefile b/Makefile
index e5220507..da3bf568 100644
--- a/Makefile
+++ b/Makefile
@@ -381,7 +381,6 @@ FWLIB_SRCS = \
firmware/lib/cgptlib/cgptlib_internal.c \
firmware/lib/cgptlib/crc32.c \
firmware/lib/gpt_misc.c \
- firmware/lib/utility_string.c \
firmware/lib/vboot_api_kernel.c \
firmware/lib/vboot_audio.c \
firmware/lib/vboot_display.c \
@@ -500,7 +499,6 @@ HOSTLIB_SRCS = \
firmware/lib/cgptlib/cgptlib_internal.c \
firmware/lib/cgptlib/crc32.c \
firmware/lib/gpt_misc.c \
- firmware/lib/utility_string.c \
firmware/stub/tpm_lite_stub.c \
firmware/stub/vboot_api_stub.c \
firmware/stub/vboot_api_stub_disk.c \
@@ -675,7 +673,6 @@ TEST_NAMES = \
tests/cgptlib_test \
tests/sha_benchmark \
tests/subprocess_tests \
- tests/utility_string_tests \
tests/vboot_api_kernel4_tests \
tests/vboot_api_kernel_tests \
tests/vboot_display_tests \
@@ -1203,7 +1200,6 @@ ifeq (${MOCK_TPM}${TPM2_MODE},)
# tlcl_tests only works when MOCK_TPM is disabled
${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
endif
- ${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
diff --git a/cgpt/cgpt_add.c b/cgpt/cgpt_add.c
index e2b0b32e..09a86ba9 100644
--- a/cgpt/cgpt_add.c
+++ b/cgpt/cgpt_add.c
@@ -3,72 +3,46 @@
* found in the LICENSE file.
*/
+#include <stdio.h>
#include <string.h>
#include "cgpt.h"
#include "cgptlib_internal.h"
#include "cgpt_params.h"
-#include "utility.h"
#include "vboot_host.h"
-static const char* DumpCgptAddParams(const CgptAddParams *params) {
- static char buf[256];
+static void PrintCgptAddParams(const CgptAddParams *params) {
char tmp[64];
- buf[0] = 0;
- snprintf(tmp, sizeof(tmp), "-i %d ", params->partition);
- StrnAppend(buf, tmp, sizeof(buf));
- if (params->label) {
- snprintf(tmp, sizeof(tmp), "-l %s ", params->label);
- StrnAppend(buf, tmp, sizeof(buf));
- }
- if (params->set_begin) {
- snprintf(tmp, sizeof(tmp), "-b %llu ", (unsigned long long)params->begin);
- StrnAppend(buf, tmp, sizeof(buf));
- }
- if (params->set_size) {
- snprintf(tmp, sizeof(tmp), "-s %llu ", (unsigned long long)params->size);
- StrnAppend(buf, tmp, sizeof(buf));
- }
+ fprintf(stderr, "-i %d ", params->partition);
+ if (params->label)
+ fprintf(stderr, "-l %s ", params->label);
+ if (params->set_begin)
+ fprintf(stderr, "-b %llu ", (unsigned long long)params->begin);
+ if (params->set_size)
+ fprintf(stderr, "-s %llu ", (unsigned long long)params->size);
if (params->set_type) {
GuidToStr(&params->type_guid, tmp, sizeof(tmp));
- StrnAppend(buf, "-t ", sizeof(buf));
- StrnAppend(buf, tmp, sizeof(buf));
- StrnAppend(buf, " ", sizeof(buf));
+ fprintf(stderr, "-t %s ", tmp);
}
if (params->set_unique) {
GuidToStr(&params->unique_guid, tmp, sizeof(tmp));
- StrnAppend(buf, "-u ", sizeof(buf));
- StrnAppend(buf, tmp, sizeof(buf));
- StrnAppend(buf, " ", sizeof(buf));
- }
- if (params->set_successful) {
- snprintf(tmp, sizeof(tmp), "-S %d ", params->successful);
- StrnAppend(buf, tmp, sizeof(buf));
+ fprintf(stderr, "-u %s ", tmp);
}
- if (params->set_tries) {
- snprintf(tmp, sizeof(tmp), "-T %d ", params->tries);
- StrnAppend(buf, tmp, sizeof(buf));
- }
- if (params->set_priority) {
- snprintf(tmp, sizeof(tmp), "-P %d ", params->priority);
- StrnAppend(buf, tmp, sizeof(buf));
- }
- if (params->set_required) {
- snprintf(tmp, sizeof(tmp), "-R %d ", params->required);
- StrnAppend(buf, tmp, sizeof(buf));
- }
- if (params->set_legacy_boot) {
- snprintf(tmp, sizeof(tmp), "-B %d ", params->legacy_boot);
- StrnAppend(buf, tmp, sizeof(buf));
- }
- if (params->set_raw) {
- snprintf(tmp, sizeof(tmp), "-A %#x ", params->raw_value);
- StrnAppend(buf, tmp, sizeof(buf));
- }
-
- StrnAppend(buf, "\n", sizeof(buf));
- return buf;
+ if (params->set_successful)
+ fprintf(stderr, "-S %d ", params->successful);
+ if (params->set_tries)
+ fprintf(stderr, "-T %d ", params->tries);
+ if (params->set_priority)
+ fprintf(stderr, "-P %d ", params->priority);
+ if (params->set_required)
+ fprintf(stderr, "-R %d ", params->required);
+ if (params->set_legacy_boot)
+ fprintf(stderr, "-B %d ", params->legacy_boot);
+ if (params->set_raw)
+ fprintf(stderr, "-A %#x ", params->raw_value);
+
+ fprintf(stderr, "\n");
}
// This is the implementation-specific helper function.
@@ -295,7 +269,8 @@ static int GptAdd(struct drive *drive, CgptAddParams *params, uint32_t index) {
// If the modified entry is illegal, recover it and return error.
memcpy(entry, &backup, sizeof(*entry));
Error("%s\n", GptErrorText(rv));
- Error(DumpCgptAddParams(params));
+ Error("");
+ PrintCgptAddParams(params);
return -1;
}
diff --git a/firmware/2lib/include/2sysincludes.h b/firmware/2lib/include/2sysincludes.h
index c23054a1..06717724 100644
--- a/firmware/2lib/include/2sysincludes.h
+++ b/firmware/2lib/include/2sysincludes.h
@@ -17,6 +17,7 @@
#include <inttypes.h> /* For PRIu64 */
#include <stddef.h>
#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
diff --git a/firmware/include/vboot_api.h b/firmware/include/vboot_api.h
index 7e141348..d3e05817 100644
--- a/firmware/include/vboot_api.h
+++ b/firmware/include/vboot_api.h
@@ -85,7 +85,7 @@ vb2_error_t VbSelectAndLoadKernel(struct vb2_context *ctx,
VbSelectAndLoadKernelParams *kparams);
/*****************************************************************************/
-/* Timer and delay (first two from utility.h) */
+/* Timer and delay */
#define VB_USEC_PER_MSEC 1000ULL
#define VB_MSEC_PER_SEC VB_USEC_PER_MSEC
diff --git a/firmware/lib/cgptlib/cgptlib.c b/firmware/lib/cgptlib/cgptlib.c
index db704b54..2cc77b4a 100644
--- a/firmware/lib/cgptlib/cgptlib.c
+++ b/firmware/lib/cgptlib/cgptlib.c
@@ -9,7 +9,6 @@
#include "cgptlib_internal.h"
#include "crc32.h"
#include "gpt.h"
-#include "utility.h"
#include "vboot_api.h"
int GptInit(GptData *gpt)
diff --git a/firmware/lib/cgptlib/cgptlib_internal.c b/firmware/lib/cgptlib/cgptlib_internal.c
index 7d214a91..593b1e2c 100644
--- a/firmware/lib/cgptlib/cgptlib_internal.c
+++ b/firmware/lib/cgptlib/cgptlib_internal.c
@@ -9,7 +9,6 @@
#include "crc32.h"
#include "gpt.h"
#include "gpt_misc.h"
-#include "utility.h"
const static int MIN_SECTOR_SIZE = 512;
diff --git a/firmware/lib/gpt_misc.c b/firmware/lib/gpt_misc.c
index 6d91ec15..ae7f8a23 100644
--- a/firmware/lib/gpt_misc.c
+++ b/firmware/lib/gpt_misc.c
@@ -9,7 +9,6 @@
#include "cgptlib_internal.h"
#include "crc32.h"
#include "gpt.h"
-#include "utility.h"
#include "vboot_api.h"
/**
diff --git a/firmware/lib/include/utility.h b/firmware/lib/include/utility.h
deleted file mode 100644
index bca49828..00000000
--- a/firmware/lib/include/utility.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Helper functions/wrappers for memory allocations, manipulation and
- * comparison.
- */
-
-#ifndef VBOOT_REFERENCE_UTILITY_H_
-#define VBOOT_REFERENCE_UTILITY_H_
-
-#include "2common.h"
-#include "2sysincludes.h"
-#include "vboot_api.h"
-
-/*
- * Buffer size required to hold the longest possible output of Uint64ToString()
- * - that is, Uint64ToString(~0, 2).
- */
-#define UINT64_TO_STRING_MAX 65
-
-/**
- * Convert a value to a string in the specified radix (2=binary, 10=decimal,
- * 16=hex) and store it in <buf>, which is <bufsize> chars long. If
- * <zero_pad_width>, left-pads the string to at least that width with '0'.
- * Returns the length of the stored string, not counting the terminating null.
- */
-uint32_t Uint64ToString(char *buf, uint32_t bufsize, uint64_t value,
- uint32_t radix, uint32_t zero_pad_width);
-
-/**
- * Concatenate <src> onto <dest>, which has space for <destlen> characters
- * including the terminating null. Note that <dest> will always be
- * null-terminated if <destlen> > 0. Returns the number of characters used in
- * <dest>, not counting the terminating null.
- */
-uint32_t StrnAppend(char *dest, const char *src, uint32_t destlen);
-
-#endif /* VBOOT_REFERENCE_UTILITY_H_ */
diff --git a/firmware/lib/tpm2_lite/marshaling.c b/firmware/lib/tpm2_lite/marshaling.c
index 90ce04ca..ef3606b9 100644
--- a/firmware/lib/tpm2_lite/marshaling.c
+++ b/firmware/lib/tpm2_lite/marshaling.c
@@ -6,7 +6,6 @@
#include "2common.h"
#include "2sysincludes.h"
#include "tpm2_marshaling.h"
-#include "utility.h"
static uint16_t tpm_tag; /* Depends on the command type. */
static int ph_disabled; /* Platform hierarchy disabled. */
diff --git a/firmware/lib/tpm2_lite/tlcl.c b/firmware/lib/tpm2_lite/tlcl.c
index dca8facc..9bacbb6b 100644
--- a/firmware/lib/tpm2_lite/tlcl.c
+++ b/firmware/lib/tpm2_lite/tlcl.c
@@ -10,7 +10,7 @@
#include "2sysincludes.h"
#include "tlcl.h"
#include "tpm2_marshaling.h"
-#include "utility.h"
+#include "vboot_api.h"
/*
* TODO(chromium:1032930): Originally accessed by including secdata_tpm.h.
diff --git a/firmware/lib/tpm_lite/mocked_tlcl.c b/firmware/lib/tpm_lite/mocked_tlcl.c
index d0f61201..838b5e7e 100644
--- a/firmware/lib/tpm_lite/mocked_tlcl.c
+++ b/firmware/lib/tpm_lite/mocked_tlcl.c
@@ -6,7 +6,6 @@
#include "2sysincludes.h"
#include "tlcl.h"
#include "tlcl_internal.h"
-#include "utility.h"
#include "vboot_api.h"
uint32_t TlclLibInit(void)
diff --git a/firmware/lib/tpm_lite/tlcl.c b/firmware/lib/tpm_lite/tlcl.c
index b6685bf8..28c0bb63 100644
--- a/firmware/lib/tpm_lite/tlcl.c
+++ b/firmware/lib/tpm_lite/tlcl.c
@@ -21,7 +21,6 @@
#include "tlcl.h"
#include "tlcl_internal.h"
#include "tlcl_structures.h"
-#include "utility.h"
#include "vboot_api.h"
/* Sets the size field of a TPM command. */
diff --git a/firmware/lib/utility_string.c b/firmware/lib/utility_string.c
deleted file mode 100644
index 299bbaa1..00000000
--- a/firmware/lib/utility_string.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * String utility functions that need to be built as part of the firmware.
- */
-
-#include "2sysincludes.h"
-#include "utility.h"
-
-uint32_t Uint64ToString(char *buf, uint32_t bufsize, uint64_t value,
- uint32_t radix, uint32_t zero_pad_width)
-{
- char ibuf[UINT64_TO_STRING_MAX];
- char *s;
- uint32_t usedsize = 1;
-
- if (!buf)
- return 0;
-
- /* Clear output buffer in case of error */
- *buf = '\0';
-
- /* Sanity-check input args */
- if (radix < 2 || radix > 36 || zero_pad_width >= UINT64_TO_STRING_MAX)
- return 0;
-
- /* Start at end of string and work backwards */
- s = ibuf + UINT64_TO_STRING_MAX - 1;
- *(s) = '\0';
- do {
- int v = value % radix;
- value /= radix;
-
- *(--s) = (char)(v < 10 ? v + '0' : v + 'a' - 10);
- if (++usedsize > bufsize)
- return 0; /* Result won't fit in buffer */
- } while (value);
-
- /* Zero-pad if necessary */
- while (usedsize <= zero_pad_width) {
- *(--s) = '0';
- if (++usedsize > bufsize)
- return 0; /* Result won't fit in buffer */
- }
-
- /* Now copy the string back to the input buffer. */
- memcpy(buf, s, usedsize);
-
- /* Don't count the terminating null in the bytes used */
- return usedsize - 1;
-}
-
-uint32_t StrnAppend(char *dest, const char *src, uint32_t destlen)
-{
- uint32_t used = 0;
-
- if (!dest || !src || !destlen)
- return 0;
-
- /* Skip past existing string in destination.*/
- while (dest[used] && used < destlen - 1)
- used++;
-
- /* Now copy source */
- while (*src && used < destlen - 1)
- dest[used++] = *src++;
-
- /* Terminate destination and return count of non-null characters */
- dest[used] = 0;
- return used;
-}
diff --git a/firmware/lib/vboot_api_kernel.c b/firmware/lib/vboot_api_kernel.c
index 4f86046a..6111eee0 100644
--- a/firmware/lib/vboot_api_kernel.c
+++ b/firmware/lib/vboot_api_kernel.c
@@ -15,7 +15,6 @@
#include "2sysincludes.h"
#include "2ui.h"
#include "load_kernel_fw.h"
-#include "utility.h"
#include "vb2_common.h"
#include "vboot_api.h"
#include "vboot_kernel.h"
diff --git a/firmware/lib/vboot_audio.c b/firmware/lib/vboot_audio.c
index 20b14376..5e44606d 100644
--- a/firmware/lib/vboot_audio.c
+++ b/firmware/lib/vboot_audio.c
@@ -8,7 +8,6 @@
#include "2common.h"
#include "2misc.h"
#include "2sysincludes.h"
-#include "utility.h"
#include "vboot_api.h"
#include "vboot_audio.h"
diff --git a/firmware/lib/vboot_display.c b/firmware/lib/vboot_display.c
index 258619fb..07e1da0a 100644
--- a/firmware/lib/vboot_display.c
+++ b/firmware/lib/vboot_display.c
@@ -10,7 +10,6 @@
#include "2nvstorage.h"
#include "2sha.h"
#include "2sysincludes.h"
-#include "utility.h"
#include "vboot_api.h"
#include "vboot_display.h"
#include "vboot_kernel.h"
@@ -216,7 +215,12 @@ const char *RecoveryReasonString(uint8_t code)
return "Unknown or deprecated error code";
}
-#define DEBUG_INFO_SIZE 512
+#define DEBUG_INFO_SIZE 1024
+#define DEBUG_INFO_APPEND(format, args...) do { \
+ if (used < DEBUG_INFO_SIZE) \
+ used += snprintf(buf + used, DEBUG_INFO_SIZE - used, format, \
+ ## args); \
+} while (0)
vb2_error_t VbDisplayDebugInfo(struct vb2_context *ctx)
{
@@ -225,7 +229,7 @@ vb2_error_t VbDisplayDebugInfo(struct vb2_context *ctx)
struct vb2_workbuf wb;
char buf[DEBUG_INFO_SIZE] = "";
char sha1sum[VB2_SHA1_DIGEST_SIZE * 2 + 1];
- uint32_t used = 0;
+ int32_t used = 0;
vb2_error_t ret;
uint32_t i;
@@ -238,83 +242,53 @@ vb2_error_t VbDisplayDebugInfo(struct vb2_context *ctx)
ret = vb2api_gbb_read_hwid(ctx, hwid, &size);
if (ret)
strcpy(hwid, "{INVALID}");
- used += StrnAppend(buf + used, "HWID: ",
- DEBUG_INFO_SIZE - used);
- used += StrnAppend(buf + used, hwid, DEBUG_INFO_SIZE - used);
+ DEBUG_INFO_APPEND("HWID: %s", hwid);
}
/* Add recovery reason and subcode */
i = vb2_nv_get(ctx, VB2_NV_RECOVERY_SUBCODE);
- used += StrnAppend(buf + used,
- "\nrecovery_reason: 0x", DEBUG_INFO_SIZE - used);
- used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
- sd->recovery_reason, 16, 2);
- used += StrnAppend(buf + used, " / 0x", DEBUG_INFO_SIZE - used);
- used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used, i, 16, 2);
- used += StrnAppend(buf + used, " ", DEBUG_INFO_SIZE - used);
- used += StrnAppend(buf + used,
- RecoveryReasonString(sd->recovery_reason),
- DEBUG_INFO_SIZE - used);
+ DEBUG_INFO_APPEND("\nrecovery_reason: %#.2x / %#.2x %s",
+ sd->recovery_reason, i,
+ RecoveryReasonString(sd->recovery_reason));
/* Add vb2_context and vb2_shared_data flags */
- used += StrnAppend(buf + used, "\ncontext.flags: 0x",
- DEBUG_INFO_SIZE - used);
- used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
- ctx->flags, 16, 16);
- used += StrnAppend(buf + used, "\nshared_data.flags: 0x",
- DEBUG_INFO_SIZE - used);
- used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
- sd->flags, 16, 8);
- used += StrnAppend(buf + used, "\nshared_data.status: 0x",
- DEBUG_INFO_SIZE - used);
- used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
- sd->status, 16, 8);
-
- /* Add raw contents of VbNvStorage */
- used += StrnAppend(buf + used, "\nVbNv.raw:", DEBUG_INFO_SIZE - used);
+ DEBUG_INFO_APPEND("\ncontext.flags: %#.16" PRIx64, ctx->flags);
+ DEBUG_INFO_APPEND("\nshared_data.flags: %#.8x", sd->flags);
+ DEBUG_INFO_APPEND("\nshared_data.status: %#.8x", sd->status);
+
+ /* Add raw contents of nvdata */
+ DEBUG_INFO_APPEND("\nnvdata:");
+ if (vb2_nv_get_size(ctx) > 16) /* Multi-line starts on next line */
+ DEBUG_INFO_APPEND("\n ");
for (i = 0; i < vb2_nv_get_size(ctx); i++) {
- used += StrnAppend(buf + used, " ", DEBUG_INFO_SIZE - used);
- used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
- ctx->nvdata[i], 16, 2);
+ /* Split into 16-byte blocks */
+ if (i > 0 && i % 16 == 0)
+ DEBUG_INFO_APPEND("\n ");
+ DEBUG_INFO_APPEND(" %02x", ctx->nvdata[i]);
}
/* Add dev_boot_usb flag */
i = vb2_nv_get(ctx, VB2_NV_DEV_BOOT_USB);
- used += StrnAppend(buf + used, "\ndev_boot_usb: ", DEBUG_INFO_SIZE - used);
- used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used, i, 10, 0);
+ DEBUG_INFO_APPEND("\ndev_boot_usb: %d", i);
/* Add dev_boot_legacy flag */
i = vb2_nv_get(ctx, VB2_NV_DEV_BOOT_LEGACY);
- used += StrnAppend(buf + used,
- "\ndev_boot_legacy: ", DEBUG_INFO_SIZE - used);
- used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used, i, 10, 0);
+ DEBUG_INFO_APPEND("\ndev_boot_legacy: %d", i);
/* Add dev_default_boot flag */
i = vb2_nv_get(ctx, VB2_NV_DEV_DEFAULT_BOOT);
- used += StrnAppend(buf + used,
- "\ndev_default_boot: ", DEBUG_INFO_SIZE - used);
- used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used, i, 10, 0);
+ DEBUG_INFO_APPEND("\ndev_default_boot: %d", i);
/* Add dev_boot_signed_only flag */
i = vb2_nv_get(ctx, VB2_NV_DEV_BOOT_SIGNED_ONLY);
- used += StrnAppend(buf + used, "\ndev_boot_signed_only: ",
- DEBUG_INFO_SIZE - used);
- used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used, i, 10, 0);
+ DEBUG_INFO_APPEND("\ndev_boot_signed_only: %d", i);
/* Add TPM versions */
- used += StrnAppend(buf + used,
- "\nTPM: fwver=0x", DEBUG_INFO_SIZE - used);
- used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
- sd->fw_version_secdata, 16, 8);
- used += StrnAppend(buf + used, " kernver=0x", DEBUG_INFO_SIZE - used);
- used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
- sd->kernel_version_secdata, 16, 8);
+ DEBUG_INFO_APPEND("\nTPM: fwver=%#.8x kernver=%#.8x",
+ sd->fw_version_secdata, sd->kernel_version_secdata);
/* Add GBB flags */
- used += StrnAppend(buf + used,
- "\ngbb.flags: 0x", DEBUG_INFO_SIZE - used);
- used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
- gbb->flags, 16, 8);
+ DEBUG_INFO_APPEND("\ngbb.flags: %#.8x", gbb->flags);
/* Add sha1sum for Root & Recovery keys */
{
@@ -323,10 +297,7 @@ vb2_error_t VbDisplayDebugInfo(struct vb2_context *ctx)
ret = vb2_gbb_read_root_key(ctx, &key, NULL, &wblocal);
if (!ret) {
FillInSha1Sum(sha1sum, key);
- used += StrnAppend(buf + used, "\ngbb.rootkey: ",
- DEBUG_INFO_SIZE - used);
- used += StrnAppend(buf + used, sha1sum,
- DEBUG_INFO_SIZE - used);
+ DEBUG_INFO_APPEND("\ngbb.rootkey: %s", sha1sum);
}
}
@@ -336,10 +307,7 @@ vb2_error_t VbDisplayDebugInfo(struct vb2_context *ctx)
ret = vb2_gbb_read_recovery_key(ctx, &key, NULL, &wblocal);
if (!ret) {
FillInSha1Sum(sha1sum, key);
- used += StrnAppend(buf + used, "\ngbb.recovery_key: ",
- DEBUG_INFO_SIZE - used);
- used += StrnAppend(buf + used, sha1sum,
- DEBUG_INFO_SIZE - used);
+ DEBUG_INFO_APPEND("\ngbb.recovery_key: %s", sha1sum);
}
}
@@ -349,13 +317,11 @@ vb2_error_t VbDisplayDebugInfo(struct vb2_context *ctx)
struct vb2_packed_key *key =
vb2_member_of(sd, sd->kernel_key_offset);
FillInSha1Sum(sha1sum, key);
- used += StrnAppend(buf + used,
- "\nkernel_subkey: ", DEBUG_INFO_SIZE - used);
- used += StrnAppend(buf + used, sha1sum, DEBUG_INFO_SIZE - used);
+ DEBUG_INFO_APPEND("\nkernel_subkey: %s", sha1sum);
}
/* Make sure we finish with a newline */
- used += StrnAppend(buf + used, "\n", DEBUG_INFO_SIZE - used);
+ DEBUG_INFO_APPEND("\n");
/* TODO: add more interesting data:
* - Information on current disks */
diff --git a/firmware/lib/vboot_kernel.c b/firmware/lib/vboot_kernel.c
index 8118599d..7420a697 100644
--- a/firmware/lib/vboot_kernel.c
+++ b/firmware/lib/vboot_kernel.c
@@ -17,7 +17,6 @@
#include "cgptlib_internal.h"
#include "gpt_misc.h"
#include "load_kernel_fw.h"
-#include "utility.h"
#include "vb2_common.h"
#include "vboot_api.h"
#include "vboot_kernel.h"
diff --git a/firmware/lib/vboot_ui_legacy_clamshell.c b/firmware/lib/vboot_ui_legacy_clamshell.c
index 959981dd..c510d58f 100644
--- a/firmware/lib/vboot_ui_legacy_clamshell.c
+++ b/firmware/lib/vboot_ui_legacy_clamshell.c
@@ -13,7 +13,6 @@
#include "2sysincludes.h"
#include "load_kernel_fw.h"
#include "tlcl.h"
-#include "utility.h"
#include "vb2_common.h"
#include "vboot_api.h"
#include "vboot_audio.h"
diff --git a/firmware/lib/vboot_ui_legacy_menu.c b/firmware/lib/vboot_ui_legacy_menu.c
index b0cfb43b..48eaabe9 100644
--- a/firmware/lib/vboot_ui_legacy_menu.c
+++ b/firmware/lib/vboot_ui_legacy_menu.c
@@ -12,7 +12,6 @@
#include "2secdata.h"
#include "2sysincludes.h"
#include "load_kernel_fw.h"
-#include "utility.h"
#include "vb2_common.h"
#include "vboot_api.h"
#include "vboot_audio.h"
diff --git a/firmware/stub/tpm_lite_stub.c b/firmware/stub/tpm_lite_stub.c
index 5fd673f2..54accb56 100644
--- a/firmware/stub/tpm_lite_stub.c
+++ b/firmware/stub/tpm_lite_stub.c
@@ -23,7 +23,6 @@
#include "2sysincludes.h"
#include "tlcl.h"
#include "tlcl_internal.h"
-#include "utility.h"
#include "vboot_api.h"
#define TPM_DEVICE_PATH "/dev/tpm0"
diff --git a/futility/cmd_update.c b/futility/cmd_update.c
index 70e699a2..e83095fb 100644
--- a/futility/cmd_update.c
+++ b/futility/cmd_update.c
@@ -11,7 +11,6 @@
#include "futility.h"
#include "updater.h"
-#include "utility.h"
enum {
OPT_DUMMY = 0x100,
diff --git a/host/arch/x86/lib/crossystem_arch.c b/host/arch/x86/lib/crossystem_arch.c
index a57fcde5..eba9661a 100644
--- a/host/arch/x86/lib/crossystem_arch.c
+++ b/host/arch/x86/lib/crossystem_arch.c
@@ -21,7 +21,6 @@
#include "crossystem.h"
#include "crossystem_vbnv.h"
#include "host_common.h"
-#include "utility.h"
#include "vboot_struct.h"
/* ACPI constants from Chrome OS Main Processor Firmware Spec */
diff --git a/host/lib/crossystem.c b/host/lib/crossystem.c
index 2ba21e64..cf7600e4 100644
--- a/host/lib/crossystem.c
+++ b/host/lib/crossystem.c
@@ -17,7 +17,6 @@
#include "crossystem_vbnv.h"
#include "host_common.h"
#include "subprocess.h"
-#include "utility.h"
#include "vboot_struct.h"
/* Filename for kernel command line */
diff --git a/host/lib/host_common.c b/host/lib/host_common.c
index 00f9100e..63b45f2e 100644
--- a/host/lib/host_common.c
+++ b/host/lib/host_common.c
@@ -12,7 +12,6 @@
#include "2sysincludes.h"
#include "host_common.h"
#include "host_key21.h"
-#include "utility.h"
#include "vb2_common.h"
struct vb2_fw_preamble *vb2_create_fw_preamble(
diff --git a/host/lib/include/host_common.h b/host/lib/include/host_common.h
index 5fcc5c52..43cb0250 100644
--- a/host/lib/include/host_common.h
+++ b/host/lib/include/host_common.h
@@ -13,7 +13,6 @@
#include "host_keyblock.h"
#include "host_misc.h"
#include "host_signature.h"
-#include "utility.h"
#include "vboot_api.h"
#include "vboot_struct.h"
diff --git a/host/lib/include/host_misc.h b/host/lib/include/host_misc.h
index 1aed20a7..9759d44d 100644
--- a/host/lib/include/host_misc.h
+++ b/host/lib/include/host_misc.h
@@ -8,7 +8,6 @@
#ifndef VBOOT_REFERENCE_HOST_MISC_H_
#define VBOOT_REFERENCE_HOST_MISC_H_
-#include "utility.h"
#include "vboot_struct.h"
/* Copy up to dest_size-1 characters from src to dest, ensuring null
diff --git a/host/lib/include/host_signature.h b/host/lib/include/host_signature.h
index 682840c4..72160fd2 100644
--- a/host/lib/include/host_signature.h
+++ b/host/lib/include/host_signature.h
@@ -9,7 +9,6 @@
#define VBOOT_REFERENCE_HOST_SIGNATURE_H_
#include "host_key.h"
-#include "utility.h"
#include "vboot_struct.h"
struct vb2_private_key;
diff --git a/tests/cgptlib_test.c b/tests/cgptlib_test.c
index ee7cb9da..e522592c 100644
--- a/tests/cgptlib_test.c
+++ b/tests/cgptlib_test.c
@@ -13,7 +13,6 @@
#include "crc32_test.h"
#include "gpt.h"
#include "test_common.h"
-#include "utility.h"
/*
* Testing partition layout (sector_bytes=512)
diff --git a/tests/crc32_test.c b/tests/crc32_test.c
index aeb48b34..1d1d8cd3 100644
--- a/tests/crc32_test.c
+++ b/tests/crc32_test.c
@@ -7,7 +7,6 @@
#include "crc32.h"
#include "crc32_test.h"
#include "test_common.h"
-#include "utility.h"
#define MAX_VECTOR_LEN 256
diff --git a/tests/tpm_lite/readonly.c b/tests/tpm_lite/readonly.c
index c3940e12..68de06b4 100644
--- a/tests/tpm_lite/readonly.c
+++ b/tests/tpm_lite/readonly.c
@@ -14,7 +14,6 @@
#include <stdlib.h>
#include "tlcl.h"
-#include "utility.h"
/* These index values are used to create NVRAM spaces. They only need to be
* unique.
diff --git a/tests/tpm_lite/tpmtest_earlynvram.c b/tests/tpm_lite/tpmtest_earlynvram.c
index d5ff77f5..db44862f 100644
--- a/tests/tpm_lite/tpmtest_earlynvram.c
+++ b/tests/tpm_lite/tpmtest_earlynvram.c
@@ -12,7 +12,6 @@
#include "tlcl.h"
#include "tlcl_tests.h"
-#include "utility.h"
#define INDEX0 0xcafe
diff --git a/tests/tpm_lite/tpmtest_earlynvram2.c b/tests/tpm_lite/tpmtest_earlynvram2.c
index 88f6a6b4..9307a588 100644
--- a/tests/tpm_lite/tpmtest_earlynvram2.c
+++ b/tests/tpm_lite/tpmtest_earlynvram2.c
@@ -12,7 +12,6 @@
#include "tlcl.h"
#include "tlcl_tests.h"
-#include "utility.h"
int main(int argc, char** argv) {
uint32_t x;
diff --git a/tests/tpm_lite/tpmtest_testsetup.c b/tests/tpm_lite/tpmtest_testsetup.c
index ce360994..a6331d9d 100644
--- a/tests/tpm_lite/tpmtest_testsetup.c
+++ b/tests/tpm_lite/tpmtest_testsetup.c
@@ -12,7 +12,6 @@
#include "tlcl.h"
#include "tlcl_tests.h"
-#include "utility.h"
int main(int argc, char** argv) {
uint32_t perm;
diff --git a/tests/tpm_lite/tpmtest_timing.c b/tests/tpm_lite/tpmtest_timing.c
index 1ec14a2e..eaba52f4 100644
--- a/tests/tpm_lite/tpmtest_timing.c
+++ b/tests/tpm_lite/tpmtest_timing.c
@@ -16,7 +16,6 @@
#include "tlcl.h"
#include "tlcl_tests.h"
-#include "utility.h"
/* Runs [op] and ensures it returns success and doesn't run longer than
* [time_limit] in milliseconds.
diff --git a/tests/utility_string_tests.c b/tests/utility_string_tests.c
deleted file mode 100644
index d41cbe87..00000000
--- a/tests/utility_string_tests.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/* Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- *
- * Tests for string utility functions.
- */
-
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "test_common.h"
-#include "utility.h"
-
-/* Test string concatenation */
-static void StrncatTest(void) {
- char dest[128];
-
- /* Null inputs */
- TEST_EQ(0, StrnAppend(dest, NULL, sizeof(dest)),
- "StrnAppend('', null)");
- TEST_EQ(0, StrnAppend(NULL, "Hey!", sizeof(dest)),
- "StrnAppend(null, '')");
-
- /* Empty <-- empty */
- *dest = 0;
- TEST_EQ(0, StrnAppend(dest, "", sizeof(dest)), "StrnAppend('', '')");
- TEST_EQ(0, strcmp(dest, ""), "StrnAppend('', '') result");
-
- /* Nonempty <-- empty */
- strcpy(dest, "Bob");
- TEST_EQ(3, StrnAppend(dest, "", sizeof(dest)), "StrnAppend(B, '')");
- TEST_EQ(0, strcmp(dest, "Bob"), "StrnAppend(B, '') result");
-
- /* Empty <-- nonempty */
- *dest = 0;
- TEST_EQ(5, StrnAppend(dest, "Alice", sizeof(dest)),
- "StrnAppend('', A)");
- TEST_EQ(0, strcmp(dest, "Alice"), "StrnAppend('', A) result");
-
- /* Nonempty <-- nonempty */
- strcpy(dest, "Tigre");
- TEST_EQ(10, StrnAppend(dest, "Bunny", sizeof(dest)),
- "StrnAppend(T, B)");
- TEST_EQ(0, strcmp(dest, "TigreBunny"), "StrnAppend(T, B) result");
-
- /* Test clipping */
- strcpy(dest, "YesI");
- TEST_EQ(7, StrnAppend(dest, "Can't", 8), "StrnAppend(Y, over)");
- TEST_EQ(0, strcmp(dest, "YesICan"), "StrnAppend(Y, over) result");
-
- /* Test clipping if dest already overflows its claimed length */
- strcpy(dest, "BudgetDeficit");
- TEST_EQ(6, StrnAppend(dest, "Spending", 7), "StrnAppend(over, over)");
- TEST_EQ(0, strcmp(dest, "Budget"), "StrnAppend(over, over) result");
-}
-
-
-static void TestU64ToS(uint64_t value, uint32_t radix, uint32_t zero_pad_width,
- const char *expect) {
- char dest[UINT64_TO_STRING_MAX];
-
- TEST_EQ(strlen(expect),
- Uint64ToString(dest, sizeof(dest), value, radix,
- zero_pad_width),
- "Uint64ToString");
- printf("Uint64ToString expect %s got %s\n", expect, dest);
- TEST_EQ(0, strcmp(dest, expect), "Uint64ToString result");
-}
-
-
-/* Test uint64 to string conversion */
-static void Uint64ToStringTest(void) {
- char dest[UINT64_TO_STRING_MAX];
-
- /* Test invalid inputs */
- TEST_EQ(0, Uint64ToString(NULL, 8, 123, 10, 8),
- "Uint64ToString null dest");
- TestU64ToS(0, 1, 0, "");
- TestU64ToS(0, 37, 0, "");
-
- /* Binary */
- TestU64ToS(0, 2, 0, "0");
- TestU64ToS(0x9A, 2, 0, "10011010");
- TestU64ToS(0x71, 2, 12, "000001110001");
- TestU64ToS(~0ULL, 2, 0,
- "1111111111111111111111111111111111111111111111111111111111111111");
-
- /* Decimal */
- TestU64ToS(0, 10, 0, "0");
- TestU64ToS(12345, 10, 0, "12345");
- TestU64ToS(67890, 10, 8, "00067890");
- TestU64ToS(~0ULL, 10, 0, "18446744073709551615");
-
- /* Hex */
- TestU64ToS(0, 16, 0, "0");
- TestU64ToS(0x12345678, 16, 0, "12345678");
- TestU64ToS(0x9ABCDEF, 16, 8, "09abcdef");
- TestU64ToS(~0ULL, 16, 0, "ffffffffffffffff");
-
- /* Zero pad corner cases */
- /* Don't pad if over length */
- TestU64ToS(0x1234567890ULL, 16, 8, "1234567890");
- /* Fail if padding won't fit in buffer */
- TEST_EQ(0, Uint64ToString(dest, 8, 123, 10, 8),
- "Uint64ToString bad pad");
- TEST_EQ(0, strcmp(dest, ""), "Uint64ToString bad pad result");
-
-}
-
-
-int main(int argc, char* argv[]) {
- int error_code = 0;
-
- StrncatTest();
- Uint64ToStringTest();
-
- if (!gTestSuccess)
- error_code = 255;
-
- return error_code;
-}
diff --git a/tests/vb20_rsa_padding_tests.c b/tests/vb20_rsa_padding_tests.c
index be9d91b5..8a0d58af 100644
--- a/tests/vb20_rsa_padding_tests.c
+++ b/tests/vb20_rsa_padding_tests.c
@@ -12,7 +12,6 @@
#include "host_key.h"
#include "rsa_padding_test.h"
#include "test_common.h"
-#include "utility.h"
#include "vb2_common.h"
/**
diff --git a/tests/vb2_rsa_utility_tests.c b/tests/vb2_rsa_utility_tests.c
index 989b401e..cc856e88 100644
--- a/tests/vb2_rsa_utility_tests.c
+++ b/tests/vb2_rsa_utility_tests.c
@@ -12,7 +12,6 @@
#include "file_keys.h"
#include "rsa_padding_test.h"
#include "test_common.h"
-#include "utility.h"
#include "vboot_api.h"
#include "vboot_test.h"
diff --git a/tests/vboot_api_kernel_tests.c b/tests/vboot_api_kernel_tests.c
index d7c32357..bcb5d046 100644
--- a/tests/vboot_api_kernel_tests.c
+++ b/tests/vboot_api_kernel_tests.c
@@ -11,7 +11,6 @@
#include "2sysincludes.h"
#include "load_kernel_fw.h"
#include "test_common.h"
-#include "utility.h"
#include "vboot_api.h"
#include "vboot_kernel.h"
#include "vboot_test.h"
diff --git a/tests/verify_kernel.c b/tests/verify_kernel.c
index 28813c40..9aaad723 100644
--- a/tests/verify_kernel.c
+++ b/tests/verify_kernel.c
@@ -5,12 +5,9 @@
* Routines for verifying a kernel or disk image
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
#include "2sysincludes.h"
#include "2api.h"
+#include "2common.h"
#include "2misc.h"
#include "2nvstorage.h"
#include "host_common.h"
diff --git a/utility/load_kernel_test.c b/utility/load_kernel_test.c
index 609a9a3a..c5dc7cb6 100644
--- a/utility/load_kernel_test.c
+++ b/utility/load_kernel_test.c
@@ -11,6 +11,7 @@
#include <unistd.h>
#include "2api.h"
+#include "2common.h"
#include "2misc.h"
#include "2sysincludes.h"
#include "host_common.h"