mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-17 02:52:12 +01:00
flash: verify JEDEC ID during flash init
Verify that the flash component on the board matches exactly what we're expecting. This is a simple way to verify that we are communicating properly with the JEDEC flash chip. Conflicts: flight/targets/board_hw_defs/freedom/board_hw_defs.c flight/targets/board_hw_defs/quanton/board_hw_defs.c
This commit is contained in:
parent
17b8696261
commit
b6eeb59b26
@ -49,8 +49,6 @@
|
||||
#define JEDEC_STATUS_SEC 0x40
|
||||
#define JEDEC_STATUS_SRP0 0x80
|
||||
|
||||
static uint8_t device_type;
|
||||
|
||||
enum pios_jedec_dev_magic {
|
||||
PIOS_JEDEC_DEV_MAGIC = 0xcb55aa55,
|
||||
};
|
||||
@ -60,8 +58,11 @@ struct jedec_flash_dev {
|
||||
uint32_t spi_id;
|
||||
uint32_t slave_num;
|
||||
bool claimed;
|
||||
uint32_t device_type;
|
||||
uint32_t capacity;
|
||||
|
||||
uint8_t manufacturer;
|
||||
uint8_t memorytype;
|
||||
uint8_t capacity;
|
||||
|
||||
const struct pios_flash_jedec_cfg * cfg;
|
||||
#if defined(FLASH_FREERTOS)
|
||||
xSemaphoreHandle transaction_lock;
|
||||
@ -124,9 +125,13 @@ int32_t PIOS_Flash_Jedec_Init(uintptr_t * flash_id, uint32_t spi_id, uint32_t sl
|
||||
flash_dev->slave_num = slave_num;
|
||||
flash_dev->cfg = cfg;
|
||||
|
||||
device_type = PIOS_Flash_Jedec_ReadID(flash_dev);
|
||||
if (device_type == 0)
|
||||
(void) PIOS_Flash_Jedec_ReadID(flash_dev);
|
||||
if ((flash_dev->manufacturer != flash_dev->cfg->expect_manufacturer) ||
|
||||
(flash_dev->memorytype != flash_dev->cfg->expect_memorytype) ||
|
||||
(flash_dev->capacity != flash_dev->cfg->expect_capacity)) {
|
||||
/* Mismatched device has been discovered */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Give back a handle to this flash device */
|
||||
*flash_id = (uintptr_t) flash_dev;
|
||||
@ -227,10 +232,11 @@ static int32_t PIOS_Flash_Jedec_ReadID(struct jedec_flash_dev * flash_dev)
|
||||
|
||||
PIOS_Flash_Jedec_ReleaseBus(flash_dev);
|
||||
|
||||
flash_dev->device_type = in[1];
|
||||
flash_dev->capacity = in[3];
|
||||
flash_dev->manufacturer = in[1];
|
||||
flash_dev->memorytype = in[2];
|
||||
flash_dev->capacity = in[3];
|
||||
|
||||
return in[1];
|
||||
return flash_dev->manufacturer;
|
||||
}
|
||||
|
||||
/**********************************
|
||||
|
@ -35,7 +35,14 @@
|
||||
|
||||
extern const struct pios_flash_driver pios_jedec_flash_driver;
|
||||
|
||||
#define JEDEC_MANUFACTURER_ST 0x20
|
||||
#define JEDEC_MANUFACTURER_MACRONIX 0xC2
|
||||
#define JEDEC_MANUFACTURER_WINBOND 0xEF
|
||||
|
||||
struct pios_flash_jedec_cfg {
|
||||
uint8_t expect_manufacturer;
|
||||
uint8_t expect_memorytype;
|
||||
uint8_t expect_capacity;
|
||||
uint32_t sector_erase;
|
||||
uint32_t chip_erase;
|
||||
};
|
||||
|
@ -415,8 +415,11 @@ static const struct flashfs_logfs_cfg flashfs_w25x_cfg = {
|
||||
};
|
||||
|
||||
static const struct pios_flash_jedec_cfg flash_w25x_cfg = {
|
||||
.sector_erase = 0x20,
|
||||
.chip_erase = 0x60
|
||||
.expect_manufacturer = JEDEC_MANUFACTURER_WINBOND,
|
||||
.expect_memorytype = 0x30,
|
||||
.expect_capacity = 0x13,
|
||||
.sector_erase = 0x20,
|
||||
.chip_erase = 0x60
|
||||
};
|
||||
|
||||
static const struct flashfs_logfs_cfg flashfs_m25p_cfg = {
|
||||
@ -431,8 +434,11 @@ static const struct flashfs_logfs_cfg flashfs_m25p_cfg = {
|
||||
};
|
||||
|
||||
static const struct pios_flash_jedec_cfg flash_m25p_cfg = {
|
||||
.sector_erase = 0xD8,
|
||||
.chip_erase = 0xC7
|
||||
.expect_manufacturer = JEDEC_MANUFACTURER_ST,
|
||||
.expect_memorytype = 0x20,
|
||||
.expect_capacity = 0x15,
|
||||
.sector_erase = 0xD8,
|
||||
.chip_erase = 0xC7,
|
||||
};
|
||||
|
||||
#include "pios_flash.h"
|
||||
|
@ -463,8 +463,11 @@ static const struct flashfs_logfs_cfg flashfs_m25p_cfg = {
|
||||
};
|
||||
|
||||
static const struct pios_flash_jedec_cfg flash_m25p_cfg = {
|
||||
.sector_erase = 0xD8,
|
||||
.chip_erase = 0xC7
|
||||
.expect_manufacturer = JEDEC_MANUFACTURER_ST,
|
||||
.expect_memorytype = 0x20,
|
||||
.expect_capacity = 0x15,
|
||||
.sector_erase = 0xD8,
|
||||
.chip_erase = 0xC7,
|
||||
};
|
||||
|
||||
#endif /* PIOS_INCLUDE_FLASH */
|
||||
|
@ -578,8 +578,11 @@ static const struct flashfs_logfs_cfg flashfs_m25p_cfg = {
|
||||
};
|
||||
|
||||
static const struct pios_flash_jedec_cfg flash_m25p_cfg = {
|
||||
.sector_erase = 0xD8,
|
||||
.chip_erase = 0xC7
|
||||
.expect_manufacturer = JEDEC_MANUFACTURER_ST,
|
||||
.expect_memorytype = 0x20,
|
||||
.expect_capacity = 0x15,
|
||||
.sector_erase = 0xD8,
|
||||
.chip_erase = 0xC7,
|
||||
};
|
||||
|
||||
#endif /* PIOS_INCLUDE_FLASH */
|
||||
|
Loading…
x
Reference in New Issue
Block a user