summaryrefslogtreecommitdiff
path: root/host/arch/arm/lib
diff options
context:
space:
mode:
authorDuncan Laurie <dlaurie@chromium.org>2014-10-13 08:11:09 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-10-18 01:39:26 +0000
commitd241fff54c982f2764e6d126a024ab71fa6dd84a (patch)
tree6e73128010fcf45d70c1ae38927833ed09d0ceb4 /host/arch/arm/lib
parent6d03b527fe0107c3bb71d0bbaf6236fe980b0704 (diff)
downloadvboot-d241fff54c982f2764e6d126a024ab71fa6dd84a.tar.gz
crossystem: Change ReadFileInt to take an unsigned int pointer
Currently ReadFileInt assumes that an integer value read from a file is never going to be "-1" and uses that value to indicate failure. In particular for GPIO values that may be returned by the kernel it is possible for them to be not simply 0 or 1 but instead a bit within the GPIO status register that indicates the value. The function semantics are changed to have the caller pass in the variable to store the integer in, and use the return code explicitly as a pass or fail condition. This requires all the callers of ReadFileInt to be changed to use the new scheme, and the x86 ReadGpio function is changed to normalize the GPIO value that is read from the kernel instead of assuming it is always 1 for active high values. BUG=chrome-os-partner:32645 BRANCH=samus,auron TEST=build for samus, check crossystem output and ensure that all values are properly reported and that wpsw_cur is correct now. Also tested to ensure no changes in output on: x86-alex, daisy, peach_pit, lumpy, stumpy, nyan_big, nyan_blaze, rush_ryu, panther, wolf, zako, auron, rambi, squawks, parrot_ivb, veyron_pinky Change-Id: I824152eed5f96cf1faaa18ba31a01f4d346ad172 Signed-off-by: Duncan Laurie <dlaurie@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/223009 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'host/arch/arm/lib')
-rw-r--r--host/arch/arm/lib/crossystem_arch.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/host/arch/arm/lib/crossystem_arch.c b/host/arch/arm/lib/crossystem_arch.c
index 92b61b4c..3864451c 100644
--- a/host/arch/arm/lib/crossystem_arch.c
+++ b/host/arch/arm/lib/crossystem_arch.c
@@ -68,12 +68,15 @@ const PlatformFamily platform_family_array[] = {
static int FindEmmcDev(void) {
int mmcblk;
+ unsigned value;
char filename[FNAME_SIZE];
for (mmcblk = 0; mmcblk < MAX_NMMCBLK; mmcblk++) {
/* Get first non-removable mmc block device */
snprintf(filename, sizeof(filename), "/sys/block/mmcblk%d/removable",
mmcblk);
- if (ReadFileInt(filename) == 0)
+ if (ReadFileInt(filename, &value) < 0)
+ continue;
+ if (value == 0)
return mmcblk;
}
/* eMMC not found */
@@ -211,24 +214,23 @@ static char * ReadFdtPlatformFamily(void) {
static int VbGetPlatformGpioStatus(const char* name) {
char gpio_name[FNAME_SIZE];
- int value;
+ unsigned value;
snprintf(gpio_name, sizeof(gpio_name), "%s/%s/value",
PLATFORM_DEV_PATH, name);
- value = ReadFileInt(gpio_name);
+ if (ReadFileInt(gpio_name, &value) < 0)
+ return -1;
- return value;
+ return (int)value;
}
static int VbGetGpioStatus(unsigned gpio_number) {
char gpio_name[FNAME_SIZE];
- int value;
+ unsigned value;
snprintf(gpio_name, sizeof(gpio_name), "%s/gpio%d/value",
GPIO_BASE_PATH, gpio_number);
- value = ReadFileInt(gpio_name);
-
- if (value == -1) {
+ if (ReadFileInt(gpio_name, &value) < 0) {
/* Try exporting the GPIO */
FILE* f = fopen(GPIO_EXPORT_PATH, "wt");
if (!f)
@@ -237,10 +239,11 @@ static int VbGetGpioStatus(unsigned gpio_number) {
fclose(f);
/* Try re-reading the GPIO value */
- value = ReadFileInt(gpio_name);
+ if (ReadFileInt(gpio_name, &value) < 0)
+ return -1;
}
- return value;
+ return (int)value;
}
static int VbGetVarGpio(const char* name) {