Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NUC472/M453: Fix several startup and hal bugs #4832

Merged
merged 12 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* mbed Microcontroller Library
* Copyright (c) 2015-2016 Nuvoton
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBEDTLS_DEVICE_H
#define MBEDTLS_DEVICE_H

#define MBEDTLS_DES_ALT

#define MBEDTLS_SHA1_ALT
#define MBEDTLS_SHA256_ALT

#define MBEDTLS_AES_ALT
#define MBEDTLS_AES_SETKEY_ENC_ALT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if MBEDTLS_AES_ALT is defined, no need to define other Alternative configuration for AES, as MBEDTLS_AES_ALT defines alternative implementation for the whole module

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RonEld I fixed it. Please check another PR 63e4fb8.

#define MBEDTLS_AES_SETKEY_DEC_ALT
#define MBEDTLS_AES_ENCRYPT_ALT
#define MBEDTLS_AES_DECRYPT_ALT

#endif /* MBEDTLS_DEVICE_H */
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
* http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
*/

/* Compatible with mbed OS 2 which doesn't support mbedtls */
#if MBED_CONF_RTOS_PRESENT

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
Expand Down Expand Up @@ -591,5 +588,3 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,


#endif /* MBEDTLS_AES_C */

#endif /* MBED_CONF_RTOS_PRESENT */
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
* This file is part of mbed TLS (https://tls.mbed.org)
*/

#ifndef MBEDTLS_AES_ALT_H
#define MBEDTLS_AES_ALT_H

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif

#if defined(MBEDTLS_AES_C)
#if defined(MBEDTLS_AES_ALT)
// Regular implementation
//
Expand Down Expand Up @@ -270,5 +280,6 @@ void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,


#endif /* MBEDTLS_AES_ALT */
#endif /* MBEDTLS_AES_C */


#endif /* aes_alt.h */
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
* limitations under the License.
*/

/* Compatible with mbed OS 2 which doesn't support mbedtls */
#if MBED_CONF_RTOS_PRESENT

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
Expand Down Expand Up @@ -348,7 +345,7 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S

uint32_t rmn = length;
const unsigned char *in_pos = input;
const unsigned char *out_pos = output;
unsigned char *out_pos = output;

while (rmn) {
uint32_t data_len = (rmn <= MAXSIZE_DMABUF) ? rmn : MAXSIZE_DMABUF;
Expand Down Expand Up @@ -411,5 +408,3 @@ static int mbedtls_des_docrypt(uint16_t keyopt, uint8_t key[3][MBEDTLS_DES_KEY_S

#endif /* MBEDTLS_DES_ALT */
#endif /* MBEDTLS_DES_C */

#endif /* MBED_CONF_RTOS_PRESENT */
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include MBEDTLS_CONFIG_FILE
#endif

#if defined(MBEDTLS_DES_C)
#if defined(MBEDTLS_DES_ALT)

#include <stddef.h>
Expand Down Expand Up @@ -276,5 +277,6 @@ void mbedtls_des_setkey( uint32_t SK[32],
#endif

#endif /* MBEDTLS_DES_ALT */
#endif /* MBEDTLS_DES_C */

#endif /* des_alt.h */
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
* http://csrc.nist.gov/publications/fips/fips46-3/fips46-3.pdf
*/

/* Compatible with mbed OS 2 which doesn't support mbedtls */
#if MBED_CONF_RTOS_PRESENT

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
Expand Down Expand Up @@ -798,5 +795,3 @@ int mbedtls_des3_sw_crypt_cbc( mbedtls_des3_sw_context *ctx,

#endif /* MBEDTLS_DES_ALT */
#endif /* MBEDTLS_DES_C */

#endif /* MBED_CONF_RTOS_PRESENT */
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
* limitations under the License.
*/

/* Compatible with mbed OS 2 which doesn't support mbedtls */
#if MBED_CONF_RTOS_PRESENT

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
Expand Down Expand Up @@ -139,5 +136,3 @@ void mbedtls_sha1_process(mbedtls_sha1_context *ctx, const unsigned char data[64

#endif /* MBEDTLS_SHA1_ALT */
#endif /* MBEDTLS_SHA1_C */

#endif /* MBED_CONF_RTOS_PRESENT */
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
* http://www.itl.nist.gov/fipspubs/fip180-1.htm
*/

/* Compatible with mbed OS 2 which doesn't support mbedtls */
#if MBED_CONF_RTOS_PRESENT

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
Expand Down Expand Up @@ -346,5 +343,3 @@ void mbedtls_sha1_sw_finish( mbedtls_sha1_sw_context *ctx, unsigned char output[
#endif /* MBEDTLS_SHA1_ALT */

#endif /* MBEDTLS_SHA1_C */

#endif /* MBED_CONF_RTOS_PRESENT */
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
* limitations under the License.
*/

/* Compatible with mbed OS 2 which doesn't support mbedtls */
#if MBED_CONF_RTOS_PRESENT

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
Expand Down Expand Up @@ -140,5 +137,3 @@ void mbedtls_sha256_process(mbedtls_sha256_context *ctx, const unsigned char dat

#endif /* MBEDTLS_SHA256_ALT */
#endif /* MBEDTLS_SHA256_C */

#endif /* MBED_CONF_RTOS_PRESENT */
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
* http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf
*/

/* Compatible with mbed OS 2 which doesn't support mbedtls */
#if MBED_CONF_RTOS_PRESENT

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
Expand Down Expand Up @@ -320,5 +317,3 @@ void mbedtls_sha256_sw_finish( mbedtls_sha256_sw_context *ctx, unsigned char out
#endif /* MBEDTLS_SHA256_ALT */

#endif /* MBEDTLS_SHA256_C */

#endif /* MBED_CONF_RTOS_PRESENT */
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
* limitations under the License.
*/

/* Compatible with mbed OS 2 which doesn't support mbedtls */
#if MBED_CONF_RTOS_PRESENT

#if !defined(MBEDTLS_CONFIG_FILE)
#include "mbedtls/config.h"
#else
Expand Down Expand Up @@ -51,6 +48,7 @@ void crypto_sha_getinternstate(unsigned char output[], size_t olen);

#endif /* MBEDTLS_SHA1_ALT || MBEDTLS_SHA256_ALT || MBEDTLS_SHA512_ALT */

#if defined(MBEDTLS_SHA1_C)
#if defined(MBEDTLS_SHA1_ALT)

void mbedtls_sha1_hw_init(crypto_sha_context *ctx)
Expand Down Expand Up @@ -123,7 +121,9 @@ void mbedtls_sha1_hw_process(crypto_sha_context *ctx, const unsigned char data[6
}

#endif /* MBEDTLS_SHA1_ALT */
#endif /* MBEDTLS_SHA1_C */

#if defined(MBEDTLS_SHA256_C)
#if defined(MBEDTLS_SHA256_ALT)

void mbedtls_sha256_hw_init(crypto_sha_context *ctx)
Expand Down Expand Up @@ -197,7 +197,9 @@ void mbedtls_sha256_hw_process(crypto_sha_context *ctx, const unsigned char data
}

#endif /* MBEDTLS_SHA256_ALT */
#endif /* MBEDTLS_SHA256_C */

#if defined(MBEDTLS_SHA1_C) || defined(MBEDTLS_SHA256_C) || defined(MBEDTLS_SHA512_C)
#if defined(MBEDTLS_SHA1_ALT) || defined(MBEDTLS_SHA256_ALT) || defined(MBEDTLS_SHA512_ALT)

void crypto_sha_update(crypto_sha_context *ctx, const unsigned char *input, size_t ilen)
Expand Down Expand Up @@ -332,7 +334,6 @@ void crypto_sha_getinternstate(unsigned char output[], size_t olen)
}

#endif /* MBEDTLS_SHA1_ALT || MBEDTLS_SHA256_ALT || MBEDTLS_SHA512_ALT */

#endif /* MBEDTLS_SHA1_C || MBEDTLS_SHA256_C || MBEDTLS_SHA512_C */

#endif /* MBED_CONF_RTOS_PRESENT */
#endif /* MBEDTLS_SHA1_C || MBEDTLS_SHA256_C || MBEDTLS_SHA512_C */
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#endif

#if defined(MBEDTLS_SHA1_C) || defined(MBEDTLS_SHA256_C) || defined(MBEDTLS_SHA512_C)
#if defined(MBEDTLS_SHA1_ALT) || defined(MBEDTLS_SHA256_ALT) || defined(MBEDTLS_SHA512_ALT)

#include <stddef.h>
#include <stdint.h>
Expand Down Expand Up @@ -50,6 +51,7 @@ void crypto_sha_update(crypto_sha_context *ctx, const unsigned char *input, size
void crypto_sha_update_nobuf(crypto_sha_context *ctx, const unsigned char *input, size_t ilen, int islast);
void crypto_sha_getinternstate(unsigned char output[], size_t olen);

#if defined(MBEDTLS_SHA1_C)
#if defined(MBEDTLS_SHA1_ALT)

void mbedtls_sha1_hw_init( crypto_sha_context *ctx );
Expand All @@ -62,7 +64,9 @@ void mbedtls_sha1_hw_finish( crypto_sha_context *ctx, unsigned char output[20] )
void mbedtls_sha1_hw_process( crypto_sha_context *ctx, const unsigned char data[64] );

#endif /* MBEDTLS_SHA1_ALT */
#endif /* MBEDTLS_SHA1_C */

#if defined(MBEDTLS_SHA256_C)
#if defined(MBEDTLS_SHA256_ALT)

void mbedtls_sha256_hw_init( crypto_sha_context *ctx );
Expand All @@ -76,11 +80,13 @@ void mbedtls_sha256_hw_finish( crypto_sha_context *ctx, unsigned char output[32]
void mbedtls_sha256_hw_process( crypto_sha_context *ctx, const unsigned char data[64] );

#endif /* MBEDTLS_SHA256_ALT */
#endif /* MBEDTLS_SHA256_C */

#ifdef __cplusplus
}
#endif

#endif /* MBEDTLS_SHA1_C || MBEDTLS_SHA256_C || MBEDTLS_SHA512_C*/
#endif /* MBEDTLS_SHA1_ALT || MBEDTLS_SHA256_ALT || MBEDTLS_SHA512_ALT */
#endif /* MBEDTLS_SHA1_C || MBEDTLS_SHA256_C || MBEDTLS_SHA512_C */

#endif /* sha_alt.h */
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ typedef enum {
LED1 = PD_2,
LED2 = PD_3,
LED3 = PD_7,
LED4 = D0, // No real LED. Just for passing ATS.
LED4 = LED1, // No real LED. Just for passing ATS.
LED_RED = LED2,
LED_GREEN = LED3,
LED_BLUE = LED1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@

#include "analogin_api.h"

// NOTE: Ensurce mbed_sdk_init() will get called before C++ global object constructor.
#if defined(__CC_ARM) || defined(__GNUC__)
void mbed_sdk_init_forced(void) __attribute__((constructor(101)));
#elif defined(__ICCARM__)
// FIXME: How to achieve it in IAR?
#endif


void mbed_sdk_init(void)
{
// NOTE: Support singleton semantics to be called from other init functions
Expand Down Expand Up @@ -75,8 +67,3 @@ void mbed_sdk_init(void)
/* Lock protected registers */
SYS_LockReg();
}

void mbed_sdk_init_forced(void)
{
mbed_sdk_init();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define symbol __ICFEDIT_intvec_start__ = MBED_APP_START;
define symbol __ICFEDIT_region_ROM_start__ = MBED_APP_START;
define symbol __ICFEDIT_region_ROM_end__ = MBED_APP_START + MBED_APP_SIZE - 1;
define symbol __ICFEDIT_region_IRAM_start__ = 0x20000000;
define symbol __ICFEDIT_region_IRAM_end__ = 0x20008000;
define symbol __ICFEDIT_region_IRAM_end__ = 0x20008000 - 1;
/*-Sizes-*/
define symbol __ICFEDIT_size_cstack__ = 0x800;
define symbol __ICFEDIT_size_heap__ = 0x4000;
Expand Down
33 changes: 11 additions & 22 deletions targets/TARGET_NUVOTON/TARGET_M451/device/startup_M451Series.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ extern uint32_t __bss_start__;
extern uint32_t __bss_end__;

extern void uvisor_init(void);
//#if defined(TOOLCHAIN_GCC_ARM)
//extern void _start(void);
//#endif
extern void software_init_hook(void) __attribute__((weak));
extern void __libc_init_array(void);
extern int main(void);
#if defined(TOOLCHAIN_GCC_ARM)
extern void _start(void);
#else
#error("For GCC toolchain, only support GNU ARM Embedded")
#endif
#endif

/* Default empty handler */
Expand Down Expand Up @@ -271,14 +270,15 @@ void Reset_Handler(void)
/* HXT Crystal Type Select: INV */
CLK->PWRCTL &= ~CLK_PWRCTL_HXTSELTYP_Msk;

/* Enable register write-protection function */
SYS_LockReg();

/**
* Because EBI (external SRAM) init is done in SystemInit(), SystemInit() must be called at the very start.
* NOTE 1: Unlock is required for perhaps some register access in SystemInit().
* NOTE 2: Because EBI (external SRAM) init is done in SystemInit(), SystemInit() must be called at the very start.
*/
SystemInit();

/* Enable register write-protection function */
SYS_LockReg();

#if defined(__CC_ARM)
__main();

Expand Down Expand Up @@ -306,19 +306,8 @@ void Reset_Handler(void)
}
}

//uvisor_init();
_start();

if (software_init_hook) {
/**
* Give control to the RTOS via software_init_hook() which will also call __libc_init_array().
* Assume software_init_hook() is defined in libraries/rtos/rtx/TARGET_CORTEX_M/RTX_CM_lib.h.
*/
software_init_hook();
}
else {
__libc_init_array();
main();
}
#endif

/* Infinite loop */
Expand Down
Loading