@@ -98,6 +98,16 @@ uint16_t wolfBoot_find_header(uint8_t *haystack, uint16_t type, uint8_t **ptr);
9898# define PART_IS_EXT (x ) PARTN_IS_EXT(((x)->part))
9999#include "hal.h"
100100
101+
102+ #ifdef EXT_ENCRYPTED
103+ #include "encrypt.h"
104+ #define ext_flash_check_write ext_flash_encrypt_write
105+ #define ext_flash_check_read ext_flash_decrypt_read
106+ #else
107+ #define ext_flash_check_write ext_flash_write
108+ #define ext_flash_check_read ext_flash_read
109+ #endif
110+
101111static inline int wb_flash_erase (struct wolfBoot_image * img , uint32_t off , uint32_t size )
102112{
103113 if (PART_IS_EXT (img ))
@@ -109,7 +119,7 @@ static inline int wb_flash_erase(struct wolfBoot_image *img, uint32_t off, uint3
109119static inline int wb_flash_write (struct wolfBoot_image * img , uint32_t off , const void * data , uint32_t size )
110120{
111121 if (PART_IS_EXT (img ))
112- return ext_flash_write ((uintptr_t )(img -> hdr ) + off , data , size );
122+ return ext_flash_check_write ((uintptr_t )(img -> hdr ) + off , data , size );
113123 else
114124 return hal_flash_write ((uintptr_t )(img -> hdr ) + off , data , size );
115125}
@@ -120,12 +130,12 @@ static inline int wb_flash_write_verify_word(struct wolfBoot_image *img, uint32_
120130 volatile uint32_t copy ;
121131 if (PART_IS_EXT (img ))
122132 {
123- ext_flash_read ((uintptr_t )(img -> hdr ) + off , (void * )& copy , sizeof (uint32_t ));
133+ ext_flash_check_read ((uintptr_t )(img -> hdr ) + off , (void * )& copy , sizeof (uint32_t ));
124134 while (copy != word ) {
125- ret = ext_flash_write ((uintptr_t )(img -> hdr ) + off , (void * )& word , sizeof (uint32_t ));
135+ ret = ext_flash_check_write ((uintptr_t )(img -> hdr ) + off , (void * )& word , sizeof (uint32_t ));
126136 if (ret < 0 )
127137 return ret ;
128- ext_flash_read ((uintptr_t )(img -> hdr ) + off , (void * )& copy , sizeof (uint32_t ));
138+ ext_flash_check_read ((uintptr_t )(img -> hdr ) + off , (void * )& copy , sizeof (uint32_t ));
129139 }
130140 } else {
131141 volatile uint32_t * pcopy = (volatile uint32_t * )(img -> hdr + off );
@@ -154,5 +164,11 @@ static inline int wb_flash_write_verify_word(struct wolfBoot_image *img, uint32_
154164/* --- Flattened Device Tree Blob */
155165#define UBOOT_FDT_MAGIC 0xEDFE0DD0UL
156166
167+ #ifndef EXT_ENCRYPTED
168+ #define WOLFBOOT_MAX_SPACE (WOLFBOOT_PARTITION_SIZE - (TRAILER_SKIP + sizeof(uint32_t) + (WOLFBOOT_PARTITION_SIZE + 1 / (WOLFBOOT_SECTOR_SIZE * 8))))
169+ #else
170+ #include "encrypt.h"
171+ #define WOLFBOOT_MAX_SPACE (WOLFBOOT_PARTITION_SIZE - ENCRYPT_TMP_SECRET_OFFSET)
172+ #endif
157173
158174#endif /* !IMAGE_H */
0 commit comments