summaryrefslogtreecommitdiff
path: root/zephyr/emul/emul_flash.c
blob: 2fa88916f34215bce3eb76d313e3970e0306153f (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* Copyright 2022 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.
 */

#define DT_DRV_COMPAT cros_ec_flash_emul

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(emul_flash);

#include <zephyr/device.h>
#include <zephyr/drivers/emul.h>
#include <ec_commands.h>
#include <drivers/cros_flash.h>
#include <zephyr/sys/__assert.h>

struct flash_emul_data {};

struct flash_emul_cfg {
	/** Label of the device being emulated */
	const char *dev_label;
	/** Pointer to run-time data */
	struct flash_emul_data *data;
};

void system_jump_to_booter(void)
{
}

uint32_t system_get_lfw_address(void)
{
	uint32_t jump_addr = (uint32_t)system_jump_to_booter;
	return jump_addr;
}

enum ec_image system_get_shrspi_image_copy(void)
{
	return EC_IMAGE_RO;
}

void system_set_image_copy(enum ec_image copy)
{
}

static int cros_flash_emul_init(const struct device *dev)
{
	return 0;
}

static int cros_flash_emul_write(const struct device *dev, int offset, int size,
				 const char *src_data)
{
	__ASSERT(false, "Not implemented");
	return -EINVAL;
}

static int cros_flash_emul_erase(const struct device *dev, int offset, int size)
{
	__ASSERT(false, "Not implemented");
	return -EINVAL;
}

static int cros_flash_emul_get_protect(const struct device *dev, int bank)
{
	__ASSERT(false, "Not implemented");
	return -EINVAL;
}

static uint32_t cros_flash_emul_get_protect_flags(const struct device *dev)
{
	return EC_FLASH_PROTECT_ERROR_UNKNOWN;
}

static int cros_flash_emul_protect_at_boot(const struct device *dev,
					   uint32_t new_flags)
{
	__ASSERT(false, "Not implemented");
	return -EINVAL;
}

static int cros_flash_emul_protect_now(const struct device *dev, int all)
{
	__ASSERT(false, "Not implemented");
	return -EINVAL;
}

static int cros_flash_emul_get_jedec_id(const struct device *dev,
					uint8_t *manufacturer, uint16_t *device)
{
	__ASSERT(false, "Not implemented");
	return -EINVAL;
}

static int cros_flash_emul_get_status(const struct device *dev, uint8_t *sr1,
				      uint8_t *sr2)
{
	__ASSERT(false, "Not implemented");
	return -EINVAL;
}


static const struct cros_flash_driver_api emul_cros_flash_driver_api = {
	.init = cros_flash_emul_init,
	.physical_write = cros_flash_emul_write,
	.physical_erase = cros_flash_emul_erase,
	.physical_get_protect = cros_flash_emul_get_protect,
	.physical_get_protect_flags = cros_flash_emul_get_protect_flags,
	.physical_protect_at_boot = cros_flash_emul_protect_at_boot,
	.physical_protect_now = cros_flash_emul_protect_now,
	.physical_get_jedec_id = cros_flash_emul_get_jedec_id,
	.physical_get_status = cros_flash_emul_get_status,
};

static int flash_emul_init(const struct device *dev)
{
	ARG_UNUSED(dev);

	return 0;
}

#define FLASH_EMUL(n)                                                      \
	static struct flash_emul_data flash_emul_data_##n = {              \
	};                                                                 \
									   \
	static const struct flash_emul_cfg flash_emul_cfg_##n = {          \
		.dev_label = DT_INST_LABEL(n),                             \
		.data = &flash_emul_data_##n,                              \
	};                                                                 \
	DEVICE_DT_INST_DEFINE(n, flash_emul_init, NULL,                    \
			      &flash_emul_data_##n, &flash_emul_cfg_##n,   \
			      PRE_KERNEL_1,                                \
			      CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,         \
			      &emul_cros_flash_driver_api)
DT_INST_FOREACH_STATUS_OKAY(FLASH_EMUL);