summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--common/Makefile1
-rw-r--r--common/cmd_cros.c168
-rw-r--r--config.mk3
-rw-r--r--include/config_cmd_all.h1
-rw-r--r--lib_generic/chromeos/Makefile55
-rw-r--r--lib_generic/chromeos/boot_device.c119
7 files changed, 348 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index e07906074e..0c24430cd4 100644
--- a/Makefile
+++ b/Makefile
@@ -214,6 +214,7 @@ LIBS = lib/libgeneric.o
LIBS += lib/lzma/liblzma.o
LIBS += lib/lzo/liblzo.o
LIBS += lib/zlib/libz.o
+LIBS += lib_generic/chromeos/libchromeos.a
LIBS += $(shell if [ -f board/$(VENDOR)/common/Makefile ]; then echo \
"board/$(VENDOR)/common/lib$(VENDOR).o"; fi)
LIBS += $(CPUDIR)/lib$(CPU).o
diff --git a/common/Makefile b/common/Makefile
index 9bf807db99..d878491b4f 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -75,6 +75,7 @@ COBJS-$(CONFIG_CMD_BOOTLDR) += cmd_bootldr.o
COBJS-$(CONFIG_CMD_CACHE) += cmd_cache.o
COBJS-$(CONFIG_CMD_CONSOLE) += cmd_console.o
COBJS-$(CONFIG_CMD_CPLBINFO) += cmd_cplbinfo.o
+COBJS-$(CONFIG_CMD_CROS) += cmd_cros.o
COBJS-$(CONFIG_DATAFLASH_MMC_SELECT) += cmd_dataflash_mmc_mux.o
COBJS-$(CONFIG_CMD_DATE) += cmd_date.o
ifdef CONFIG_4xx
diff --git a/common/cmd_cros.c b/common/cmd_cros.c
new file mode 100644
index 0000000000..59637b83ab
--- /dev/null
+++ b/common/cmd_cros.c
@@ -0,0 +1,168 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * 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.
+ */
+
+/*
+ * Support Chrome OS Verify Boot
+ */
+#include <common.h>
+#include <command.h>
+#include <part.h>
+#include <boot_device.h>
+
+#define USAGE(ret, cmdtp, fmt, args...) do { \
+ printf(fmt, args); \
+ cmd_usage(cmdtp); \
+ return (ret); \
+} while (0);
+
+block_dev_desc_t *get_bootdev(void);
+int set_bootdev(char *ifname, int dev, int part);
+
+int do_cros (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
+int do_bootdev (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
+int do_cros_help(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
+
+U_BOOT_CMD(cros, CONFIG_SYS_MAXARGS, 1, do_cros,
+ "perform action (try \"cros help\")",
+ "[action [args...]]\n - perform action with arguments"
+);
+
+cmd_tbl_t cmd_cros_sub[] = {
+ U_BOOT_CMD_MKENT(bootdev, 4, 1, do_bootdev,
+ "show/set/read/write boot device",
+ "[sub-action args...]\n - perform sub-action\n"
+ "\n"
+ "Subactions:\n"
+ " - show boot device (when no sub-action)\n"
+ "set iface dev [part]\n - set boot device\n"
+ "read addr block count\n - read from boot device\n"
+ "write addr block count\n - write to boot device"),
+ U_BOOT_CMD_MKENT(help, 1, 1, do_cros_help,
+ "show this message",
+ "[action]")
+};
+
+int do_cros(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ cmd_tbl_t *c;
+
+ if (argc < 2)
+ USAGE(0, cmdtp, "Missing action\n");
+
+ c = find_cmd_tbl(argv[1], &cmd_cros_sub[0], ARRAY_SIZE(cmd_cros_sub));
+ if (!c)
+ USAGE(1, cmdtp, "Unrecognized action: %s\n", argv[1]);
+
+ return c->cmd(c, flag, argc - 1, argv + 1);
+}
+
+int do_bootdev(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ enum {
+ SET, READ, WRITE
+ } opcode;
+
+ block_dev_desc_t *dev_desc;
+ int dev, part, retcode;
+ uint64_t blk, cnt;
+ void *buf;
+
+ if (argc < 2) { /* show boot device information */
+ if ((dev_desc = get_bootdev()) == NULL)
+ puts("No boot device set\n");
+ else
+ dev_print(dev_desc);
+ return 0;
+ }
+
+ if (!strcmp(argv[1], "set"))
+ opcode = SET;
+ else if (!strcmp(argv[1], "read"))
+ opcode = READ;
+ else if (!strcmp(argv[1], "write"))
+ opcode = WRITE;
+ else
+ USAGE(1, cmdpt, "Unrecognized action: %s\n", argv[1]);
+
+ /* apply De Morgan's laws on
+ * !((argc == 4 && opcode == SET) || argc == 5) */
+ if ((argc != 4 || opcode != SET) && argc != 5)
+ USAGE(1, cmdtp, "Wrong number of arguments\n");
+
+ if (opcode == SET) {
+ dev = (int) simple_strtoul(argv[3], NULL, 16);
+ part = (argc == 5) ?
+ 0 : (int) simple_strtoul(argv[4], NULL, 16);
+
+ if (set_bootdev(argv[2], dev, part)) {
+ puts("Set bootdev failed\n");
+ return 1;
+ }
+
+ return 0;
+ }
+
+ /* assert(opcode == READ || opcode == WRITE); */
+
+ buf = (void *) simple_strtoul(argv[2], NULL, 16);
+ blk = (uint64_t) simple_strtoul(argv[3], NULL, 16);
+ cnt = (uint64_t) simple_strtoul(argv[4], NULL, 16);
+
+ retcode = (opcode == READ) ?
+ BootDeviceReadLBA(blk, cnt, buf) :
+ BootDeviceWriteLBA(blk, cnt, buf);
+
+ if (retcode)
+ USAGE(1, cmdtp, opcode == READ ?
+ "Read failed\n" : "Write failed\n");
+
+ return 0;
+}
+
+int do_cros_help(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ cmd_tbl_t *c;
+
+ if (argc < 2)
+ return _do_help(&cmd_cros_sub[0], ARRAY_SIZE(cmd_cros_sub),
+ cmdtp, flag, argc, argv);
+
+ c = find_cmd_tbl(argv[1], &cmd_cros_sub[0], ARRAY_SIZE(cmd_cros_sub));
+ if (!c)
+ USAGE(1, cmdtp, "Unrecognized action: %s\n", argv[1]);
+
+ cmd_usage(c);
+ return 0;
+}
diff --git a/config.mk b/config.mk
index a0ee570acd..a6da1118fb 100644
--- a/config.mk
+++ b/config.mk
@@ -175,6 +175,9 @@ endif
ifdef VBOOT
CPPFLAGS += -I$(VBOOT)/include/vboot
endif
+ifdef VBOOT_DEBUG
+CPPFLAGS += -DVBOOT_DEBUG
+endif
CPPFLAGS += -I$(TOPDIR)/include
CPPFLAGS += -fno-builtin -ffreestanding -nostdinc \
diff --git a/include/config_cmd_all.h b/include/config_cmd_all.h
index aae6540b43..47abd05e19 100644
--- a/include/config_cmd_all.h
+++ b/include/config_cmd_all.h
@@ -24,6 +24,7 @@
#define CONFIG_CMD_CACHE /* icache, dcache */
#define CONFIG_CMD_CDP /* Cisco Discovery Protocol */
#define CONFIG_CMD_CONSOLE /* coninfo */
+#define CONFIG_CMD_CROS /* Chrome OS verify boot support*/
#define CONFIG_CMD_DATE /* support for RTC, date/time...*/
#define CONFIG_CMD_DHCP /* DHCP Support */
#define CONFIG_CMD_DIAG /* Diagnostics */
diff --git a/lib_generic/chromeos/Makefile b/lib_generic/chromeos/Makefile
new file mode 100644
index 0000000000..f0d2170ab7
--- /dev/null
+++ b/lib_generic/chromeos/Makefile
@@ -0,0 +1,55 @@
+#
+# Copyright 2010, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# 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)libchromeos.a
+
+COBJS-$(CONFIG_CHROMEOS) += boot_device.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/lib_generic/chromeos/boot_device.c b/lib_generic/chromeos/boot_device.c
new file mode 100644
index 0000000000..5a57e6d856
--- /dev/null
+++ b/lib_generic/chromeos/boot_device.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright 2010, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * 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 <config.h>
+#include <common.h>
+#include <part.h>
+#include <boot_device.h>
+
+static struct {
+ block_dev_desc_t *dev_desc;
+ ulong offset, limit;
+} bootdev_config = {
+ .dev_desc = NULL,
+ .offset = 0u,
+ .limit = 0u
+};
+
+block_dev_desc_t *get_bootdev(void)
+{
+ return bootdev_config.dev_desc;
+}
+
+int set_bootdev(char *ifname, int dev, int part)
+{
+ disk_partition_t part_info;
+
+ if ((bootdev_config.dev_desc = get_dev(ifname, dev)) == NULL)
+ goto cleanup; /* block device not supported */
+
+ /* largest address not available in block_dev_desc_t */
+ if (part == 0) {
+ bootdev_config.limit = ~0;
+ return 0;
+ }
+
+ if (get_partition_info(bootdev_config.dev_desc, part, &part_info))
+ goto cleanup; /* cannot find partition */
+
+ bootdev_config.offset = part_info.start;
+ bootdev_config.limit = part_info.size;
+
+ return 0;
+
+cleanup:
+ bootdev_config.dev_desc = NULL;
+ bootdev_config.offset = 0;
+ bootdev_config.limit = 0;
+
+ return 1;
+}
+
+int BootDeviceReadLBA(uint64_t lba_start, uint64_t lba_count, void *buffer)
+{
+ block_dev_desc_t *dev_desc;
+
+ if ((dev_desc = bootdev_config.dev_desc) == NULL)
+ return 1; /* No boot device configured */
+
+ if (lba_start + lba_count > bootdev_config.limit)
+ return 1; /* read out of range */
+
+ if (dev_desc->block_read(dev_desc->dev,
+ bootdev_config.offset + lba_start, lba_count,
+ buffer) < 0)
+ return 1; /* error reading blocks */
+
+ return 0;
+}
+
+int BootDeviceWriteLBA(uint64_t lba_start, uint64_t lba_count,
+ const void *buffer)
+{
+ block_dev_desc_t *dev_desc;
+
+ if ((dev_desc = bootdev_config.dev_desc) == NULL)
+ return 1; /* No boot device configured */
+
+ if (lba_start + lba_count > bootdev_config.limit)
+ return 1; /* read out of range */
+
+ if (dev_desc->block_write(dev_desc->dev,
+ bootdev_config.offset + lba_start, lba_count,
+ buffer) < 0)
+ return 1; /* error reading blocks */
+
+ return 0;
+}