Skip to content

Commit

Permalink
fix: Replaced the standard printf function with a static printf imple…
Browse files Browse the repository at this point in the history
…mentation

Signed-off-by: Taras Drozdovskyi <[email protected]>
  • Loading branch information
tdrozdovsky committed Feb 28, 2024
1 parent 8fec8e5 commit 473c20b
Show file tree
Hide file tree
Showing 37 changed files with 1,150 additions and 132 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
- name: Build the project
run: |
make PLATFORM=${{ matrix.platform }} create_context
wget -L https://raw.githubusercontent.com/OpenNuvoton/M2351BSP/master/Library/Device/Nuvoton/M2351/Source/GCC/_syscalls.c -O ./arch/cortex-m23/m2351/src/Device/Nuvoton/M2351/Source/GCC/_syscalls.c
wget -L https://raw.githubusercontent.com/OpenNuvoton/M2351BSP/master/SampleCode/MKROM/SecureBootDemo/NuBL2/main.c -O ./arch/cortex-m23/m2351/src/NuBL2/main.c
wget -L https://raw.githubusercontent.com/OpenNuvoton/M2351BSP/master/SampleCode/MKROM/SecureBootDemo/NuBL2/VerifyNuBL3x.c -O ./arch/cortex-m23/m2351/src/NuBL2/VerifyNuBL3x.c
wget -L https://raw.githubusercontent.com/OpenNuvoton/M2351BSP/master/SampleCode/MKROM/SecureBootDemo/NuBL2/NuBL2.h -O ./arch/cortex-m23/m2351/src/NuBL2/NuBL2.h
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ jobs:
- name: Build the project
run: |
make PLATFORM=numaker_pfm_m2351 create_context
wget -L https://raw.githubusercontent.com/OpenNuvoton/M2351BSP/master/Library/Device/Nuvoton/M2351/Source/GCC/_syscalls.c -O ./arch/cortex-m23/m2351/src/Device/Nuvoton/M2351/Source/GCC/_syscalls.c
wget -L https://raw.githubusercontent.com/OpenNuvoton/M2351BSP/master/SampleCode/MKROM/SecureBootDemo/NuBL2/main.c -O ./arch/cortex-m23/m2351/src/NuBL2/main.c
wget -L https://raw.githubusercontent.com/OpenNuvoton/M2351BSP/master/SampleCode/MKROM/SecureBootDemo/NuBL2/VerifyNuBL3x.c -O ./arch/cortex-m23/m2351/src/NuBL2/VerifyNuBL3x.c
wget -L https://raw.githubusercontent.com/OpenNuvoton/M2351BSP/master/SampleCode/MKROM/SecureBootDemo/NuBL2/NuBL2.h -O ./arch/cortex-m23/m2351/src/NuBL2/NuBL2.h
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ jobs:
- name: Build the project
run: |
make PLATFORM=numaker_pfm_m2351 create_context
wget -L https://raw.githubusercontent.com/OpenNuvoton/M2351BSP/master/Library/Device/Nuvoton/M2351/Source/GCC/_syscalls.c -O ./arch/cortex-m23/m2351/src/Device/Nuvoton/M2351/Source/GCC/_syscalls.c
wget -L https://raw.githubusercontent.com/OpenNuvoton/M2351BSP/master/SampleCode/MKROM/SecureBootDemo/NuBL2/main.c -O ./arch/cortex-m23/m2351/src/NuBL2/main.c
wget -L https://raw.githubusercontent.com/OpenNuvoton/M2351BSP/master/SampleCode/MKROM/SecureBootDemo/NuBL2/VerifyNuBL3x.c -O ./arch/cortex-m23/m2351/src/NuBL2/VerifyNuBL3x.c
wget -L https://raw.githubusercontent.com/OpenNuvoton/M2351BSP/master/SampleCode/MKROM/SecureBootDemo/NuBL2/NuBL2.h -O ./arch/cortex-m23/m2351/src/NuBL2/NuBL2.h
Expand Down
6 changes: 0 additions & 6 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,6 @@ valid.
* Copyright (C) 2017 Nuvoton Technology Corp. All rights reserved.
*/

arch/cortex-m23/m2351/src/Device/Nuvoton/M2351/Source/GCC/_syscalls.c
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// This file is part of the uOS++ III distribution
// Parts of this file are from the newlib sources, issued under GPL.
// Copyright (c) 2014 Liviu Ionescu

arch/cortex-m23/m2351/src/Device/
arch/cortex-m23/m2351/src/StdDriver/
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
58 changes: 0 additions & 58 deletions ReleaseNotes

This file was deleted.

2 changes: 2 additions & 0 deletions apps/aes/ca/aes_ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <stdio.h>
#include <string.h>

#include "printf.h"

/* OP-TEE TEE client API (built by optee_client) */
#include <tee_client_api.h>

Check failure on line 35 in apps/aes/ca/aes_ns.c

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/aes/ca/aes_ns.c:35:10 [clang-diagnostic-error]

'tee_client_api.h' file not found

Expand Down
2 changes: 2 additions & 0 deletions apps/hello_world/ca/hello_world_ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <stdio.h>
#include <string.h>

#include "printf.h"

#include "tee_client_api.h"

Check failure on line 34 in apps/hello_world/ca/hello_world_ns.c

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/hello_world/ca/hello_world_ns.c:34:10 [clang-diagnostic-error]

