summaryrefslogtreecommitdiff
path: root/lib/vbexport/boot_device_usb.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2011-08-17 15:24:55 -0700
committerSimon Glass <sjg@chromium.org>2011-08-30 13:25:18 -0700
commitf759070b539747df59380ca0164b25515d927908 (patch)
tree24607aaca599f57a75eb1a393b63f3217e3a4ea7 /lib/vbexport/boot_device_usb.c
parent569408cfc87ca2cc9a45e1ebbb934624788610bf (diff)
CHROMIUMOS: Refactor boot_device to support multiple devices nicely
Now that we have MMC, USB and IDE, with some enabled for only some platforms, the code has become ugly. This refactors the code to separate out each device into its own file, with a generic start/scan interface. This also fixes the problem with indexing of devices, where it could not cope with MMC and IDE active at the same time. BUG=chromium-os:19518 TEST=build on Seaboard; vbexport_test diskinfo See that all boot devices are found with SD and USB inserted Change-Id: I4844f7b33885ec01e922686a17c90afdf0a55a9d Reviewed-on: http://gerrit.chromium.org/gerrit/6254 Tested-by: Simon Glass <sjg@chromium.org> Reviewed-by: Che-Liang Chiou <clchiou@chromium.org> Reviewed-by: Stefan Reinauer <reinauer@google.com> Reviewed-by: Anton Staaf <robotboy@chromium.org> Reviewed-on: http://gerrit.chromium.org/gerrit/6918 Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib/vbexport/boot_device_usb.c')
-rw-r--r--lib/vbexport/boot_device_usb.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/vbexport/boot_device_usb.c b/lib/vbexport/boot_device_usb.c
new file mode 100644
index 0000000000..d261e4e964
--- /dev/null
+++ b/lib/vbexport/boot_device_usb.c
@@ -0,0 +1,60 @@
+/*
+ * 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 <usb.h>
+
+#include "boot_device.h"
+
+#include <vboot_api.h>
+
+static int boot_device_usb_start(uint32_t disk_flags)
+{
+ /* If we aren't looking for removable disks, skip USB */
+ if (!(disk_flags & VB_DISK_FLAG_REMOVABLE))
+ return 0;
+
+ /*
+ * We should stop all USB devices first. Otherwise we can't detect any
+ * new devices.
+ */
+ usb_stop();
+
+ if (usb_init() >= 0)
+ usb_stor_scan(/*mode=*/1);
+ return 1;
+}
+
+static int boot_device_usb_scan(block_dev_desc_t **desc, int max_devs,
+ uint32_t disk_flags)
+{
+ int index;
+
+ max_devs = min(max_devs, USB_MAX_STOR_DEV);
+
+ for (index = 0; index < max_devs; index++) {
+ desc[index] = usb_stor_get_dev(index);
+ if (!desc[index])
+ break;
+ }
+ return index;
+}
+
+static struct boot_interface usb_interface = {
+ .name = "usb",
+ .type = IF_TYPE_USB,
+ .start = boot_device_usb_start,
+ .scan = boot_device_usb_scan,
+};
+
+int boot_device_usb_probe(void)
+{
+ return boot_device_register_interface(&usb_interface);
+}