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>
This commit is contained in:
parent
e3f71c97d0
commit
02f45f51a7
4
Makefile
4
Makefile
|
@ -381,7 +381,6 @@ FWLIB_SRCS = \
|
||||||
firmware/lib/cgptlib/cgptlib_internal.c \
|
firmware/lib/cgptlib/cgptlib_internal.c \
|
||||||
firmware/lib/cgptlib/crc32.c \
|
firmware/lib/cgptlib/crc32.c \
|
||||||
firmware/lib/gpt_misc.c \
|
firmware/lib/gpt_misc.c \
|
||||||
firmware/lib/utility_string.c \
|
|
||||||
firmware/lib/vboot_api_kernel.c \
|
firmware/lib/vboot_api_kernel.c \
|
||||||
firmware/lib/vboot_audio.c \
|
firmware/lib/vboot_audio.c \
|
||||||
firmware/lib/vboot_display.c \
|
firmware/lib/vboot_display.c \
|
||||||
|
@ -500,7 +499,6 @@ HOSTLIB_SRCS = \
|
||||||
firmware/lib/cgptlib/cgptlib_internal.c \
|
firmware/lib/cgptlib/cgptlib_internal.c \
|
||||||
firmware/lib/cgptlib/crc32.c \
|
firmware/lib/cgptlib/crc32.c \
|
||||||
firmware/lib/gpt_misc.c \
|
firmware/lib/gpt_misc.c \
|
||||||
firmware/lib/utility_string.c \
|
|
||||||
firmware/stub/tpm_lite_stub.c \
|
firmware/stub/tpm_lite_stub.c \
|
||||||
firmware/stub/vboot_api_stub.c \
|
firmware/stub/vboot_api_stub.c \
|
||||||
firmware/stub/vboot_api_stub_disk.c \
|
firmware/stub/vboot_api_stub_disk.c \
|
||||||
|
@ -675,7 +673,6 @@ TEST_NAMES = \
|
||||||
tests/cgptlib_test \
|
tests/cgptlib_test \
|
||||||
tests/sha_benchmark \
|
tests/sha_benchmark \
|
||||||
tests/subprocess_tests \
|
tests/subprocess_tests \
|
||||||
tests/utility_string_tests \
|
|
||||||
tests/vboot_api_kernel4_tests \
|
tests/vboot_api_kernel4_tests \
|
||||||
tests/vboot_api_kernel_tests \
|
tests/vboot_api_kernel_tests \
|
||||||
tests/vboot_display_tests \
|
tests/vboot_display_tests \
|
||||||
|
@ -1203,7 +1200,6 @@ ifeq (${MOCK_TPM}${TPM2_MODE},)
|
||||||
# tlcl_tests only works when MOCK_TPM is disabled
|
# tlcl_tests only works when MOCK_TPM is disabled
|
||||||
${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
|
${RUNTEST} ${BUILD_RUN}/tests/tlcl_tests
|
||||||
endif
|
endif
|
||||||
${RUNTEST} ${BUILD_RUN}/tests/utility_string_tests
|
|
||||||
${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
|
${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel4_tests
|
||||||
${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
|
${RUNTEST} ${BUILD_RUN}/tests/vboot_api_kernel_tests
|
||||||
${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
|
${RUNTEST} ${BUILD_RUN}/tests/vboot_display_tests
|
||||||
|
|
|
@ -3,72 +3,46 @@
|
||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "cgpt.h"
|
#include "cgpt.h"
|
||||||
#include "cgptlib_internal.h"
|
#include "cgptlib_internal.h"
|
||||||
#include "cgpt_params.h"
|
#include "cgpt_params.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_host.h"
|
#include "vboot_host.h"
|
||||||
|
|
||||||
static const char* DumpCgptAddParams(const CgptAddParams *params) {
|
static void PrintCgptAddParams(const CgptAddParams *params) {
|
||||||
static char buf[256];
|
|
||||||
char tmp[64];
|
char tmp[64];
|
||||||
|
|
||||||
buf[0] = 0;
|
fprintf(stderr, "-i %d ", params->partition);
|
||||||
snprintf(tmp, sizeof(tmp), "-i %d ", params->partition);
|
if (params->label)
|
||||||
StrnAppend(buf, tmp, sizeof(buf));
|
fprintf(stderr, "-l %s ", params->label);
|
||||||
if (params->label) {
|
if (params->set_begin)
|
||||||
snprintf(tmp, sizeof(tmp), "-l %s ", params->label);
|
fprintf(stderr, "-b %llu ", (unsigned long long)params->begin);
|
||||||
StrnAppend(buf, tmp, sizeof(buf));
|
if (params->set_size)
|
||||||
}
|
fprintf(stderr, "-s %llu ", (unsigned long long)params->size);
|
||||||
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));
|
|
||||||
}
|
|
||||||
if (params->set_type) {
|
if (params->set_type) {
|
||||||
GuidToStr(¶ms->type_guid, tmp, sizeof(tmp));
|
GuidToStr(¶ms->type_guid, tmp, sizeof(tmp));
|
||||||
StrnAppend(buf, "-t ", sizeof(buf));
|
fprintf(stderr, "-t %s ", tmp);
|
||||||
StrnAppend(buf, tmp, sizeof(buf));
|
|
||||||
StrnAppend(buf, " ", sizeof(buf));
|
|
||||||
}
|
}
|
||||||
if (params->set_unique) {
|
if (params->set_unique) {
|
||||||
GuidToStr(¶ms->unique_guid, tmp, sizeof(tmp));
|
GuidToStr(¶ms->unique_guid, tmp, sizeof(tmp));
|
||||||
StrnAppend(buf, "-u ", sizeof(buf));
|
fprintf(stderr, "-u %s ", tmp);
|
||||||
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));
|
|
||||||
}
|
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
|
||||||
StrnAppend(buf, "\n", sizeof(buf));
|
fprintf(stderr, "\n");
|
||||||
return buf;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the implementation-specific helper function.
|
// 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.
|
// If the modified entry is illegal, recover it and return error.
|
||||||
memcpy(entry, &backup, sizeof(*entry));
|
memcpy(entry, &backup, sizeof(*entry));
|
||||||
Error("%s\n", GptErrorText(rv));
|
Error("%s\n", GptErrorText(rv));
|
||||||
Error(DumpCgptAddParams(params));
|
Error("");
|
||||||
|
PrintCgptAddParams(params);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <inttypes.h> /* For PRIu64 */
|
#include <inttypes.h> /* For PRIu64 */
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ vb2_error_t VbSelectAndLoadKernel(struct vb2_context *ctx,
|
||||||
VbSelectAndLoadKernelParams *kparams);
|
VbSelectAndLoadKernelParams *kparams);
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Timer and delay (first two from utility.h) */
|
/* Timer and delay */
|
||||||
|
|
||||||
#define VB_USEC_PER_MSEC 1000ULL
|
#define VB_USEC_PER_MSEC 1000ULL
|
||||||
#define VB_MSEC_PER_SEC VB_USEC_PER_MSEC
|
#define VB_MSEC_PER_SEC VB_USEC_PER_MSEC
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include "cgptlib_internal.h"
|
#include "cgptlib_internal.h"
|
||||||
#include "crc32.h"
|
#include "crc32.h"
|
||||||
#include "gpt.h"
|
#include "gpt.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
|
|
||||||
int GptInit(GptData *gpt)
|
int GptInit(GptData *gpt)
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include "crc32.h"
|
#include "crc32.h"
|
||||||
#include "gpt.h"
|
#include "gpt.h"
|
||||||
#include "gpt_misc.h"
|
#include "gpt_misc.h"
|
||||||
#include "utility.h"
|
|
||||||
|
|
||||||
const static int MIN_SECTOR_SIZE = 512;
|
const static int MIN_SECTOR_SIZE = 512;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include "cgptlib_internal.h"
|
#include "cgptlib_internal.h"
|
||||||
#include "crc32.h"
|
#include "crc32.h"
|
||||||
#include "gpt.h"
|
#include "gpt.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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_ */
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include "2common.h"
|
#include "2common.h"
|
||||||
#include "2sysincludes.h"
|
#include "2sysincludes.h"
|
||||||
#include "tpm2_marshaling.h"
|
#include "tpm2_marshaling.h"
|
||||||
#include "utility.h"
|
|
||||||
|
|
||||||
static uint16_t tpm_tag; /* Depends on the command type. */
|
static uint16_t tpm_tag; /* Depends on the command type. */
|
||||||
static int ph_disabled; /* Platform hierarchy disabled. */
|
static int ph_disabled; /* Platform hierarchy disabled. */
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "2sysincludes.h"
|
#include "2sysincludes.h"
|
||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
#include "tpm2_marshaling.h"
|
#include "tpm2_marshaling.h"
|
||||||
#include "utility.h"
|
#include "vboot_api.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO(chromium:1032930): Originally accessed by including secdata_tpm.h.
|
* TODO(chromium:1032930): Originally accessed by including secdata_tpm.h.
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
#include "2sysincludes.h"
|
#include "2sysincludes.h"
|
||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
#include "tlcl_internal.h"
|
#include "tlcl_internal.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
|
|
||||||
uint32_t TlclLibInit(void)
|
uint32_t TlclLibInit(void)
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
#include "tlcl_internal.h"
|
#include "tlcl_internal.h"
|
||||||
#include "tlcl_structures.h"
|
#include "tlcl_structures.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
|
|
||||||
/* Sets the size field of a TPM command. */
|
/* Sets the size field of a TPM command. */
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include "2sysincludes.h"
|
#include "2sysincludes.h"
|
||||||
#include "2ui.h"
|
#include "2ui.h"
|
||||||
#include "load_kernel_fw.h"
|
#include "load_kernel_fw.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vb2_common.h"
|
#include "vb2_common.h"
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
#include "vboot_kernel.h"
|
#include "vboot_kernel.h"
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#include "2common.h"
|
#include "2common.h"
|
||||||
#include "2misc.h"
|
#include "2misc.h"
|
||||||
#include "2sysincludes.h"
|
#include "2sysincludes.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
#include "vboot_audio.h"
|
#include "vboot_audio.h"
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
#include "2nvstorage.h"
|
#include "2nvstorage.h"
|
||||||
#include "2sha.h"
|
#include "2sha.h"
|
||||||
#include "2sysincludes.h"
|
#include "2sysincludes.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
#include "vboot_display.h"
|
#include "vboot_display.h"
|
||||||
#include "vboot_kernel.h"
|
#include "vboot_kernel.h"
|
||||||
|
@ -216,7 +215,12 @@ const char *RecoveryReasonString(uint8_t code)
|
||||||
return "Unknown or deprecated error 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)
|
vb2_error_t VbDisplayDebugInfo(struct vb2_context *ctx)
|
||||||
{
|
{
|
||||||
|
@ -225,7 +229,7 @@ vb2_error_t VbDisplayDebugInfo(struct vb2_context *ctx)
|
||||||
struct vb2_workbuf wb;
|
struct vb2_workbuf wb;
|
||||||
char buf[DEBUG_INFO_SIZE] = "";
|
char buf[DEBUG_INFO_SIZE] = "";
|
||||||
char sha1sum[VB2_SHA1_DIGEST_SIZE * 2 + 1];
|
char sha1sum[VB2_SHA1_DIGEST_SIZE * 2 + 1];
|
||||||
uint32_t used = 0;
|
int32_t used = 0;
|
||||||
vb2_error_t ret;
|
vb2_error_t ret;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
|
@ -238,83 +242,53 @@ vb2_error_t VbDisplayDebugInfo(struct vb2_context *ctx)
|
||||||
ret = vb2api_gbb_read_hwid(ctx, hwid, &size);
|
ret = vb2api_gbb_read_hwid(ctx, hwid, &size);
|
||||||
if (ret)
|
if (ret)
|
||||||
strcpy(hwid, "{INVALID}");
|
strcpy(hwid, "{INVALID}");
|
||||||
used += StrnAppend(buf + used, "HWID: ",
|
DEBUG_INFO_APPEND("HWID: %s", hwid);
|
||||||
DEBUG_INFO_SIZE - used);
|
|
||||||
used += StrnAppend(buf + used, hwid, DEBUG_INFO_SIZE - used);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add recovery reason and subcode */
|
/* Add recovery reason and subcode */
|
||||||
i = vb2_nv_get(ctx, VB2_NV_RECOVERY_SUBCODE);
|
i = vb2_nv_get(ctx, VB2_NV_RECOVERY_SUBCODE);
|
||||||
used += StrnAppend(buf + used,
|
DEBUG_INFO_APPEND("\nrecovery_reason: %#.2x / %#.2x %s",
|
||||||
"\nrecovery_reason: 0x", DEBUG_INFO_SIZE - used);
|
sd->recovery_reason, i,
|
||||||
used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
|
RecoveryReasonString(sd->recovery_reason));
|
||||||
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);
|
|
||||||
|
|
||||||
/* Add vb2_context and vb2_shared_data flags */
|
/* Add vb2_context and vb2_shared_data flags */
|
||||||
used += StrnAppend(buf + used, "\ncontext.flags: 0x",
|
DEBUG_INFO_APPEND("\ncontext.flags: %#.16" PRIx64, ctx->flags);
|
||||||
DEBUG_INFO_SIZE - used);
|
DEBUG_INFO_APPEND("\nshared_data.flags: %#.8x", sd->flags);
|
||||||
used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
|
DEBUG_INFO_APPEND("\nshared_data.status: %#.8x", sd->status);
|
||||||
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 */
|
/* Add raw contents of nvdata */
|
||||||
used += StrnAppend(buf + used, "\nVbNv.raw:", DEBUG_INFO_SIZE - used);
|
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++) {
|
for (i = 0; i < vb2_nv_get_size(ctx); i++) {
|
||||||
used += StrnAppend(buf + used, " ", DEBUG_INFO_SIZE - used);
|
/* Split into 16-byte blocks */
|
||||||
used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
|
if (i > 0 && i % 16 == 0)
|
||||||
ctx->nvdata[i], 16, 2);
|
DEBUG_INFO_APPEND("\n ");
|
||||||
|
DEBUG_INFO_APPEND(" %02x", ctx->nvdata[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add dev_boot_usb flag */
|
/* Add dev_boot_usb flag */
|
||||||
i = vb2_nv_get(ctx, VB2_NV_DEV_BOOT_USB);
|
i = vb2_nv_get(ctx, VB2_NV_DEV_BOOT_USB);
|
||||||
used += StrnAppend(buf + used, "\ndev_boot_usb: ", DEBUG_INFO_SIZE - used);
|
DEBUG_INFO_APPEND("\ndev_boot_usb: %d", i);
|
||||||
used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used, i, 10, 0);
|
|
||||||
|
|
||||||
/* Add dev_boot_legacy flag */
|
/* Add dev_boot_legacy flag */
|
||||||
i = vb2_nv_get(ctx, VB2_NV_DEV_BOOT_LEGACY);
|
i = vb2_nv_get(ctx, VB2_NV_DEV_BOOT_LEGACY);
|
||||||
used += StrnAppend(buf + used,
|
DEBUG_INFO_APPEND("\ndev_boot_legacy: %d", i);
|
||||||
"\ndev_boot_legacy: ", DEBUG_INFO_SIZE - used);
|
|
||||||
used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used, i, 10, 0);
|
|
||||||
|
|
||||||
/* Add dev_default_boot flag */
|
/* Add dev_default_boot flag */
|
||||||
i = vb2_nv_get(ctx, VB2_NV_DEV_DEFAULT_BOOT);
|
i = vb2_nv_get(ctx, VB2_NV_DEV_DEFAULT_BOOT);
|
||||||
used += StrnAppend(buf + used,
|
DEBUG_INFO_APPEND("\ndev_default_boot: %d", i);
|
||||||
"\ndev_default_boot: ", DEBUG_INFO_SIZE - used);
|
|
||||||
used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used, i, 10, 0);
|
|
||||||
|
|
||||||
/* Add dev_boot_signed_only flag */
|
/* Add dev_boot_signed_only flag */
|
||||||
i = vb2_nv_get(ctx, VB2_NV_DEV_BOOT_SIGNED_ONLY);
|
i = vb2_nv_get(ctx, VB2_NV_DEV_BOOT_SIGNED_ONLY);
|
||||||
used += StrnAppend(buf + used, "\ndev_boot_signed_only: ",
|
DEBUG_INFO_APPEND("\ndev_boot_signed_only: %d", i);
|
||||||
DEBUG_INFO_SIZE - used);
|
|
||||||
used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used, i, 10, 0);
|
|
||||||
|
|
||||||
/* Add TPM versions */
|
/* Add TPM versions */
|
||||||
used += StrnAppend(buf + used,
|
DEBUG_INFO_APPEND("\nTPM: fwver=%#.8x kernver=%#.8x",
|
||||||
"\nTPM: fwver=0x", DEBUG_INFO_SIZE - used);
|
sd->fw_version_secdata, sd->kernel_version_secdata);
|
||||||
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);
|
|
||||||
|
|
||||||
/* Add GBB flags */
|
/* Add GBB flags */
|
||||||
used += StrnAppend(buf + used,
|
DEBUG_INFO_APPEND("\ngbb.flags: %#.8x", gbb->flags);
|
||||||
"\ngbb.flags: 0x", DEBUG_INFO_SIZE - used);
|
|
||||||
used += Uint64ToString(buf + used, DEBUG_INFO_SIZE - used,
|
|
||||||
gbb->flags, 16, 8);
|
|
||||||
|
|
||||||
/* Add sha1sum for Root & Recovery keys */
|
/* 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);
|
ret = vb2_gbb_read_root_key(ctx, &key, NULL, &wblocal);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
FillInSha1Sum(sha1sum, key);
|
FillInSha1Sum(sha1sum, key);
|
||||||
used += StrnAppend(buf + used, "\ngbb.rootkey: ",
|
DEBUG_INFO_APPEND("\ngbb.rootkey: %s", sha1sum);
|
||||||
DEBUG_INFO_SIZE - used);
|
|
||||||
used += StrnAppend(buf + used, sha1sum,
|
|
||||||
DEBUG_INFO_SIZE - used);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,10 +307,7 @@ vb2_error_t VbDisplayDebugInfo(struct vb2_context *ctx)
|
||||||
ret = vb2_gbb_read_recovery_key(ctx, &key, NULL, &wblocal);
|
ret = vb2_gbb_read_recovery_key(ctx, &key, NULL, &wblocal);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
FillInSha1Sum(sha1sum, key);
|
FillInSha1Sum(sha1sum, key);
|
||||||
used += StrnAppend(buf + used, "\ngbb.recovery_key: ",
|
DEBUG_INFO_APPEND("\ngbb.recovery_key: %s", sha1sum);
|
||||||
DEBUG_INFO_SIZE - used);
|
|
||||||
used += StrnAppend(buf + used, sha1sum,
|
|
||||||
DEBUG_INFO_SIZE - used);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,13 +317,11 @@ vb2_error_t VbDisplayDebugInfo(struct vb2_context *ctx)
|
||||||
struct vb2_packed_key *key =
|
struct vb2_packed_key *key =
|
||||||
vb2_member_of(sd, sd->kernel_key_offset);
|
vb2_member_of(sd, sd->kernel_key_offset);
|
||||||
FillInSha1Sum(sha1sum, key);
|
FillInSha1Sum(sha1sum, key);
|
||||||
used += StrnAppend(buf + used,
|
DEBUG_INFO_APPEND("\nkernel_subkey: %s", sha1sum);
|
||||||
"\nkernel_subkey: ", DEBUG_INFO_SIZE - used);
|
|
||||||
used += StrnAppend(buf + used, sha1sum, DEBUG_INFO_SIZE - used);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure we finish with a newline */
|
/* 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:
|
/* TODO: add more interesting data:
|
||||||
* - Information on current disks */
|
* - Information on current disks */
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include "cgptlib_internal.h"
|
#include "cgptlib_internal.h"
|
||||||
#include "gpt_misc.h"
|
#include "gpt_misc.h"
|
||||||
#include "load_kernel_fw.h"
|
#include "load_kernel_fw.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vb2_common.h"
|
#include "vb2_common.h"
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
#include "vboot_kernel.h"
|
#include "vboot_kernel.h"
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include "2sysincludes.h"
|
#include "2sysincludes.h"
|
||||||
#include "load_kernel_fw.h"
|
#include "load_kernel_fw.h"
|
||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vb2_common.h"
|
#include "vb2_common.h"
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
#include "vboot_audio.h"
|
#include "vboot_audio.h"
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "2secdata.h"
|
#include "2secdata.h"
|
||||||
#include "2sysincludes.h"
|
#include "2sysincludes.h"
|
||||||
#include "load_kernel_fw.h"
|
#include "load_kernel_fw.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vb2_common.h"
|
#include "vb2_common.h"
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
#include "vboot_audio.h"
|
#include "vboot_audio.h"
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include "2sysincludes.h"
|
#include "2sysincludes.h"
|
||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
#include "tlcl_internal.h"
|
#include "tlcl_internal.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
|
|
||||||
#define TPM_DEVICE_PATH "/dev/tpm0"
|
#define TPM_DEVICE_PATH "/dev/tpm0"
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
#include "futility.h"
|
#include "futility.h"
|
||||||
#include "updater.h"
|
#include "updater.h"
|
||||||
#include "utility.h"
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
OPT_DUMMY = 0x100,
|
OPT_DUMMY = 0x100,
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include "crossystem.h"
|
#include "crossystem.h"
|
||||||
#include "crossystem_vbnv.h"
|
#include "crossystem_vbnv.h"
|
||||||
#include "host_common.h"
|
#include "host_common.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_struct.h"
|
#include "vboot_struct.h"
|
||||||
|
|
||||||
/* ACPI constants from Chrome OS Main Processor Firmware Spec */
|
/* ACPI constants from Chrome OS Main Processor Firmware Spec */
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
#include "crossystem_vbnv.h"
|
#include "crossystem_vbnv.h"
|
||||||
#include "host_common.h"
|
#include "host_common.h"
|
||||||
#include "subprocess.h"
|
#include "subprocess.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_struct.h"
|
#include "vboot_struct.h"
|
||||||
|
|
||||||
/* Filename for kernel command line */
|
/* Filename for kernel command line */
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "2sysincludes.h"
|
#include "2sysincludes.h"
|
||||||
#include "host_common.h"
|
#include "host_common.h"
|
||||||
#include "host_key21.h"
|
#include "host_key21.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vb2_common.h"
|
#include "vb2_common.h"
|
||||||
|
|
||||||
struct vb2_fw_preamble *vb2_create_fw_preamble(
|
struct vb2_fw_preamble *vb2_create_fw_preamble(
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include "host_keyblock.h"
|
#include "host_keyblock.h"
|
||||||
#include "host_misc.h"
|
#include "host_misc.h"
|
||||||
#include "host_signature.h"
|
#include "host_signature.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
#include "vboot_struct.h"
|
#include "vboot_struct.h"
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
#ifndef VBOOT_REFERENCE_HOST_MISC_H_
|
#ifndef VBOOT_REFERENCE_HOST_MISC_H_
|
||||||
#define VBOOT_REFERENCE_HOST_MISC_H_
|
#define VBOOT_REFERENCE_HOST_MISC_H_
|
||||||
|
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_struct.h"
|
#include "vboot_struct.h"
|
||||||
|
|
||||||
/* Copy up to dest_size-1 characters from src to dest, ensuring null
|
/* Copy up to dest_size-1 characters from src to dest, ensuring null
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#define VBOOT_REFERENCE_HOST_SIGNATURE_H_
|
#define VBOOT_REFERENCE_HOST_SIGNATURE_H_
|
||||||
|
|
||||||
#include "host_key.h"
|
#include "host_key.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_struct.h"
|
#include "vboot_struct.h"
|
||||||
|
|
||||||
struct vb2_private_key;
|
struct vb2_private_key;
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include "crc32_test.h"
|
#include "crc32_test.h"
|
||||||
#include "gpt.h"
|
#include "gpt.h"
|
||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
#include "utility.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Testing partition layout (sector_bytes=512)
|
* Testing partition layout (sector_bytes=512)
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
#include "crc32.h"
|
#include "crc32.h"
|
||||||
#include "crc32_test.h"
|
#include "crc32_test.h"
|
||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
#include "utility.h"
|
|
||||||
|
|
||||||
#define MAX_VECTOR_LEN 256
|
#define MAX_VECTOR_LEN 256
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
#include "utility.h"
|
|
||||||
|
|
||||||
/* These index values are used to create NVRAM spaces. They only need to be
|
/* These index values are used to create NVRAM spaces. They only need to be
|
||||||
* unique.
|
* unique.
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
#include "tlcl_tests.h"
|
#include "tlcl_tests.h"
|
||||||
#include "utility.h"
|
|
||||||
|
|
||||||
#define INDEX0 0xcafe
|
#define INDEX0 0xcafe
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
#include "tlcl_tests.h"
|
#include "tlcl_tests.h"
|
||||||
#include "utility.h"
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
uint32_t x;
|
uint32_t x;
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
#include "tlcl_tests.h"
|
#include "tlcl_tests.h"
|
||||||
#include "utility.h"
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
uint32_t perm;
|
uint32_t perm;
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
#include "tlcl.h"
|
#include "tlcl.h"
|
||||||
#include "tlcl_tests.h"
|
#include "tlcl_tests.h"
|
||||||
#include "utility.h"
|
|
||||||
|
|
||||||
/* Runs [op] and ensures it returns success and doesn't run longer than
|
/* Runs [op] and ensures it returns success and doesn't run longer than
|
||||||
* [time_limit] in milliseconds.
|
* [time_limit] in milliseconds.
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "host_key.h"
|
#include "host_key.h"
|
||||||
#include "rsa_padding_test.h"
|
#include "rsa_padding_test.h"
|
||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vb2_common.h"
|
#include "vb2_common.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "file_keys.h"
|
#include "file_keys.h"
|
||||||
#include "rsa_padding_test.h"
|
#include "rsa_padding_test.h"
|
||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
#include "vboot_test.h"
|
#include "vboot_test.h"
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include "2sysincludes.h"
|
#include "2sysincludes.h"
|
||||||
#include "load_kernel_fw.h"
|
#include "load_kernel_fw.h"
|
||||||
#include "test_common.h"
|
#include "test_common.h"
|
||||||
#include "utility.h"
|
|
||||||
#include "vboot_api.h"
|
#include "vboot_api.h"
|
||||||
#include "vboot_kernel.h"
|
#include "vboot_kernel.h"
|
||||||
#include "vboot_test.h"
|
#include "vboot_test.h"
|
||||||
|
|
|
@ -5,12 +5,9 @@
|
||||||
* Routines for verifying a kernel or disk image
|
* Routines for verifying a kernel or disk image
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "2sysincludes.h"
|
#include "2sysincludes.h"
|
||||||
#include "2api.h"
|
#include "2api.h"
|
||||||
|
#include "2common.h"
|
||||||
#include "2misc.h"
|
#include "2misc.h"
|
||||||
#include "2nvstorage.h"
|
#include "2nvstorage.h"
|
||||||
#include "host_common.h"
|
#include "host_common.h"
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "2api.h"
|
#include "2api.h"
|
||||||
|
#include "2common.h"
|
||||||
#include "2misc.h"
|
#include "2misc.h"
|
||||||
#include "2sysincludes.h"
|
#include "2sysincludes.h"
|
||||||
#include "host_common.h"
|
#include "host_common.h"
|
||||||
|
|
Loading…
Reference in New Issue