diff options
author | Che-Liang Chiou <clchiou@chromium.org> | 2011-07-25 15:03:57 +0800 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2011-08-29 10:59:07 -0700 |
commit | a0f700ab4b06f7c8d87d336324f5813c9a31c684 (patch) | |
tree | 8fe7bf39c8807290e7a60dd2d2a976063ca1b8e6 /board/nvidia | |
parent | e15ae271675d02be118708ebb4498ffc7924e3f2 (diff) |
CHROMIUM: move VbExNvStorageRead/Write to board-specific directory
As ARM accesses non-volatile storage from eMMC and x86 from CMOS, the
accessor functions that export to vboot_reference are really not
board-independent and so should be put at a board-dependent module.
BUG=none
TEST=make
Change-Id: Idbd4d70372770597aa8897524ee6a1ffe173bfea
Reviewed-on: http://gerrit.chromium.org/gerrit/4646
Tested-by: Che-Liang Chiou <clchiou@chromium.org>
Reviewed-by: Tom Wai-Hong Tam <waihong@chromium.org>
Diffstat (limited to 'board/nvidia')
-rw-r--r-- | board/nvidia/chromeos/Makefile | 2 | ||||
-rw-r--r-- | board/nvidia/vbexport/Makefile | 30 | ||||
-rw-r--r-- | board/nvidia/vbexport/nvstorage.c | 113 |
3 files changed, 144 insertions, 1 deletions
diff --git a/board/nvidia/chromeos/Makefile b/board/nvidia/chromeos/Makefile index efa3fd4540c..5bbae8c752f 100644 --- a/board/nvidia/chromeos/Makefile +++ b/board/nvidia/chromeos/Makefile @@ -10,7 +10,7 @@ include $(TOPDIR)/config.mk -LIB = $(obj)libchromeos_hardware_interface.a +LIB = $(obj)libchromeos_board.a COBJS-$(CONFIG_CHROMEOS) += cros_gpio.o COBJS-$(CONFIG_CHROMEOS) += power_management.o diff --git a/board/nvidia/vbexport/Makefile b/board/nvidia/vbexport/Makefile new file mode 100644 index 00000000000..327f0b2e41b --- /dev/null +++ b/board/nvidia/vbexport/Makefile @@ -0,0 +1,30 @@ +# +# 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. +# +# Alternatively, this software may be distributed under the terms of the +# GNU General Public License ("GPL") version 2 as published by the Free +# Software Foundation. +# + +include $(TOPDIR)/config.mk + +LIB = $(obj)libvbexport_board.a + +COBJS-$(CONFIG_CHROMEOS_VBEXPORT) += nvstorage.o + +COBJS := $(COBJS-y) +OBJS := $(addprefix $(obj),$(COBJS)) + +$(LIB): $(obj).depend $(OBJS) + $(AR) $(ARFLAGS) $@ $(OBJS) + +######################################################################### + +# defines $(obj).depend target +include $(SRCTREE)/rules.mk + +sinclude $(obj).depend + +######################################################################### diff --git a/board/nvidia/vbexport/nvstorage.c b/board/nvidia/vbexport/nvstorage.c new file mode 100644 index 00000000000..e9f49c4f855 --- /dev/null +++ b/board/nvidia/vbexport/nvstorage.c @@ -0,0 +1,113 @@ +/* + * 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. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + */ + +#include <common.h> +#include <chromeos/common.h> + +/* Import the header files from vboot_reference. */ +#include <vboot_api.h> + +#define PREFIX "nvstorage: " + +/* + * We had a discussion about the non-volatile storage device for keeping + * the cookies. Due to the lack of SPI flash driver in kernel, kernel cannot + * access cookies in SPI flash. So the final descision is to store the + * cookies in eMMC device where we are certain that kernel can access. + */ + +/* + * Gets the first internal disk and caches the result in a static variable. + * Returns 0 for success, non-zero for failure. + */ +static int get_internal_disk(VbDiskInfo **disk_ptr) +{ + static VbDiskInfo internal_disk; + + if (internal_disk.handle == NULL) { + VbDiskInfo* disk_info; + uint32_t disk_count; + + if (VbExDiskGetInfo(&disk_info, &disk_count, + VB_DISK_FLAG_FIXED) || disk_count == 0) { + VBDEBUG(PREFIX "No internal disk found!\n"); + return 1; + } + internal_disk = disk_info[0]; + VbExDiskFreeInfo(disk_info, internal_disk.handle); + } + + *disk_ptr = &internal_disk; + return 0; +} + +/* + * Allocates 1-block-sized memory to block_buf_ptr and fills it as the first + * block of the disk. + * Returns 0 for success, non-zero for failure. + */ +static int get_nvcxt_block_of_disk(const VbDiskInfo *disk, + uint8_t **block_buf_ptr) +{ + uint8_t *block_buf = NULL; + + block_buf = VbExMalloc(disk->bytes_per_lba); + + if (VbExDiskRead(disk->handle, + CHROMEOS_VBNVCONTEXT_LBA, 1, block_buf)) { + VBDEBUG(PREFIX "Failed to read internal disk!\n"); + VbExFree(block_buf); + return 1; + } + + *block_buf_ptr = block_buf; + return 0; +} + +VbError_t VbExNvStorageRead(uint8_t* buf) +{ + VbDiskInfo *internal_disk; + uint8_t *block_buf; + + if (get_internal_disk(&internal_disk)) + return 1; + + if (get_nvcxt_block_of_disk(internal_disk, &block_buf)) + return 1; + + memcpy(buf, block_buf, VBNV_BLOCK_SIZE); + + VbExFree(block_buf); + return VBERROR_SUCCESS; +} + +VbError_t VbExNvStorageWrite(const uint8_t* buf) +{ + VbDiskInfo *internal_disk; + uint8_t *block_buf; + + if (get_internal_disk(&internal_disk)) + return 1; + + if (get_nvcxt_block_of_disk(internal_disk, &block_buf)) + return 1; + + memcpy(block_buf, buf, VBNV_BLOCK_SIZE); + + if (VbExDiskWrite(internal_disk->handle, + CHROMEOS_VBNVCONTEXT_LBA, 1, block_buf)) { + VBDEBUG(PREFIX "Failed to write internal disk!\n"); + VbExFree(block_buf); + return 1; + } + + VbExFree(block_buf); + return VBERROR_SUCCESS; +} |