summaryrefslogtreecommitdiff
path: root/chip/npcx/spiflashfw
diff options
context:
space:
mode:
Diffstat (limited to 'chip/npcx/spiflashfw')
-rw-r--r--chip/npcx/spiflashfw/monitor_hdr.c37
-rw-r--r--chip/npcx/spiflashfw/npcx_monitor.c338
-rw-r--r--chip/npcx/spiflashfw/npcx_monitor.h33
-rw-r--r--chip/npcx/spiflashfw/npcx_monitor.ld52
4 files changed, 0 insertions, 460 deletions
diff --git a/chip/npcx/spiflashfw/monitor_hdr.c b/chip/npcx/spiflashfw/monitor_hdr.c
deleted file mode 100644
index 219a037d27..0000000000
--- a/chip/npcx/spiflashfw/monitor_hdr.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Copyright 2017 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.
- *
- * NPCX SoC spi flash update tool - monitor firmware header
- */
-
-#include "config.h"
-#include "npcx_monitor.h"
-
-const struct monitor_header_tag monitor_hdr = {
- /* 0x00: TAG = 0xA5075001 */
- NPCX_MONITOR_UUT_TAG,
- /* 0x04: Size·of·the·EC image·be·programmed.
- * Default = code RAM size
- */
- NPCX_PROGRAM_MEMORY_SIZE,
- /*
- * 0x08: The start of RAM address to store the EC image, which will be
- * programed into the SPI flash.
- */
- CONFIG_PROGRAM_MEMORY_BASE,
- /* 0x0C:The Flash start address to be programmed*/
-#ifdef SECTION_IS_RO
- /* Default: RO image is programed from the start of SPI flash */
- CONFIG_EC_PROTECTED_STORAGE_OFF,
-#else
- /* Default: RW image is programed from the half of SPI flash */
- CONFIG_EC_WRITABLE_STORAGE_OFF,
-#endif
- /* 0x10: Maximum allowable flash clock frequency */
- 0,
- /* 0x11: SPI Flash read mode */
- 0,
- /* 0x12: Reserved */
- 0,
-};
diff --git a/chip/npcx/spiflashfw/npcx_monitor.c b/chip/npcx/spiflashfw/npcx_monitor.c
deleted file mode 100644
index cd52e7a80f..0000000000
--- a/chip/npcx/spiflashfw/npcx_monitor.c
+++ /dev/null
@@ -1,338 +0,0 @@
-/* Copyright 2014 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.
- *
- * NPCX SoC spi flash update tool - monitor firmware
- */
-
-#include <stdint.h>
-#include "config.h"
-#include "npcx_monitor.h"
-#include "registers.h"
-#include "util.h"
-
-/*****************************************************************************/
-/* spi flash internal functions */
-void sspi_flash_pinmux(int enable)
-{
- if (enable)
- CLEAR_BIT(NPCX_DEVALT(0), NPCX_DEVALT0_NO_F_SPI);
- else
- SET_BIT(NPCX_DEVALT(0), NPCX_DEVALT0_NO_F_SPI);
-
- /* CS0/1 pinmux */
- if (enable) {
-#if (FIU_CHIP_SELECT == 1)
- SET_BIT(NPCX_DEVALT(0), NPCX_DEVALT0_F_SPI_CS1_1);
-#elif (FIU_CHIP_SELECT == 2)
- SET_BIT(NPCX_DEVALT(0), NPCX_DEVALT0_F_SPI_CS1_2);
-#endif
- } else {
- CLEAR_BIT(NPCX_DEVALT(0), NPCX_DEVALT0_F_SPI_CS1_1);
- CLEAR_BIT(NPCX_DEVALT(0), NPCX_DEVALT0_F_SPI_CS1_2);
- }
-}
-
-void sspi_flash_tristate(int enable)
-{
- if (enable) {
- /* Enable FIU pins to tri-state */
- SET_BIT(NPCX_DEVCNT, NPCX_DEVCNT_F_SPI_TRIS);
- } else {
- /* Disable FIU pins to tri-state */
- CLEAR_BIT(NPCX_DEVCNT, NPCX_DEVCNT_F_SPI_TRIS);
- }
-}
-
-void sspi_flash_execute_cmd(uint8_t code, uint8_t cts)
-{
- /* set UMA_CODE */
- NPCX_UMA_CODE = code;
- /* execute UMA flash transaction */
- NPCX_UMA_CTS = cts;
- while (IS_BIT_SET(NPCX_UMA_CTS, NPCX_UMA_CTS_EXEC_DONE))
- ;
-}
-
-void sspi_flash_cs_level(int level)
-{
- /* level is high */
- if (level) {
- /* Set chip select to high */
- SET_BIT(NPCX_UMA_ECTS, NPCX_UMA_ECTS_SW_CS1);
- } else { /* level is low */
- /* Set chip select to low */
- CLEAR_BIT(NPCX_UMA_ECTS, NPCX_UMA_ECTS_SW_CS1);
- }
-}
-
-void sspi_flash_wait_ready(void)
-{
- uint8_t mask = SPI_FLASH_SR1_BUSY;
-
- /* Chip Select down. */
- sspi_flash_cs_level(0);
- /* Command for Read status register */
- sspi_flash_execute_cmd(CMD_READ_STATUS_REG, MASK_CMD_ONLY);
- do {
- /* Read status register */
- NPCX_UMA_CTS = MASK_RD_1BYTE;
- while (IS_BIT_SET(NPCX_UMA_CTS, NPCX_UMA_CTS_EXEC_DONE))
- ;
- } while (NPCX_UMA_DB0 & mask); /* Wait for Busy clear */
- /* Chip Select high. */
- sspi_flash_cs_level(1);
-}
-
-int sspi_flash_write_enable(void)
-{
- uint8_t mask = SPI_FLASH_SR1_WEL;
- /* Write enable command */
- sspi_flash_execute_cmd(CMD_WRITE_EN, MASK_CMD_ONLY);
- /* Wait for flash is not busy */
- sspi_flash_wait_ready();
-
- if (NPCX_UMA_DB0 & mask)
- return 1;
- else
- return 0;
-}
-
-void sspi_flash_set_address(uint32_t dest_addr)
-{
- uint8_t *addr = (uint8_t *)&dest_addr;
- /* Write address */
- NPCX_UMA_AB2 = addr[2];
- NPCX_UMA_AB1 = addr[1];
- NPCX_UMA_AB0 = addr[0];
-}
-
-void sspi_flash_burst_write(unsigned int dest_addr, unsigned int bytes,
- const char *data)
-{
- unsigned int i;
- /* Chip Select down. */
- sspi_flash_cs_level(0);
- /* Set erase address */
- sspi_flash_set_address(dest_addr);
- /* Start write */
- sspi_flash_execute_cmd(CMD_FLASH_PROGRAM, MASK_CMD_WR_ADR);
- for (i = 0; i < bytes; i++) {
- sspi_flash_execute_cmd(*data, MASK_CMD_WR_ONLY);
- data++;
- }
- /* Chip Select up */
- sspi_flash_cs_level(1);
-}
-
-int sspi_flash_physical_clear_stsreg(void)
-{
- /* Disable tri-state */
- sspi_flash_tristate(0);
- /* Enable write */
- sspi_flash_write_enable();
-
- NPCX_UMA_DB0 = 0x0;
- NPCX_UMA_DB1 = 0x0;
-
- /* Write status register 1/2 */
- sspi_flash_execute_cmd(CMD_WRITE_STATUS_REG, MASK_CMD_WR_2BYTE);
-
- /* Wait writing completed */
- sspi_flash_wait_ready();
-
- /* Read status register 1/2 for checking */
- sspi_flash_execute_cmd(CMD_READ_STATUS_REG, MASK_CMD_RD_1BYTE);
- if (NPCX_UMA_DB0 != 0x00)
- return 0;
- sspi_flash_execute_cmd(CMD_READ_STATUS_REG2, MASK_CMD_RD_1BYTE);
- if (NPCX_UMA_DB0 != 0x00)
- return 0;
- /* Enable tri-state */
- sspi_flash_tristate(1);
-
- return 1;
-}
-
-void sspi_flash_physical_write(int offset, int size, const char *data)
-{
- int dest_addr = offset;
- const int sz_page = CONFIG_FLASH_WRITE_IDEAL_SIZE;
-
- /* Disable tri-state */
- sspi_flash_tristate(0);
-
- /* Write the data per CONFIG_FLASH_WRITE_IDEAL_SIZE bytes */
- for (; size >= sz_page; size -= sz_page) {
- /* Enable write */
- sspi_flash_write_enable();
- /* Burst UMA transaction */
- sspi_flash_burst_write(dest_addr, sz_page, data);
- /* Wait write completed */
- sspi_flash_wait_ready();
-
- data += sz_page;
- dest_addr += sz_page;
- }
-
- /* Handle final partial page, if any */
- if (size != 0) {
- /* Enable write */
- sspi_flash_write_enable();
- /* Burst UMA transaction */
- sspi_flash_burst_write(dest_addr, size, data);
-
- /* Wait write completed */
- sspi_flash_wait_ready();
- }
-
- /* Enable tri-state */
- sspi_flash_tristate(1);
-}
-
-void sspi_flash_physical_erase(int offset, int size)
-{
- /* Disable tri-state */
- sspi_flash_tristate(0);
-
- /* Alignment has been checked in upper layer */
- for (; size > 0; size -= NPCX_MONITOR_FLASH_ERASE_SIZE,
- offset += NPCX_MONITOR_FLASH_ERASE_SIZE) {
- /* Enable write */
- sspi_flash_write_enable();
- /* Set erase address */
- sspi_flash_set_address(offset);
- /* Start erase */
- sspi_flash_execute_cmd(CMD_SECTOR_ERASE, MASK_CMD_ADR);
-
- /* Wait erase completed */
- sspi_flash_wait_ready();
- }
-
- /* Enable tri-state */
- sspi_flash_tristate(1);
-}
-
-int sspi_flash_verify(int offset, int size, const char *data)
-{
- int i, result;
- uint8_t *ptr_flash;
- uint8_t *ptr_mram;
- uint8_t cmp_data;
-
- ptr_flash = (uint8_t *)(CONFIG_MAPPED_STORAGE_BASE + offset);
- ptr_mram = (uint8_t *)data;
- result = 1;
-
- /* Disable tri-state */
- sspi_flash_tristate(0);
-
- /* Start to verify */
- for (i = 0; i < size; i++) {
- cmp_data = ptr_mram ? ptr_mram[i] : 0xFF;
- if (ptr_flash[i] != cmp_data) {
- result = 0;
- break;
- }
- }
-
- /* Enable tri-state */
- sspi_flash_tristate(1);
- return result;
-}
-
-int sspi_flash_get_image_used(const char *fw_base)
-{
- const uint8_t *image;
- int size = MAX(CONFIG_RO_SIZE, CONFIG_RW_SIZE); /* max size is 128KB */
-
- image = (const uint8_t *)fw_base;
- /*
- * Scan backwards looking for 0xea byte, which is by definition the
- * last byte of the image. See ec.lds.S for how this is inserted at
- * the end of the image.
- */
- for (size--; size > 0 && image[size] != 0xea; size--)
- ;
-
- return size ? size + 1 : 0; /* 0xea byte IS part of the image */
-
-}
-
-/* Entry function of spi upload function */
-uint32_t __attribute__ ((section(".startup_text")))
-sspi_flash_upload(int spi_offset, int spi_size)
-{
- /*
- * Flash image has been uploaded to Code RAM
- */
- uint32_t sz_image;
- uint32_t uut_tag;
- const char *image_base;
- uint32_t *flag_upload = (uint32_t *)SPI_PROGRAMMING_FLAG;
- struct monitor_header_tag *monitor_header =
- (struct monitor_header_tag *)NPCX_MONITOR_HEADER_ADDR;
-
- *flag_upload = 0;
-
- uut_tag = monitor_header->tag;
- /* If it is UUT tag, read required parameters from header */
- if (uut_tag == NPCX_MONITOR_UUT_TAG) {
- sz_image = monitor_header->size;
- spi_offset = monitor_header->dest_addr;
- image_base = (const char *)(monitor_header->src_addr);
- } else {
- sz_image = spi_size;
- image_base = (const char *)CONFIG_PROGRAM_MEMORY_BASE;
- }
-
- /* Unlock & stop watchdog */
- NPCX_WDSDM = 0x87;
- NPCX_WDSDM = 0x61;
- NPCX_WDSDM = 0x63;
-
- /* UMA Unlock */
- CLEAR_BIT(NPCX_UMA_ECTS, NPCX_UMA_ECTS_UMA_LOCK);
-
- /*
- * If UUT is used, assuming the target is the internal flash.
- * Don't switch the pinmux and make sure bit 7 of DEVALT0 is set.
- */
- if (uut_tag == NPCX_MONITOR_UUT_TAG)
- SET_BIT(NPCX_DEVALT(0), NPCX_DEVALT0_NO_F_SPI);
- else
- /* Set pinmux first */
- sspi_flash_pinmux(1);
-
- /* Get size of image automatically */
- if (sz_image == 0)
- sz_image = sspi_flash_get_image_used(image_base);
-
- /* Clear status reg of spi flash for protection */
- if (sspi_flash_physical_clear_stsreg()) {
- /* Start to erase */
- sspi_flash_physical_erase(spi_offset, sz_image);
- /* Start to write */
- if (image_base != NULL)
- sspi_flash_physical_write(spi_offset, sz_image,
- image_base);
- /* Verify data */
- if (sspi_flash_verify(spi_offset, sz_image, image_base))
- *flag_upload |= 0x02;
- }
- if (uut_tag != NPCX_MONITOR_UUT_TAG)
- /* Disable pinmux */
- sspi_flash_pinmux(0);
-
- /* Mark we have finished upload work */
- *flag_upload |= 0x01;
-
- /* Return the status back to ROM code is required for UUT */
- if (uut_tag == NPCX_MONITOR_UUT_TAG)
- return *flag_upload;
-
- /* Infinite loop */
- for (;;)
- ;
-}
-
diff --git a/chip/npcx/spiflashfw/npcx_monitor.h b/chip/npcx/spiflashfw/npcx_monitor.h
deleted file mode 100644
index f4f30454d2..0000000000
--- a/chip/npcx/spiflashfw/npcx_monitor.h
+++ /dev/null
@@ -1,33 +0,0 @@
-/* Copyright 2017 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.
- */
-#ifndef __CROS_EC_NPCX_MONITOR_H
-#define __CROS_EC_NPCX_MONITOR_H
-
-#include <stdint.h>
-
-#define NPCX_MONITOR_UUT_TAG 0xA5075001
-#define NPCX_MONITOR_HEADER_ADDR 0x200C3000
-
-/* Flag to record the progress of programming SPI flash */
-#define SPI_PROGRAMMING_FLAG 0x200C4000
-
-struct monitor_header_tag {
- /* offset 0x00: TAG NPCX_MONITOR_TAG */
- uint32_t tag;
- /* offset 0x04: Size of the binary being programmed (in bytes) */
- uint32_t size;
- /* offset 0x08: The RAM address of the binary to program into the SPI */
- uint32_t src_addr;
- /* offset 0x0C: The Flash address to be programmed (Absolute address) */
- uint32_t dest_addr;
- /* offset 0x10: Maximum allowable flash clock frequency */
- uint8_t max_clock;
- /* offset 0x11: SPI Flash read mode */
- uint8_t read_mode;
- /* offset 0x12: Reserved */
- uint16_t reserved;
-} __packed;
-
-#endif /* __CROS_EC_NPCX_MONITOR_H */
diff --git a/chip/npcx/spiflashfw/npcx_monitor.ld b/chip/npcx/spiflashfw/npcx_monitor.ld
deleted file mode 100644
index 03e38b0609..0000000000
--- a/chip/npcx/spiflashfw/npcx_monitor.ld
+++ /dev/null
@@ -1,52 +0,0 @@
-/* Copyright 2017 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.
- *
- * NPCX SoC spi flash update tool
- */
-
-/* Memory Spaces Definitions */
-MEMORY
-{
- CODERAM (rx) : ORIGIN = 0x200C3020, LENGTH = 0xFE0
-}
-
-/*
- * The entry point is informative, for debuggers and simulators,
- * since the Cortex-M vector points to it anyway.
- */
-ENTRY(sspi_flash_upload)
-
-
-/* Sections Definitions */
-
-SECTIONS
-{
- .startup_text :
- {
- . = ALIGN(4);
- *(.startup_text ) /* Startup code */
- . = ALIGN(4);
- } >CODERAM
-
- /*
- * The program code is stored in the .text section,
- * which goes to CODERAM.
- */
- .text :
- {
- . = ALIGN(4);
- *(.text .text.*) /* all remaining code */
- *(.rodata .rodata.*) /* read-only data (constants) */
- } >CODERAM
-
- . = ALIGN(4);
- _etext = .;
-
- /*
- * This address is used by the startup code to
- * initialise the .data section.
- */
- _sidata = _etext;
-
-}