Merge pull request #72 from xixijay1988/master

针对ENV添加大小端MCU的适配
This commit is contained in:
朱天龙 (Armink) 2019-09-04 16:50:42 +08:00 committed by GitHub
commit bda011569d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -40,6 +40,10 @@
* Please change it when your firmware add a new ENV to default_env_set.
*/
#define EF_ENV_VER_NUM /* @note you must define it for a value, such as 0 */
/* MCU Endian Configuration, default is Little Endian Order.
/* #define EF_BIG_ENDIAN */
#endif /* EF_USING_ENV */
/* using IAP function */

View File

@ -495,7 +495,11 @@ static uint32_t find_next_env_addr(uint32_t start, uint32_t end)
for (; start < end; start += (sizeof(buf) - sizeof(uint32_t))) {
ef_port_read(start, (uint32_t *) buf, sizeof(buf));
for (i = 0; i < sizeof(buf) - sizeof(uint32_t) && start + i < end; i++) {
#ifndef EF_BIG_ENDIAN /* Little Endian Order */
magic = buf[i] + (buf[i + 1] << 8) + (buf[i + 2] << 16) + (buf[i + 3] << 24);
#else // Big Endian Order
magic = buf[i + 3] + (buf[i + 2] << 8) + (buf[i + 1] << 16) + (buf[i] << 24);
#endif
if (magic == ENV_MAGIC_WORD && (start + i - ENV_MAGIC_OFFSET) >= start_bak) {
return start + i - ENV_MAGIC_OFFSET;
}