Change in ...osmocom-bb[master]: fw/flash: Read extended ID, expose API

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

steve-m gerrit-no-reply at lists.osmocom.org
Sun Aug 11 11:38:55 UTC 2019


steve-m has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/15151


Change subject: fw/flash: Read extended ID, expose API
......................................................................

fw/flash: Read extended ID, expose API

We now unlock the flash before reading the
extended ID (required for Spansion and Samsung
flash chips). These commands will be ignored
by Intel/ST flash chips, and this change has been
verified with all flash chips we support.

Furthermore, expose the API for reading the flash ID.

Change-Id: I3bcd71c84c8931bcd574953063737b51a41738a3
---
M src/target/firmware/flash/cfi_flash.c
M src/target/firmware/include/flash/cfi_flash.h
2 files changed, 36 insertions(+), 14 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/51/15151/1

diff --git a/src/target/firmware/flash/cfi_flash.c b/src/target/firmware/flash/cfi_flash.c
index 974165d..2f8cde0 100644
--- a/src/target/firmware/flash/cfi_flash.c
+++ b/src/target/firmware/flash/cfi_flash.c
@@ -69,12 +69,6 @@
 	struct cfi_region erase_regions[CFI_FLASH_MAX_ERASE_REGIONS];
 } __attribute__ ((packed));
 
-/* manufacturer ids */
-enum cfi_manuf {
-	CFI_MANUF_ST    = 0x0020,
-	CFI_MANUF_INTEL = 0x0089,
-};
-
 /* algorithm ids */
 enum cfi_algo {
 	CFI_ALGO_INTEL_3 = 0x03
@@ -83,6 +77,7 @@
 /* various command bytes */
 enum cfi_flash_cmd {
 	CFI_CMD_RESET = 0xff,
+	CFI_CMD_RESET_TO_READ_MODE = 0xF0,
 	CFI_CMD_READ_ID = 0x90,
 	CFI_CMD_CFI = 0x98,
 	CFI_CMD_READ_STATUS = 0x70,
@@ -91,6 +86,8 @@
 	CFI_CMD_BLOCK_ERASE = 0x20,
 	CFI_CMD_ERASE_CONFIRM = 0xD0,
 	CFI_CMD_PROTECT = 0x60,
+	CFI_CMD_UNLOCK1 = 0xAA,
+	CFI_CMD_UNLOCK2 = 0x55,
 };
 
 /* protection commands */
@@ -104,6 +101,8 @@
 enum flash_offset {
 	CFI_OFFSET_MANUFACTURER_ID = 0x00,
 	CFI_OFFSET_DEVICE_ID = 0x01,
+	CFI_OFFSET_EXT_DEVICE_ID1 = 0x0E,
+	CFI_OFFSET_EXT_DEVICE_ID2 = 0x0F,
 	CFI_OFFSET_INTEL_PROTECTION = 0x81,
 	CFI_OFFSET_CFI_RESP = 0x10
 };
@@ -125,6 +124,9 @@
 	CFI_STATUS_RESERVED = 0x01
 };
 
+#define CFI_CMD_ADDR1			0xAAA
+#define CFI_CMD_ADDR2			0x555
+
 __ramtext
 static inline void flash_write_cmd(const void *base_addr, uint16_t cmd)
 {
@@ -379,17 +381,27 @@
 	return res;
 }
 
-/* Internal: retrieve manufacturer and device id from id space */
+/* retrieve manufacturer and extended device id from id space */
 __ramtext
-static int get_id(void *base_addr,
+int flash_get_id(void *base_addr,
 		  uint16_t * manufacturer_id, uint16_t * device_id)
 {
-	flash_write_cmd(base_addr, CFI_CMD_READ_ID);
+	flash_write_cmd(base_addr, CFI_CMD_RESET_TO_READ_MODE);
 
-	*manufacturer_id = flash_read16(base_addr, CFI_OFFSET_MANUFACTURER_ID);
-	*device_id = flash_read16(base_addr, CFI_OFFSET_DEVICE_ID);
+	flash_write_cmd(base_addr + CFI_CMD_ADDR1, CFI_CMD_UNLOCK1);
+	flash_write_cmd(base_addr + CFI_CMD_ADDR2, CFI_CMD_UNLOCK2);
+	flash_write_cmd(base_addr + CFI_CMD_ADDR1, CFI_CMD_READ_ID);
 
-	flash_write_cmd(base_addr, CFI_CMD_RESET);
+	if (manufacturer_id)
+		*manufacturer_id = flash_read16(base_addr, CFI_OFFSET_MANUFACTURER_ID);
+
+	if (device_id) {
+		device_id[0] = flash_read16(base_addr, CFI_OFFSET_DEVICE_ID);
+		device_id[1] = flash_read16(base_addr, CFI_OFFSET_EXT_DEVICE_ID1);
+		device_id[2] = flash_read16(base_addr, CFI_OFFSET_EXT_DEVICE_ID2);
+	}
+
+	flash_write_cmd(base_addr, CFI_CMD_RESET_TO_READ_MODE);
 
 	return 0;
 }
@@ -524,12 +536,12 @@
 {
 	int res;
 	unsigned u;
-	uint16_t m_id, d_id;
+	uint16_t m_id, d_id[3];
 	uint32_t base;
 	struct cfi_query qry;
 
 	/* retrieve and check manufacturer and device id */
-	res = get_id(base_addr, &m_id, &d_id);
+	res = flash_get_id(base_addr, &m_id, d_id);
 	if (res) {
 		return res;
 	}
diff --git a/src/target/firmware/include/flash/cfi_flash.h b/src/target/firmware/include/flash/cfi_flash.h
index 9d8b33a..8589fb6 100644
--- a/src/target/firmware/include/flash/cfi_flash.h
+++ b/src/target/firmware/include/flash/cfi_flash.h
@@ -26,6 +26,14 @@
 	FLASH_LOCKED_DOWN
 } flash_lock_t;
 
+/* manufacturer ids */
+enum cfi_manuf {
+	CFI_MANUF_ST       = 0x0020,
+	CFI_MANUF_INTEL    = 0x0089,
+	CFI_MANUF_SPANSION = 0x0001,
+	CFI_MANUF_SAMSUNG  = 0x00EC,
+};
+
 int flash_init(flash_t *flash, void *base_addr);
 
 flash_lock_t flash_block_getlock(flash_t *flash, uint32_t block_offset);
@@ -38,4 +46,6 @@
 
 int flash_program(flash_t *flash, uint32_t dst_offset, void *src, uint32_t nbytes);
 
+int flash_get_id(void *base_addr, uint16_t * manufacturer_id, uint16_t * device_id);
+
 #endif

-- 
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/15151
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I3bcd71c84c8931bcd574953063737b51a41738a3
Gerrit-Change-Number: 15151
Gerrit-PatchSet: 1
Gerrit-Owner: steve-m <steve at steve-m.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190811/61355f34/attachment.htm>


More information about the gerrit-log mailing list