mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-29 05:21:37 +03:00
XMC flash support - WIP (#6725)
* Move the spi vendor list from Esp.h to its own header in eboot. * Fix ifdef issue with spi_vendors.h * Add initFlashQuirks() for any chip specific flash initialization. Called from user_init(). * namespace experimental for initFlashQuirks() * Slow down flash access during eboot firmware copy Part 1 - still some work to do * Slow down flash access during eboot firmware copy on XMC chips Part 2 - Identify the chip type. Note: there may still be issues with the access speed change. This is very much experimental. * Commit eboot.elf Co-authored-by: Develo <deveyes@gmail.com> Co-authored-by: Earle F. Philhower, III <earlephilhower@yahoo.com>
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
#include <string.h>
|
||||
#include "flash.h"
|
||||
#include "eboot_command.h"
|
||||
#include "spi_vendors.h"
|
||||
#include <uzlib.h>
|
||||
|
||||
extern unsigned char _gzip_dict;
|
||||
@ -189,6 +190,28 @@ int copy_raw(const uint32_t src_addr,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define XMC_SUPPORT
|
||||
#ifdef XMC_SUPPORT
|
||||
// Define a few SPI0 registers we need access to
|
||||
#define ESP8266_REG(addr) *((volatile uint32_t *)(0x60000000+(addr)))
|
||||
#define SPI0CMD ESP8266_REG(0x200)
|
||||
#define SPI0CLK ESP8266_REG(0x218)
|
||||
#define SPI0C ESP8266_REG(0x208)
|
||||
#define SPI0W0 ESP8266_REG(0x240)
|
||||
|
||||
#define SPICMDRDID (1 << 28)
|
||||
|
||||
/* spi_flash_get_id()
|
||||
Returns the flash chip ID - same as the SDK function.
|
||||
We need our own version as the SDK isn't available here.
|
||||
*/
|
||||
uint32_t __attribute__((noinline)) spi_flash_get_id() {
|
||||
SPI0W0=0;
|
||||
SPI0CMD=SPICMDRDID;
|
||||
while (SPI0CMD) {}
|
||||
return SPI0W0;
|
||||
}
|
||||
#endif // XMC_SUPPORT
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -211,9 +234,48 @@ int main()
|
||||
|
||||
if (cmd.action == ACTION_COPY_RAW) {
|
||||
ets_putc('c'); ets_putc('p'); ets_putc(':');
|
||||
|
||||
#ifdef XMC_SUPPORT
|
||||
// save the flash access speed registers
|
||||
uint32_t spi0clk = SPI0CLK;
|
||||
uint32_t spi0c = SPI0C;
|
||||
|
||||
uint32_t vendor = spi_flash_get_id() & 0x000000ff;
|
||||
if (vendor == SPI_FLASH_VENDOR_XMC) {
|
||||
uint32_t flashinfo=0;
|
||||
if (SPIRead(0, &flashinfo, 4)) {
|
||||
// failed to read the configured flash speed.
|
||||
// Do not change anything,
|
||||
} else {
|
||||
// select an appropriate flash speed
|
||||
// Register values are those used by ROM
|
||||
switch ((flashinfo >> 24) & 0x0f) {
|
||||
case 0x0: // 40MHz, slow to 20
|
||||
case 0x1: // 26MHz, slow to 20
|
||||
SPI0CLK = 0x00003043;
|
||||
SPI0C = 0x00EAA313;
|
||||
break;
|
||||
case 0x2: // 20MHz, no change
|
||||
break;
|
||||
case 0xf: // 80MHz, slow to 26
|
||||
SPI0CLK = 0x00002002;
|
||||
SPI0C = 0x00EAA202;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // XMC_SUPPORT
|
||||
ets_wdt_disable();
|
||||
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2]);
|
||||
ets_wdt_enable();
|
||||
|
||||
#ifdef XMC_SUPPORT
|
||||
// restore the saved flash access speed registers
|
||||
SPI0CLK = spi0clk;
|
||||
SPI0C = spi0c;
|
||||
#endif
|
||||
ets_putc('0'+res); ets_putc('\n');
|
||||
if (res == 0) {
|
||||
cmd.action = ACTION_LOAD_APP;
|
||||
|
Binary file not shown.
63
bootloaders/eboot/spi_vendors.h
Normal file
63
bootloaders/eboot/spi_vendors.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
spi_vendors.h - Vendor IDs for SPI chips
|
||||
Copyright (c) 2019 Mike Nix. All rights reserved.
|
||||
This file is part of the esp8266 core for Arduino environment.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef __SPI_VENDORS_H__
|
||||
#define __SPI_VENDORS_H__
|
||||
|
||||
// Vendor IDs taken from Flashrom project
|
||||
// https://review.coreboot.org/cgit/flashrom.git/tree/flashchips.h?h=1.0.x
|
||||
// Moved here from ../../cores/esp8266/Esp.h
|
||||
typedef enum {
|
||||
SPI_FLASH_VENDOR_ALLIANCE = 0x52, /* Alliance Semiconductor */
|
||||
SPI_FLASH_VENDOR_AMD = 0x01, /* AMD */
|
||||
SPI_FLASH_VENDOR_AMIC = 0x37, /* AMIC */
|
||||
SPI_FLASH_VENDOR_ATMEL = 0x1F, /* Atmel (now used by Adesto) */
|
||||
SPI_FLASH_VENDOR_BRIGHT = 0xAD, /* Bright Microelectronics */
|
||||
SPI_FLASH_VENDOR_CATALYST = 0x31, /* Catalyst */
|
||||
SPI_FLASH_VENDOR_EON = 0x1C, /* EON Silicon Devices, missing 0x7F prefix */
|
||||
SPI_FLASH_VENDOR_ESMT = 0x8C, /* Elite Semiconductor Memory Technology (ESMT) / EFST Elite Flash Storage */
|
||||
SPI_FLASH_VENDOR_EXCEL = 0x4A, /* ESI, missing 0x7F prefix */
|
||||
SPI_FLASH_VENDOR_FIDELIX = 0xF8, /* Fidelix */
|
||||
SPI_FLASH_VENDOR_FUJITSU = 0x04, /* Fujitsu */
|
||||
SPI_FLASH_VENDOR_GIGADEVICE = 0xC8, /* GigaDevice */
|
||||
SPI_FLASH_VENDOR_HYUNDAI = 0xAD, /* Hyundai */
|
||||
SPI_FLASH_VENDOR_INTEL = 0x89, /* Intel */
|
||||
SPI_FLASH_VENDOR_ISSI = 0xD5, /* ISSI Integrated Silicon Solutions, see also PMC. */
|
||||
SPI_FLASH_VENDOR_MACRONIX = 0xC2, /* Macronix (MX) */
|
||||
SPI_FLASH_VENDOR_NANTRONICS = 0xD5, /* Nantronics, missing prefix */
|
||||
SPI_FLASH_VENDOR_PMC = 0x9D, /* PMC, missing 0x7F prefix */
|
||||
SPI_FLASH_VENDOR_PUYA = 0x85, /* Puya semiconductor (shanghai) co. ltd */
|
||||
SPI_FLASH_VENDOR_SANYO = 0x62, /* Sanyo */
|
||||
SPI_FLASH_VENDOR_SHARP = 0xB0, /* Sharp */
|
||||
SPI_FLASH_VENDOR_SPANSION = 0x01, /* Spansion, same ID as AMD */
|
||||
SPI_FLASH_VENDOR_SST = 0xBF, /* SST */
|
||||
SPI_FLASH_VENDOR_ST = 0x20, /* ST / SGS/Thomson / Numonyx (later acquired by Micron) */
|
||||
SPI_FLASH_VENDOR_SYNCMOS_MVC = 0x40, /* SyncMOS (SM) and Mosel Vitelic Corporation (MVC) */
|
||||
SPI_FLASH_VENDOR_TENX = 0x5E, /* Tenx Technologies */
|
||||
SPI_FLASH_VENDOR_TI = 0x97, /* Texas Instruments */
|
||||
SPI_FLASH_VENDOR_TI_OLD = 0x01, /* TI chips from last century */
|
||||
SPI_FLASH_VENDOR_WINBOND = 0xDA, /* Winbond */
|
||||
SPI_FLASH_VENDOR_WINBOND_NEX = 0xEF, /* Winbond (ex Nexcom) serial flashes */
|
||||
SPI_FLASH_VENDOR_XMC = 0x20, /* Wuhan Xinxin Semiconductor Manufacturing Corp */
|
||||
|
||||
SPI_FLASH_VENDOR_UNKNOWN = 0xFF
|
||||
} SPI_FLASH_VENDOR_t;
|
||||
|
||||
#endif // __SPI_VENDORS_H__
|
Reference in New Issue
Block a user