'tee_client_api.h' file not found

/* To the the UUID (found the the TA's h-file(s)) */
Expand Down
2 changes: 2 additions & 0 deletions apps/hotp/ca/hotp_ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <stdio.h>
#include <string.h>

#include "printf.h"

/* OP-TEE TEE client API (built by optee_client) */
#include <tee_client_api.h>

Check failure on line 15 in apps/hotp/ca/hotp_ns.c

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/hotp/ca/hotp_ns.c:15:10 [clang-diagnostic-error]

'tee_client_api.h' file not found

Expand Down
2 changes: 2 additions & 0 deletions apps/test/ca/test_ns.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <stdio.h>
#include <string.h>

#include "printf.h"

/* OP-TEE TEE client API (built by optee_client) */
#include <tee_client_api.h>

Check failure on line 35 in apps/test/ca/test_ns.c

View workflow job for this annotation

GitHub Actions / cpp-linter

apps/test/ca/test_ns.c:35:10 [clang-diagnostic-error]

'tee_client_api.h' file not found

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <stdint.h>
#include "NuMicro.h"

#include "printf.h"

#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
#include "partition_M2351.h"
extern void SCU_IRQHandler(void);
Expand Down
2 changes: 0 additions & 2 deletions arch/cortex-m23/m2351/src/NuBL2/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ CHIP_ASRCS_S = ../Device/Nuvoton/M2351/Source/GCC/startup_M2351.S \
KeyInfo/NuBL3xKeyStorage.S

CHIP_CSRCS_S = ../Device/Nuvoton/M2351/Source/system_M2351.c \
../Device/Nuvoton/M2351/Source/GCC/_syscalls.c \
main.c \
VerifyNuBL3x.c \
FwInfo.c

121 changes: 121 additions & 0 deletions arch/cortex-m23/m2351/src/StdDriver/inc/printf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
///////////////////////////////////////////////////////////////////////////////
// \author (c) Marco Paland ([email protected])
// 2014-2019, PALANDesign Hannover, Germany
//
// \license The MIT License (MIT)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// \brief Tiny printf, sprintf and snprintf implementation, optimized for speed on
// embedded systems with a very limited resources.
// Use this instead of bloated standard/newlib printf.
// These routines are thread safe and reentrant.
//
///////////////////////////////////////////////////////////////////////////////

#ifndef _PRINTF_H_
#define _PRINTF_H_

#include <stdarg.h>
#include <stddef.h>


#ifdef __cplusplus
extern "C" {
#endif


/**
* Output a character to a custom device like UART, used by the printf() function
* This function is declared here only. You have to write your custom implementation somewhere
* \param character Character to output
*/
// #ifdef C_SECURE_CODE
// void __putchar(char character);
// #else
void _putchar(char character);
// #endif


/**
* Tiny printf implementation
* You have to implement _putchar if you use printf()
* To avoid conflicts with the regular printf() API it is overridden by macro defines
* and internal underscore-appended functions like printf_() are used
* \param format A string that specifies the format of the output
* \return The number of characters that are written into the array, not counting the terminating null character
*/
#define printf printf_
int printf_(const char* format, ...);


/**
* Tiny sprintf implementation
* Due to security reasons (buffer overflow) YOU SHOULD CONSIDER USING (V)SNPRINTF INSTEAD!
* \param buffer A pointer to the buffer where to store the formatted string. MUST be big enough to store the output!
* \param format A string that specifies the format of the output
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
*/
#define sprintf sprintf_
int sprintf_(char* buffer, const char* format, ...);


/**
* Tiny snprintf/vsnprintf implementation
* \param buffer A pointer to the buffer where to store the formatted string
* \param count The maximum number of characters to store in the buffer, including a terminating null character
* \param format A string that specifies the format of the output
* \param va A value identifying a variable arguments list
* \return The number of characters that COULD have been written into the buffer, not counting the terminating
* null character. A value equal or larger than count indicates truncation. Only when the returned value
* is non-negative and less than count, the string has been completely written.
*/
#define snprintf snprintf_
#define vsnprintf vsnprintf_
int snprintf_(char* buffer, size_t count, const char* format, ...);
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);


/**
* Tiny vprintf implementation
* \param format A string that specifies the format of the output
* \param va A value identifying a variable arguments list
* \return The number of characters that are WRITTEN into the buffer, not counting the terminating null character
*/
#define vprintf vprintf_
int vprintf_(const char* format, va_list va);


/**
* printf with output function
* You may use this as dynamic alternative to printf() with its fixed _putchar() output
* \param out An output function which takes one character and an argument pointer
* \param arg An argument pointer for user data passed to output function
* \param format A string that specifies the format of the output
* \return The number of characters that are sent to the output function, not counting the terminating null character
*/
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...);


#ifdef __cplusplus
}
#endif


#endif // _PRINTF_H_
1 change: 1 addition & 0 deletions arch/cortex-m23/m2351/src/StdDriver/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ SRCS += uart.c
#SRCS += usci_uart.c
#SRCS += wdt.c
#SRCS += wwdt.c
SRCS += printf.c

ifeq ($(WORLD), secure)
SRCS += clk.c
Expand Down
Loading

0 comments on commit 473c20b

Please sign in to comment.