summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2017-03-20 21:26:32 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-03-21 23:15:07 -0700
commita4f6a548d8f3e05d01563b52095b03cecb23fe28 (patch)
tree709e6b119fc5e21a84bf3de818db8c3071cd9f0e
parentbd30d3f2cd5a0fb90ec72ed7ea47b3f29d114c7f (diff)
downloadchrome-ec-a4f6a548d8f3e05d01563b52095b03cecb23fe28.tar.gz
g: expose API to unlock secondary RO area
For the upcoming header restore vendor command implementation there is a need to allow rw access to the alternative RO area. A static function for this is available in upgrade_fw.c, let's make it available to other users. BRANCH=cr50 BUG=b:35580805 TEST=verified that it is still possible to update the RO. Change-Id: I879804ff180c5d00cf6860ce5669f2fe48731832 Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/457501 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r--chip/g/flash.c12
-rw-r--r--chip/g/flash_info.h2
-rw-r--r--chip/g/upgrade_fw.c23
3 files changed, 21 insertions, 16 deletions
diff --git a/chip/g/flash.c b/chip/g/flash.c
index 2029a0e438..6fd262a31d 100644
--- a/chip/g/flash.c
+++ b/chip/g/flash.c
@@ -451,6 +451,18 @@ int flash_physical_erase(int byte_offset, int num_bytes)
return EC_SUCCESS;
}
+
+/* Enable write access to the backup RO section. */
+void flash_open_ro_window(uint32_t offset, size_t size_b)
+{
+ GREG32(GLOBALSEC, FLASH_REGION6_BASE_ADDR) =
+ offset + CONFIG_PROGRAM_MEMORY_BASE;
+ GREG32(GLOBALSEC, FLASH_REGION6_SIZE) = size_b - 1;
+ GWRITE_FIELD(GLOBALSEC, FLASH_REGION6_CTRL, EN, 1);
+ GWRITE_FIELD(GLOBALSEC, FLASH_REGION6_CTRL, RD_EN, 1);
+ GWRITE_FIELD(GLOBALSEC, FLASH_REGION6_CTRL, WR_EN, 1);
+}
+
#ifdef CR50_DEV
static int command_erase_flash_info(int argc, char **argv)
diff --git a/chip/g/flash_info.h b/chip/g/flash_info.h
index b80c6889ba..9ff730b39e 100644
--- a/chip/g/flash_info.h
+++ b/chip/g/flash_info.h
@@ -30,4 +30,6 @@ void flash_info_write_disable(void);
int flash_info_physical_write(int byte_offset, int num_bytes, const char *data);
int flash_physical_info_read_word(int byte_offset, uint32_t *dst);
+void flash_open_ro_window(uint32_t offset, size_t size_b);
+
#endif /* ! __EC_CHIP_G_FLASH_INFO_H */
diff --git a/chip/g/upgrade_fw.c b/chip/g/upgrade_fw.c
index 182f1308fc..17bffe5f4c 100644
--- a/chip/g/upgrade_fw.c
+++ b/chip/g/upgrade_fw.c
@@ -3,21 +3,23 @@
* found in the LICENSE file.
*/
+#include "config.h"
+
#include "byteorder.h"
#include "compile_time_macros.h"
#include "console.h"
+#include "cryptoc/sha.h"
#include "dcrypto/dcrypto.h"
#include "extension.h"
#include "flash.h"
+#include "flash_info.h"
#include "hooks.h"
+#include "registers.h"
+#include "signed_header.h"
#include "system.h"
#include "system_chip.h"
-#include "registers.h"
#include "uart.h"
-
-#include "signed_header.h"
#include "upgrade_fw.h"
-#include "cryptoc/sha.h"
#define CPRINTF(format, args...) cprintf(CC_EXTENSION, format, ## args)
@@ -66,17 +68,6 @@ static void set_valid_sections(void)
CONFIG_RW_SIZE;
}
-/* Enable write access to the backup RO section. */
-static void open_ro_window(uint32_t offset, size_t size_b)
-{
- GREG32(GLOBALSEC, FLASH_REGION6_BASE_ADDR) =
- offset + CONFIG_PROGRAM_MEMORY_BASE;
- GREG32(GLOBALSEC, FLASH_REGION6_SIZE) = size_b - 1;
- GWRITE_FIELD(GLOBALSEC, FLASH_REGION6_CTRL, EN, 1);
- GWRITE_FIELD(GLOBALSEC, FLASH_REGION6_CTRL, RD_EN, 1);
- GWRITE_FIELD(GLOBALSEC, FLASH_REGION6_CTRL, WR_EN, 1);
-}
-
/*
* Verify that the passed in block fits into the valid area. If it does, and
* is destined to the base address of the area - erase the area contents.
@@ -128,7 +119,7 @@ static uint8_t check_update_chunk(uint32_t block_offset, size_t body_size)
size = valid_sections.ro_top_offset -
valid_sections.ro_base_offset;
/* backup RO area write access needs to be enabled. */
- open_ro_window(base, size);
+ flash_open_ro_window(base, size);
if (flash_physical_erase(base, size) != EC_SUCCESS) {
CPRINTF("%s:%d erase failure of 0x%x..+0x%x\n",
__func__, __LINE__, base, size);