nanohub: firmware: add AOSP header support
1. Change the secure loading FSM to accept new header format
2. Add support for arbitrary flash relocation base
3. rearrange source tree
4. OS update BL API
5. Rework shared area management
6. Add key update with nanoapp image
7. Add OS update with nanoapp image
Bug: 28265099
Change-Id: I1710f46eb6abf0256cd25f834a01b559a79e9c99
Signed-off-by: Alexey Polyudov <[email protected]>
diff --git a/firmware/src/platform/stm32f4xx/bl.c b/firmware/src/platform/stm32f4xx/bl.c
index 61f5f90..ac2d4ec 100644
--- a/firmware/src/platform/stm32f4xx/bl.c
+++ b/firmware/src/platform/stm32f4xx/bl.c
@@ -16,17 +16,21 @@
#include <variant/inc/variant.h>
+
#include <plat/inc/cmsis.h>
#include <plat/inc/gpio.h>
#include <plat/inc/pwr.h>
#include <plat/inc/bl.h>
+
+#include <nanohub/sha2.h>
+#include <nanohub/aes.h>
+#include <nanohub/rsa.h>
+#include <nanohub/nanohub.h>
+
#include <printf.h>
#include <string.h>
#include <alloca.h>
#include <gpio.h>
-#include <sha2.h>
-#include <aes.h>
-#include <rsa.h>
static uint32_t blVerifyOsImage(const uint8_t *addr, struct OsUpdateHdr **start, uint32_t *size);
diff --git a/firmware/src/platform/stm32f4xx/crc.c b/firmware/src/platform/stm32f4xx/crc.c
index 8538cc5..771703d 100644
--- a/firmware/src/platform/stm32f4xx/crc.c
+++ b/firmware/src/platform/stm32f4xx/crc.c
@@ -16,7 +16,7 @@
#include <string.h>
-#include <crc.h>
+#include <nanohub/crc.h>
#include <seos.h>
#include <plat/inc/pwr.h>
diff --git a/firmware/src/platform/stm32f4xx/eeData.c b/firmware/src/platform/stm32f4xx/eeData.c
index bcd8893..906b9f3 100644
--- a/firmware/src/platform/stm32f4xx/eeData.c
+++ b/firmware/src/platform/stm32f4xx/eeData.c
@@ -20,7 +20,6 @@
#include <stdint.h>
#include <eeData.h>
-
extern uint32_t __eedata_start[], __eedata_end[];
//STM32F4xx eedata stores data in 4-byte aligned chunks
@@ -65,7 +64,7 @@
return name && name < EE_DATA_NAME_MAX;
}
-static bool eeDataGetEx(uint32_t name, uint32_t *offsetP, bool first, void *buf, uint32_t *szP)
+static void *eeDataGetEx(uint32_t name, uint32_t *offsetP, bool first, void *buf, uint32_t *szP)
{
uint32_t sz = 0;
void *data;
@@ -76,7 +75,7 @@
//find the data item
data = eeFind(name, offsetP, first, &sz);
if (!data)
- return false;
+ return NULL;
if (buf && szP) { //get the data
if (sz > *szP)
@@ -87,25 +86,22 @@
else if (szP) //get size
*szP = sz;
- return true;
+ return (uint32_t*)data - 1;
}
bool eeDataGet(uint32_t name, void *buf, uint32_t *szP)
{
uint32_t offset = 0;
- return eeDataGetEx(name, &offset, false, buf, szP);
+ return eeDataGetEx(name, &offset, false, buf, szP) != NULL;
}
-bool eeDataGetAllVersions(uint32_t name, void *buf, uint32_t *szP, void **stateP)
+void *eeDataGetAllVersions(uint32_t name, void *buf, uint32_t *szP, void **stateP)
{
uint32_t offset = *(uint32_t*)stateP;
- bool ret;
-
- ret = eeDataGetEx(name, &offset, true, buf, szP);
+ void *addr = eeDataGetEx(name, &offset, true, buf, szP);
*(uint32_t*)stateP = offset;
-
- return ret;
+ return addr;
}
static bool eeWrite(void *dst, const void *src, uint32_t len)
@@ -141,13 +137,17 @@
return ret;
}
-bool eeDataEraseOldVersion(uint32_t name, void *state)
+bool eeDataEraseOldVersion(uint32_t name, void *vaddr)
{
- uint32_t v = *(uint32_t*)state;
+ uint32_t *addr = (uint32_t*)vaddr;
+ uint32_t v;
- if (!eeIsValidName(name))
+ // sanity check
+ if (!eeIsValidName(name) || addr < __eedata_start || addr >= (__eedata_end - 1))
return false;
+ v = *addr;
+
//verify name
if ((v & EE_DATA_NAME_MAX) != name)
return false;
@@ -156,15 +156,5 @@
v &=~ EE_DATA_NAME_MAX;
//store result
- return eeWrite(state, &v, sizeof(v));
+ return eeWrite(addr, &v, sizeof(v));
}
-
-
-
-
-
-
-
-
-
-