summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorEvan Lojewski <github@meklort.com>2020-10-03 11:21:45 -0600
committerGitHub <noreply@github.com>2020-10-03 11:21:45 -0600
commit1a2a285a00d5cb7476f33ddaa83e8a91112f7329 (patch)
treee7f2981eafef54377cf8941bececf9c29681dadd /libs
parent93e2cd20348d46d51cb6cab5353962afeb1a22c6 (diff)
downloadbcm5719-ortega-1a2a285a00d5cb7476f33ddaa83e8a91112f7329.tar.gz
bcm5719-ortega-1a2a285a00d5cb7476f33ddaa83e8a91112f7329.zip
NVM: Add an API to determine the NVM size. (#124)
Diffstat (limited to 'libs')
-rw-r--r--libs/NVRam/include/NVRam.h2
-rw-r--r--libs/NVRam/nvm.c27
2 files changed, 28 insertions, 1 deletions
diff --git a/libs/NVRam/include/NVRam.h b/libs/NVRam/include/NVRam.h
index 919aeb7..5ec5b5f 100644
--- a/libs/NVRam/include/NVRam.h
+++ b/libs/NVRam/include/NVRam.h
@@ -61,6 +61,8 @@ void NVRam_enableWrites(void);
void NVRam_disable(void);
void NVRam_disableWrites(void);
+uint32_t NVRam_size(void);
+
uint32_t NVRam_crc(const uint8_t *pcDatabuf, // Pointer to data buffer
uint32_t ulDatalen, // Length of data buffer in bytes
uint32_t crc); // Initial value
diff --git a/libs/NVRam/nvm.c b/libs/NVRam/nvm.c
index 1e4d0cb..e3c33ba 100644
--- a/libs/NVRam/nvm.c
+++ b/libs/NVRam/nvm.c
@@ -45,6 +45,8 @@
#include <NVRam.h>
+#define BCM_NVRAM_MAGIC (0x669955AAu)
+
#define ATMEL_AT45DB0X1B_PAGE_POS (9u)
#define ATMEL_AT45DB0X1B_PAGE_SIZE (264u)
#define ATMEL_AT45DB0X1B_ERASE (false)
@@ -90,7 +92,7 @@ static inline uint32_t NVRam_translate(uint32_t address)
}
else
{
- return address;
+ return address;
}
#else
return address;
@@ -323,3 +325,26 @@ void NVRam_write(uint32_t address, uint32_t *buffer, uint32_t words)
}
#endif
}
+
+uint32_t NVRam_size(void)
+{
+ size_t size;
+ uint32_t magic = NVRam_readWord(0);
+
+ if (magic != htonl(BCM_NVRAM_MAGIC))
+ {
+ // Unable to determine the size.
+ return 0;
+ }
+
+ // Scan for the magic wrapping around, starting at 2KB flash size.
+ size = 2u * 1024u;
+ do
+ {
+ size *= 2;
+
+ magic = NVRam_readWord(size);
+ } while (magic != htonl(BCM_NVRAM_MAGIC));
+
+ return size;
+}
OpenPOWER on IntegriCloud