~funderscore blog cgit wiki get in touch
aboutsummaryrefslogtreecommitdiff
blob: 52b328300374fab943c584810f4bf13140edf1d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// SPDX-License-Identifier: GPL-2.0
/*
 * Verified Boot for Embedded (VBE) access functions
 *
 * Copyright 2022 Google LLC
 * Written by Simon Glass <sjg@chromium.org>
 */

#include <common.h>
#include <bootmeth.h>
#include <bootstd.h>
#include <dm.h>
#include <image.h>
#include <vbe.h>
#include <dm/uclass-internal.h>

/**
 * is_vbe() - Check if a device is a VBE method
 *
 * @dev: Device to check
 * @return true if this is a VBE bootmth device, else false
 */
static bool is_vbe(struct udevice *dev)
{
	return !strncmp("vbe", dev->driver->name, 3);
}

int vbe_find_next_device(struct udevice **devp)
{
	for (uclass_find_next_device(devp);
	     *devp;
	     uclass_find_next_device(devp)) {
		if (is_vbe(*devp))
			return 0;
	}

	return 0;
}

int vbe_find_first_device(struct udevice **devp)
{
	uclass_find_first_device(UCLASS_BOOTMETH, devp);
	if (!*devp || is_vbe(*devp))
		return 0;

	return vbe_find_next_device(devp);
}

int vbe_list(void)
{
	struct bootstd_priv *std;
	struct udevice *dev;
	int ret;

	ret = bootstd_get_priv(&std);
	if (ret)
		return ret;

	printf("%3s  %-3s  %-15s  %-15s %s\n", "#", "Sel", "Device", "Driver",
	       "Description");
	printf("%3s  %-3s  %-15s  %-15s %s\n", "---", "---", "--------------",
	       "--------------", "-----------");
	for (ret = vbe_find_first_device(&dev); dev;
	     ret = vbe_find_next_device(&dev)) {
		const struct bootmeth_uc_plat *plat = dev_get_uclass_plat(dev);

		printf("%3d  %-3s  %-15s  %-15s %s\n", dev_seq(dev),
		       std->vbe_bootmeth == dev ? "*" : "", dev->name,
		       dev->driver->name, plat->desc);
	}
	printf("%3s  %-3s  %-15s  %-15s %s\n", "---", "---", "--------------",
	       "--------------", "-----------");

	return 0;
}

int vbe_select(struct udevice *dev)
{
	struct bootstd_priv *std;
	int ret;

	ret = bootstd_get_priv(&std);
	if (ret)
		return ret;
	std->vbe_bootmeth = dev;

	return 0;
}

int vbe_find_by_any(const char *name, struct udevice **devp)
{
	struct udevice *dev;
	int ret, seq;
	char *endp;

	seq = simple_strtol(name, &endp, 16);

	/* Select by name */
	if (*endp) {
		ret = uclass_get_device_by_name(UCLASS_BOOTMETH, name, &dev);
		if (ret) {
			printf("Cannot probe VBE bootmeth '%s' (err=%d)\n", name,
			       ret);
			return ret;
		}

	/* select by number */
	} else {
		ret = uclass_get_device_by_seq(UCLASS_BOOTMETH, seq, &dev);
		if (ret) {
			printf("Cannot find '%s' (err=%d)\n", name, ret);
			return ret;
		}
	}

	*devp = dev;

	return 0;
}