Skip to content

Commit 5ab5722

Browse files
committed
Cleanup for GCC macros and CMSE non-secure callable function macros
1 parent d93b1d2 commit 5ab5722

File tree

8 files changed

+166
-164
lines changed

8 files changed

+166
-164
lines changed

include/image.h

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -42,65 +42,6 @@ extern "C" {
4242
#include "encrypt.h"
4343
#endif
4444

45-
46-
int wolfBot_get_dts_size(void *dts_addr);
47-
48-
49-
#ifndef RAMFUNCTION
50-
#if defined(__WOLFBOOT) && defined(RAM_CODE)
51-
# if defined(ARCH_ARM)
52-
# define RAMFUNCTION __attribute__((used,section(".ramcode"),long_call))
53-
# else
54-
# define RAMFUNCTION __attribute__((used,section(".ramcode")))
55-
# endif
56-
#else
57-
# define RAMFUNCTION
58-
#endif
59-
#endif
60-
61-
#ifndef WEAKFUNCTION
62-
# if defined(__GNUC__) || defined(__CC_ARM)
63-
# define WEAKFUNCTION __attribute__((weak))
64-
# else
65-
# define WEAKFUNCTION
66-
# endif
67-
#endif
68-
69-
#ifndef UNUSEDFUNCTION
70-
# if defined(__GNUC__) || defined(__CC_ARM)
71-
# define UNUSEDFUNCTION __attribute__((unused))
72-
# else
73-
# define UNUSEDFUNCTION
74-
# endif
75-
#endif
76-
77-
78-
/* Helpers for memory alignment */
79-
#ifndef XALIGNED
80-
#if defined(__GNUC__) || defined(__llvm__) || \
81-
defined(__IAR_SYSTEMS_ICC__)
82-
#define XALIGNED(x) __attribute__ ( (aligned (x)))
83-
#elif defined(__KEIL__)
84-
#define XALIGNED(x) __align(x)
85-
#elif defined(_MSC_VER)
86-
/* disable align warning, we want alignment ! */
87-
#pragma warning(disable: 4324)
88-
#define XALIGNED(x) __declspec (align (x))
89-
#else
90-
#define XALIGNED(x) /* null expansion */
91-
#endif
92-
#endif
93-
94-
#ifndef XALIGNED_STACK
95-
/* Don't enforce stack alignment on IAR */
96-
#if defined (__IAR_SYSTEMS_ICC__)
97-
#define XALIGNED_STACK(x)
98-
#else
99-
#define XALIGNED_STACK(x) XALIGNED(x)
100-
#endif
101-
#endif
102-
103-
10445
#ifndef WOLFBOOT_FLAGS_INVERT
10546
#define SECT_FLAG_NEW 0x0F
10647
#define SECT_FLAG_SWAPPING 0x07

include/tpm.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ void wolfBoot_tpm2_deinit(void);
5555
int wolfBoot_tpm2_clear(void);
5656

5757
/* API's that are callable from non-secure code */
58-
int __attribute__((cmse_nonsecure_entry)) wolfBoot_tpm2_caps(WOLFTPM2_CAPS* caps);
59-
int __attribute__((cmse_nonsecure_entry)) wolfBoot_tpm2_get_handles(TPM_HANDLE handle, TPML_HANDLE* handles);
60-
const char* __attribute__((cmse_nonsecure_entry)) wolfBoot_tpm2_get_alg_name(TPM_ALG_ID alg);
61-
const char* __attribute__((cmse_nonsecure_entry)) wolfBoot_tpm2_get_rc_string(int rc);
62-
TPM_RC __attribute__((cmse_nonsecure_entry)) wolfBoot_tpm2_get_capability(GetCapability_In* in, GetCapability_Out* out);
58+
int CSME_NSE_API wolfBoot_tpm2_caps(WOLFTPM2_CAPS* caps);
59+
int CSME_NSE_API wolfBoot_tpm2_get_handles(TPM_HANDLE handle, TPML_HANDLE* handles);
60+
const char* CSME_NSE_API wolfBoot_tpm2_get_alg_name(TPM_ALG_ID alg);
61+
const char* CSME_NSE_API wolfBoot_tpm2_get_rc_string(int rc);
62+
TPM_RC CSME_NSE_API wolfBoot_tpm2_get_capability(GetCapability_In* in, GetCapability_Out* out);
6363

6464
#if defined(WOLFBOOT_TPM_VERIFY) || defined(WOLFBOOT_TPM_SEAL)
6565
int wolfBoot_load_pubkey(const uint8_t* pubkey_hint, WOLFTPM2_KEY* pubKey,

include/wolfboot/wc_secure.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828

2929
/* Data types shared between wolfBoot and the non-secure application */
3030

31+
#ifndef CSME_NSE_API
32+
# if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
33+
# define CSME_NSE_API __attribute__((cmse_nonsecure_entry))
34+
# else
35+
# define CSME_NSE_API
36+
# endif
37+
#endif
38+
3139
#ifdef WOLFCRYPT_SECURE_MODE
3240
struct wcs_sign_call_params
3341
{
@@ -52,36 +60,35 @@ struct wcs_verify_call_params
5260

5361
#ifdef WOLFBOOT_SECURE_CALLS
5462

55-
5663
/* Secure calls prototypes for the non-secure world */
5764

5865
/* RAW file read */
59-
int __attribute__((cmse_nonsecure_entry)) wcs_slot_read(int slot_id,
66+
int CSME_NSE_API wcs_slot_read(int slot_id,
6067
uint8_t *buffer, uint32_t len);
6168

6269

6370

6471
/* ECC */
65-
int __attribute__((cmse_nonsecure_entry)) wcs_ecc_import_public(int ecc_curve,
72+
int CSME_NSE_API wcs_ecc_import_public(int ecc_curve,
6673
uint8_t *pubkey, uint32_t key_size);
6774

68-
int __attribute__((cmse_nonsecure_entry)) wcs_ecc_keygen(uint32_t key_size,
75+
int CSME_NSE_API wcs_ecc_keygen(uint32_t key_size,
6976
int ecc_curve);
7077

71-
int __attribute__((cmse_nonsecure_entry)) wcs_ecc_getpublic(int slot_id,
78+
int CSME_NSE_API wcs_ecc_getpublic(int slot_id,
7279
uint8_t *pubkey, uint32_t *pubkeySz);
7380

74-
int __attribute__((cmse_nonsecure_entry)) wcs_ecdh_shared(int privkey_slot_id,
81+
int CSME_NSE_API wcs_ecdh_shared(int privkey_slot_id,
7582
int pubkey_slot_id, uint32_t outlen);
7683

7784
/* ECC Calls with wrapper for arguments (ABI only allows 4 arguments) */
78-
int __attribute__((cmse_nonsecure_entry))
85+
int CSME_NSE_API
7986
wcs_ecc_sign_call(struct wcs_sign_call_params *p);
80-
int __attribute__((cmse_nonsecure_entry))
87+
int CSME_NSE_API
8188
wcs_ecc_verify_call(struct wcs_verify_call_params *p);
8289

8390
/* RNG */
84-
int __attribute__((cmse_nonsecure_entry)) wcs_get_random(uint8_t *rand,
91+
int CSME_NSE_API wcs_get_random(uint8_t *rand,
8592
uint32_t size);
8693

8794
/* exposed API for sign/verify with all needed arguments */

include/wolfboot/wolfboot.h

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,61 @@ extern "C" {
3434
#include "target.h"
3535
#endif
3636
#include "wolfboot/version.h"
37-
38-
#ifdef WOLFCRYPT_SECURE_MODE
3937
#include "wolfboot/wc_secure.h"
38+
39+
40+
#ifndef RAMFUNCTION
41+
#if defined(__WOLFBOOT) && defined(RAM_CODE)
42+
# if defined(ARCH_ARM)
43+
# define RAMFUNCTION __attribute__((used,section(".ramcode"),long_call))
44+
# else
45+
# define RAMFUNCTION __attribute__((used,section(".ramcode")))
46+
# endif
47+
#else
48+
# define RAMFUNCTION
49+
#endif
50+
#endif
51+
52+
#ifndef WEAKFUNCTION
53+
# if defined(__GNUC__) || defined(__CC_ARM)
54+
# define WEAKFUNCTION __attribute__((weak))
55+
# else
56+
# define WEAKFUNCTION
57+
# endif
58+
#endif
59+
60+
#ifndef UNUSEDFUNCTION
61+
# if defined(__GNUC__) || defined(__CC_ARM)
62+
# define UNUSEDFUNCTION __attribute__((unused))
63+
# else
64+
# define UNUSEDFUNCTION
65+
# endif
66+
#endif
67+
68+
69+
/* Helpers for memory alignment */
70+
#ifndef XALIGNED
71+
#if defined(__GNUC__) || defined(__llvm__) || \
72+
defined(__IAR_SYSTEMS_ICC__)
73+
#define XALIGNED(x) __attribute__ ( (aligned (x)))
74+
#elif defined(__KEIL__)
75+
#define XALIGNED(x) __align(x)
76+
#elif defined(_MSC_VER)
77+
/* disable align warning, we want alignment ! */
78+
#pragma warning(disable: 4324)
79+
#define XALIGNED(x) __declspec (align (x))
80+
#else
81+
#define XALIGNED(x) /* null expansion */
82+
#endif
83+
#endif
84+
85+
#ifndef XALIGNED_STACK
86+
/* Don't enforce stack alignment on IAR */
87+
#if defined (__IAR_SYSTEMS_ICC__)
88+
#define XALIGNED_STACK(x)
89+
#else
90+
#define XALIGNED_STACK(x) XALIGNED(x)
91+
#endif
4092
#endif
4193

4294

@@ -420,36 +472,36 @@ int wolfBoot_erase_encrypt_key(void);
420472
*/
421473

422474
/* Call wolfBoot_success from non-secure application */
423-
__attribute__((cmse_nonsecure_entry))
475+
CSME_NSE_API
424476
void wolfBoot_nsc_success(void);
425477

426478
/* Call wolfBoot_update_trigger from non-secure application */
427-
__attribute__((cmse_nonsecure_entry))
479+
CSME_NSE_API
428480
void wolfBoot_nsc_update_trigger(void);
429481

430482
/* Call wolfBoot_get_image_version from non-secure application */
431-
__attribute__((cmse_nonsecure_entry))
483+
CSME_NSE_API
432484
uint32_t wolfBoot_nsc_get_image_version(uint8_t part);
433485
#define wolfBoot_nsc_current_firmware_version() wolfBoot_nsc_get_image_version(PART_BOOT)
434486
#define wolfBoot_nsc_update_firmware_version() wolfBoot_nsc_get_image_version(PART_UPDATE)
435487

436488
/* Call wolfBoot_get_partition_state from non-secure application */
437-
__attribute__((cmse_nonsecure_entry))
489+
CSME_NSE_API
438490
int wolfBoot_nsc_get_partition_state(uint8_t part, uint8_t *st);
439491

440492
/* Erase one or more sectors in the update partition.
441493
* - address: offset within the update partition ('0' corresponds to PARTITION_UPDATE_ADDRESS)
442494
* - len: size, in bytes
443495
*/
444-
__attribute__((cmse_nonsecure_entry))
496+
CSME_NSE_API
445497
int wolfBoot_nsc_erase_update(uint32_t address, uint32_t len);
446498

447499
/* Write the content of buffer `buf` and size `len` to the update partition,
448500
* at offset address, from non-secure application
449501
* - address: offset within the update partition ('0' corresponds to PARTITION_UPDATE_ADDRESS)
450502
* - len: size, in bytes
451503
*/
452-
__attribute__((cmse_nonsecure_entry))
504+
CSME_NSE_API
453505
int wolfBoot_nsc_write_update(uint32_t address, const uint8_t *buf, uint32_t len);
454506

455507
#endif /* !__WOLFBOOT && WOLFCRYPT_SECURE_MODE */

src/libwolfboot.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,31 +2039,31 @@ int wolfBoot_ram_decrypt(uint8_t *src, uint8_t *dst)
20392039
#endif /* EXT_ENCRYPTED */
20402040

20412041
#if defined(__WOLFBOOT) && defined(WOLFCRYPT_SECURE_MODE)
2042-
__attribute__((cmse_nonsecure_entry))
2042+
CSME_NSE_API
20432043
void wolfBoot_nsc_success(void)
20442044
{
20452045
wolfBoot_success();
20462046
}
20472047

2048-
__attribute__((cmse_nonsecure_entry))
2048+
CSME_NSE_API
20492049
void wolfBoot_nsc_update_trigger(void)
20502050
{
20512051
wolfBoot_update_trigger();
20522052
}
20532053

2054-
__attribute__((cmse_nonsecure_entry))
2054+
CSME_NSE_API
20552055
uint32_t wolfBoot_nsc_get_image_version(uint8_t part)
20562056
{
20572057
return wolfBoot_get_image_version(part);
20582058
}
20592059

2060-
__attribute__((cmse_nonsecure_entry))
2060+
CSME_NSE_API
20612061
int wolfBoot_nsc_get_partition_state(uint8_t part, uint8_t *st)
20622062
{
20632063
return wolfBoot_get_partition_state(part, st);
20642064
}
20652065

2066-
__attribute__((cmse_nonsecure_entry))
2066+
CSME_NSE_API
20672067
int wolfBoot_nsc_erase_update(uint32_t address, uint32_t len)
20682068
{
20692069
int ret;
@@ -2079,7 +2079,7 @@ int wolfBoot_nsc_erase_update(uint32_t address, uint32_t len)
20792079
return ret;
20802080
}
20812081

2082-
__attribute__((cmse_nonsecure_entry))
2082+
CSME_NSE_API
20832083
int wolfBoot_nsc_write_update(uint32_t address, const uint8_t *buf, uint32_t len)
20842084
{
20852085
int ret;
@@ -2088,7 +2088,7 @@ int wolfBoot_nsc_write_update(uint32_t address, const uint8_t *buf, uint32_t len
20882088
return -1;
20892089
if (address + len > WOLFBOOT_PARTITION_SIZE)
20902090
return -1;
2091-
2091+
20922092
hal_flash_unlock();
20932093
ret = hal_flash_write(address + WOLFBOOT_PARTITION_UPDATE_ADDRESS, buf, len);
20942094
hal_flash_lock();

0 commit comments

Comments
 (0)