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
|
/* Copyright (c) 2012 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.
*/
/* Mock flash memory module for Chrome EC.
* Due to RAM size limit, we cannot mock entire flash memory. Instead, we only
* mock the last bank in order to make pstate works. */
#include "flash.h"
#include "uart.h"
#include "util.h"
#define FLASH_FSIZE 0x7f
#define PHYSICAL_SIZE ((FLASH_FSIZE + 1) * CONFIG_FLASH_BANK_SIZE)
#define FLASH_MOCK_BEGIN (FLASH_FSIZE * CONFIG_FLASH_BANK_SIZE)
char mock_protect[FLASH_FSIZE + 1];
char pstate_space[CONFIG_FLASH_BANK_SIZE];
int flash_physical_size(void)
{
return PHYSICAL_SIZE;
}
int flash_physical_write(int offset, int size, const char* data)
{
int i;
int xorsum = 0;
if (offset >= FLASH_MOCK_BEGIN)
memcpy(pstate_space + offset - FLASH_MOCK_BEGIN, data, size);
else {
xorsum = 0;
for (i = 0; i < size; ++i)
xorsum ^= data[i];
uart_printf("Flash write at %x size %x XOR %x\n",
offset,
size,
xorsum);
}
return EC_SUCCESS;
}
int flash_physical_erase(int offset, int size)
{
uart_printf("Flash erase at %x size %x\n", offset, size);
if (offset + size >= FLASH_MOCK_BEGIN)
memset(pstate_space, 0xff, offset + size - FLASH_MOCK_BEGIN);
return EC_SUCCESS;
}
int flash_physical_get_protect(int block)
{
return mock_protect[block];
}
void flash_physical_set_protect(int start_bank, int bank_count)
{
for (; bank_count > 0; bank_count--)
mock_protect[start_bank++] = 1;
}
int flash_physical_pre_init(void)
{
return EC_SUCCESS;
}
|