#define BLKNV_MAJOR MMC_BLOCK_MAJOR
#define BLKNV_MINOR 0
-/* location where the nvram data blends into the sector on the MMC device */
+/*
+ * location where the vboot context data blends into the sector on the
+ * MMC device
+ */
static u16 nv_offset, nv_size;
static u64 nv_lba;
/*
- * Functions to support nvram on block device. The actual device used is minor
- * 0 of MMC device class, the sector to use is as encoded in
- * firmware_shared_data->nvcxt_lba, the nvram buffer in the sector starts at
- * offset nv_offset and takes nv_size bytes.
+ * Functions to support vboot context on block device. The actual device used
+ * is minor 0 of MMC device class, the sector to use is as encoded in
+ * firmware_shared_data->nvcxt_lba, the vboot context buffer in the sector
+ * starts at offset nv_offset and takes nv_size bytes.
*/
-static void blknv_endio(struct bio *bio, int err)
+static void vbc_blk_endio(struct bio *bio, int err)
{
struct completion *c = bio->bi_private;
bio->bi_private = (void *)err;
complete(c);
}
-static void blknv_submit_bio(struct bio *bio, int rq)
+static void vbc_blk_submit_bio(struct bio *bio, int rq)
{
DECLARE_COMPLETION_ONSTACK(wait);
- bio->bi_end_io = blknv_endio;
+ bio->bi_end_io = vbc_blk_endio;
bio->bi_private = &wait;
submit_bio(rq, bio);
wait_for_completion(&wait);
}
-static int chromeos_access_nvram_block(struct page *page,
- sector_t sector,
- bool is_read)
+static int vbc_blk_access(struct page *page, sector_t sector, bool is_read)
{
struct block_device *bdev;
struct bio *bio = NULL;
if (!is_read)
rq |= REQ_WRITE;
- blknv_submit_bio(bio, rq);
+ vbc_blk_submit_bio(bio, rq);
/* nvblk_endio passes up any error in bi_private */
ret = (int)bio->bi_private;
return ret;
}
-static int chromeos_read_nvram_block(struct page *page, sector_t sector)
-{
- return chromeos_access_nvram_block(page, sector, 1);
-}
-
-static int chromeos_write_nvram_block(struct page *page, sector_t sector)
-{
- return chromeos_access_nvram_block(page, sector, 0);
-}
-
/*
* This function accepts a buffer with exactly nv_size bytes. It reads the
* appropriate mmc one sector block, extacts the nonvolatile data from there
* and copies it to the provided buffer.
*/
-static int _chromeos_read(u8 *data)
+static int vbc_blk_read(u8 *data)
{
struct page *page;
char *virtual_addr;
return -EFAULT;
}
- ret = chromeos_read_nvram_block(page, nv_lba);
+ ret = vbc_blk_access(page, nv_lba, 1);
if (ret)
goto out;
/*
* This function accepts a buffer with exactly nv_size bytes. It reads the
- * appropriate mmc one sector block, blends in the new nvram contents and then
- * writes the sector back.
+ * appropriate mmc one sector block, blends in the new vboot context contents
+ * and then writes the sector back.
*/
-static int _chromeos_write(const u8 *data)
+static int vbc_blk_write(const u8 *data)
{
struct page *page;
char *virtual_addr;
return -EFAULT;
}
- ret = chromeos_read_nvram_block(page, nv_lba);
+ ret = vbc_blk_access(page, nv_lba, 1);
if (ret)
goto out;
/*
- * Sector has been read, lets blend in nvram data and write the sector
- * back.
+ * Sector has been read, lets blend in vboot context data and write
+ * the sector back.
*/
memcpy(virtual_addr + nv_offset, data, nv_size);
- ret = chromeos_write_nvram_block(page, nv_lba);
+ ret = vbc_blk_access(page, nv_lba, 0);
if (!ret)
ret = nv_size;
}
/*
- * Read the nvram buffer contents into the user provided space.
+ * Read the vboot context buffer contents into the user provided space.
*
* returns number of bytes copied, or negative error.
*/
-int chromeos_platform_read_nvram(u8 *nvram_buffer, int buf_size)
+ssize_t chromeos_vbc_read(void *buf, size_t count)
{
if (!nv_size) {
pr_err("%s nonvolatile context not configured!\n", __func__);
return -ENODEV;
}
- if (buf_size < nv_size) {
- pr_err("not enough room to read nvram (%d < %d)\n",
- buf_size, nv_size);
+ if (count < nv_size) {
+ pr_err("not enough room to read vboot context (%zd < %d)\n",
+ count, nv_size);
return -ENOSPC;
}
- return _chromeos_read(nvram_buffer);
+ return vbc_blk_read(buf);
}
-int chromeos_platform_write_nvram(u8 *nvram_buffer, int buf_size)
+ssize_t chromeos_vbc_write(const void *buf, size_t count)
{
if (!nv_size) {
pr_err("%s nonvolatile context not configured!\n", __func__);
return -ENODEV;
}
- if (buf_size != nv_size) {
- pr_err("wrong write buffer size (%d != %d)\n",
- buf_size, nv_size);
+ if (count != nv_size) {
+ pr_err("wrong write buffer size (%zd != %d)\n",
+ count, nv_size);
return -ENOSPC;
}
- return _chromeos_write(nvram_buffer);
+ return vbc_blk_write(buf);
}
static int __devinit chromeos_arm_platform_gpio(struct platform_device *pdev)
nv_size = be32_to_cpup(prop);
if ((nv_offset + nv_size > SECTOR_SIZE) ||
- (nv_size > MAX_NVRAM_BUFFER_SIZE)) {
- /* nvram block won't fit into a sector */
- dev_err(&pdev->dev, "bad nvram location: %d:%d!\n",
+ (nv_size > MAX_VBOOT_CONTEXT_BUFFER_SIZE)) {
+ /* vboot context block won't fit into a sector */
+ dev_err(&pdev->dev, "bad vboot context location: %d:%d!\n",
nv_offset, nv_size);
err = -EINVAL;
goto err;
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * This module isolates ChromeOS platform specific behavior. In particular,
- * it uses calls from chromeos_acpi.c to control the boot flow, and exports some
- * helper functions for kernel-side consumers of platform configuration, such
- * as nvram flags.
*/
#include <linux/types.h>
#include <linux/ramoops.h>
#include "chromeos.h"
-static int chromeos_read_nvram(u8 *nvram_buffer, int buf_size);
-static int chromeos_write_nvram_byte(unsigned offset, u8 value);
+static int vbc_read(u8 *buf, int buf_size);
+static int vbc_write_byte(unsigned offset, u8 value);
/* the following defines are copied from
* vboot_reference:firmware/lib/vboot_nvstorage.c.
if (!chromeos_legacy_set_need_recovery())
return 0;
- return chromeos_write_nvram_byte(RECOVERY_OFFSET,
- VBNV_RECOVERY_RW_INVALID_OS);
+ return vbc_write_byte(RECOVERY_OFFSET, VBNV_RECOVERY_RW_INVALID_OS);
}
/*
return (u8)(crc >> 8);
}
-static int chromeos_write_nvram_byte(unsigned offset, u8 value)
+static int vbc_write_byte(unsigned offset, u8 value)
{
- u8 nvram_buffer[MAX_NVRAM_BUFFER_SIZE];
+ u8 buf[MAX_VBOOT_CONTEXT_BUFFER_SIZE];
- int size = chromeos_read_nvram(nvram_buffer, sizeof(nvram_buffer));
+ ssize_t size = vbc_read(buf, sizeof(buf));
if (size <= 0)
return -EINVAL;
if (offset >= (size - 1))
return -EINVAL;
- if (nvram_buffer[offset] == value)
+ if (buf[offset] == value)
return 0;
- nvram_buffer[offset] = value;
- nvram_buffer[size - 1] = crc8(nvram_buffer, size - 1);
+ buf[offset] = value;
+ buf[size - 1] = crc8(buf, size - 1);
- return chromeos_platform_write_nvram(nvram_buffer, size);
+ return chromeos_vbc_write(buf, size);
}
/*
- * Read nvram buffer contents and verify it. Return 0 on success and -1 on
- * failure (uninitialized subsystem, corrupted crc8 value, not enough room in
- * the buffer, etc.).
- *
- * If everything checks out - return number of bytes in the NVRAM buffer, -1
- * on any error.
+ * Read vboot context and verify it. If everything checks out, return number
+ * of bytes in the vboot context buffer, -1 on any error (uninitialized
+ * subsystem, corrupted crc8 value, not enough room in the buffer, etc.).
*/
-static int chromeos_read_nvram(u8 *nvram_buffer, int buf_size)
+static int vbc_read(u8 *buf, int buf_size)
{
- int size = chromeos_platform_read_nvram(nvram_buffer, buf_size);
+ ssize_t size = chromeos_vbc_read(buf, buf_size);
if (size <= 0)
return -1;
- if (nvram_buffer[size - 1] != crc8(nvram_buffer, size - 1)) {
- pr_err("%s: NVRAM contents corrupted\n", __func__);
+ if (buf[size - 1] != crc8(buf, size - 1)) {
+ pr_err("%s: vboot context contents corrupted\n", __func__);
return -1;
}
return size;
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * This module isolates ChromeOS platform specific behavior. In particular,
- * it uses calls from chromeos_acpi.c to control the boot flow, and exports some
- * helper functions for kernel-side consumers of platform configuration, such
- * as nvram flags.
*/
#ifndef _DRIVERS_PLATFORM_CHROMEOS_H
#define _DRIVERS_PLATFORM_CHROMEOS_H
-#define MAX_NVRAM_BUFFER_SIZE 64 /* Should be enough for anything. */
+#define MAX_VBOOT_CONTEXT_BUFFER_SIZE 64 /* Should be enough for anything. */
#ifdef CONFIG_ACPI_CHROMEOS
extern int chromeos_legacy_set_need_recovery(void);
static inline int chromeos_legacy_set_need_recovery(void) { return -ENODEV; }
#endif
-extern int chromeos_platform_read_nvram(u8 *nvram_buffer, int buf_size);
-extern int chromeos_platform_write_nvram(u8 *nvram_buffer, int buf_size);
+/**
+ * Read vboot context to buffer
+ *
+ * @param buf Pointer to buffer for storing vboot context
+ * @param count Size of buffer
+ * @return on success, the number of bytes read is returned and
+ * on error, -err is returned.
+ */
+ssize_t chromeos_vbc_read(void *buf, size_t count);
+
+/**
+ * Write vboot context from buffer
+ *
+ * @param buf Pointer to buffer of new vboot context content
+ * @param count Size of buffer
+ * @return on success, the number of bytes written is returned and
+ * on error, -err is returned.
+ */
+ssize_t chromeos_vbc_write(const void *buf, size_t count);
#endif /* _DRIVERS_PLATFORM_CHROMEOS_H */
*
* retrun number of bytes copied, or -1 on any error.
*/
-int chromeos_platform_read_nvram(u8 *nvram_buffer, int buf_size)
+ssize_t chromeos_vbc_read(void *buf, size_t count)
{
int base, size, i;
base = chromeos_acpi_if_data.nv_base.cad_value;
size = chromeos_acpi_if_data.nv_size.cad_value;
- if (buf_size < size) {
- pr_err("%s: not enough room to read nvram (%d < %d)\n",
- __func__, buf_size, size);
+ if (count < size) {
+ pr_err("%s: not enough room to read nvram (%zd < %d)\n",
+ __func__, count, size);
return -EINVAL;
}
for (i = 0; i < size; i++)
- nvram_buffer[i] = nvram_read_byte(base++);
+ ((u8 *)buf)[i] = nvram_read_byte(base++);
return size;
}
-int chromeos_platform_write_nvram(u8 *nvram_buffer, int buf_size)
+ssize_t chromeos_vbc_write(const void *buf, size_t count)
{
unsigned base, size, i;
size = chromeos_acpi_if_data.nv_size.cad_value;
base = chromeos_acpi_if_data.nv_base.cad_value;
- if (buf_size != size) {
- printk(MY_ERR "%s: wrong buffer size (%d != %d)!\n", __func__,
- buf_size, size);
+ if (count != size) {
+ printk(MY_ERR "%s: wrong buffer size (%zd != %d)!\n", __func__,
+ count, size);
return -EINVAL;
}
u8 c;
c = nvram_read_byte(base + i);
- if (c == nvram_buffer[i])
+ if (c == ((u8 *)buf)[i])
continue;
- nvram_write_byte(nvram_buffer[i], base + i);
+ nvram_write_byte(((u8 *)buf)[i], base + i);
}
- return 0;
+ return size;
}
/*