Skip to content

Commit

Permalink
Use ubuntu 20.04 for formatting so that this repo can use the same fo…
Browse files Browse the repository at this point in the history
…rmatting as all other FreeRTOS Repos
  • Loading branch information
Skptak committed Oct 31, 2023
1 parent c0eba13 commit 07e2bc2
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 119 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: FreeRTOS/CI-CD-Github-Actions/spellings@main

formatting:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Check formatting
Expand Down
180 changes: 100 additions & 80 deletions Bsp/common/bsp_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,114 +11,134 @@

extern ARM_DRIVER_USART Driver_USART0;

void bsp_serial_init(void)
void bsp_serial_init( void )
{
Driver_USART0.Initialize(NULL);
Driver_USART0.Control(ARM_USART_MODE_ASYNCHRONOUS, DEFAULT_UART_BAUDRATE);
Driver_USART0.Initialize( NULL );
Driver_USART0.Control( ARM_USART_MODE_ASYNCHRONOUS, DEFAULT_UART_BAUDRATE );
}

void bsp_serial_print(char *str)
void bsp_serial_print( char * str )
{
(void)Driver_USART0.Send(str, strlen(str));
( void ) Driver_USART0.Send( str, strlen( str ) );
}

#if defined(__ARMCOMPILER_VERSION)
#if defined( __ARMCOMPILER_VERSION )

/* Retarget armclang, which requires all IO system calls to be overridden together. */

#include <rt_sys.h>
#include <rt_sys.h>

#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2

FILEHANDLE _sys_open(const char *name, int openmode)
{
if (name == NULL) {
return -1;
}

// By default, the Arm Compiler uses the special file path ":tt" for stdin,
// stdout and stderr and distinguishes between them using openmode. For details,
// see https://github.com/ARM-software/abi-aa/blob/2022Q1/semihosting/semihosting.rst#sys-open-0x01
if (strcmp(name, ":tt") == 0) {
if (openmode & OPEN_W) {
return STDOUT_FILENO;
}
if (openmode & OPEN_A) {
return STDERR_FILENO;
FILEHANDLE _sys_open( const char * name,
int openmode )
{
if( name == NULL )
{
return -1;
}
return STDIN_FILENO;
}

return -1;
}

int _sys_close(FILEHANDLE fh)
{
/* Not implemented */
(void)fh;
return -1;
}

int _sys_write(FILEHANDLE fd, const unsigned char *str, unsigned int len, int mode)
{
/* From <rt_sys.h>: `mode' exists for historical reasons and must be ignored. */
(void)mode;
/* By default, the Arm Compiler uses the special file path ":tt" for stdin, */
/* stdout and stderr and distinguishes between them using openmode. For details, */
/* see https://github.com/ARM-software/abi-aa/blob/2022Q1/semihosting/semihosting.rst#sys-open-0x01 */
if( strcmp( name, ":tt" ) == 0 )
{
if( openmode & OPEN_W )
{
return STDOUT_FILENO;
}

if( openmode & OPEN_A )
{
return STDERR_FILENO;
}

return STDIN_FILENO;
}

if (fd != STDOUT_FILENO && fd != STDERR_FILENO) {
return -1;
}

if (Driver_USART0.Send(str, len) != ARM_DRIVER_OK) {
int _sys_close( FILEHANDLE fh )
{
/* Not implemented */
( void ) fh;
return -1;
}

return 0;
}
int _sys_write( FILEHANDLE fd,
const unsigned char * str,
unsigned int len,
int mode )
{
/* From <rt_sys.h>: `mode' exists for historical reasons and must be ignored. */
( void ) mode;

if( ( fd != STDOUT_FILENO ) && ( fd != STDERR_FILENO ) )
{
return -1;
}

int _sys_read(FILEHANDLE fd, unsigned char *str, unsigned int len, int mode)
{
// From <rt_sys.h>: `mode' exists for historical reasons and must be ignored.
(void)mode;
if( Driver_USART0.Send( str, len ) != ARM_DRIVER_OK )
{
return -1;
}

/* Not implemented */
(void)str;
(void)len;
return -1;
}
return 0;
}

int _sys_istty(FILEHANDLE fh)
{
/* Not implemented */
(void)fh;
return 0;
}
int _sys_read( FILEHANDLE fd,
unsigned char * str,
unsigned int len,
int mode )
{
/* From <rt_sys.h>: `mode' exists for historical reasons and must be ignored. */
( void ) mode;

/* Not implemented */
( void ) str;
( void ) len;
return -1;
}

long _sys_flen(FILEHANDLE fh)
{
/* Not implemented */
(void)fh;
return -1;
}
int _sys_istty( FILEHANDLE fh )
{
/* Not implemented */
( void ) fh;
return 0;
}

int _sys_seek(FILEHANDLE fh, long offset)
{
/* Not implemented */
(void)fh;
(void)offset;
return -1;
}
long _sys_flen( FILEHANDLE fh )
{
/* Not implemented */
( void ) fh;
return -1;
}

int _sys_seek( FILEHANDLE fh,
long offset )
{
/* Not implemented */
( void ) fh;
( void ) offset;
return -1;
}

#else /* !defined(__ARMCOMPILER_VERSION) */

/* Redirects gcc printf to UART0 */
int _write(int fd, char *str, int len)
{
if (Driver_USART0.Send(str, len) == ARM_DRIVER_OK) {
return len;
int _write( int fd,
char * str,
int len )
{
if( Driver_USART0.Send( str, len ) == ARM_DRIVER_OK )
{
return len;
}

return 0;
}
return 0;
}

#endif
#endif /* if defined( __ARMCOMPILER_VERSION ) */
4 changes: 2 additions & 2 deletions Bsp/common/bsp_serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
/**
* \brief Initializes default UART device
*/
void bsp_serial_init(void);
void bsp_serial_init( void );

/**
* \brief Prints a string through the default UART device
*/
void bsp_serial_print(char *str);
void bsp_serial_print( char * str );

#endif /* __SERIAL_H__ */
17 changes: 9 additions & 8 deletions Middleware/ARM/IoT_VSocket-lib/transport_tls_iot_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@


static int Recv_Cb( void * pvCallerContext,
unsigned char * pucReceiveBuffer,
size_t xReceiveLength );
unsigned char * pucReceiveBuffer,
size_t xReceiveLength );
static int Send_Cb( void * pvCallerContext,
const unsigned char * pucData,
size_t xDataLength );
const unsigned char * pucData,
size_t xDataLength );


TransportStatus_t Transport_Connect( NetworkContext_t * pNetworkContext,
Expand Down Expand Up @@ -199,8 +199,8 @@ int32_t Transport_Send( NetworkContext_t * pNetworkContext,
* @return The number of bytes actually read or appropriate error code.
*/
static int Recv_Cb( void * pvCallerContext,
unsigned char * pucReceiveBuffer,
size_t xReceiveLength )
unsigned char * pucReceiveBuffer,
size_t xReceiveLength )
{
int rc;
NetworkContext_t * pNetworkContext = ( NetworkContext_t * ) ( pvCallerContext );
Expand Down Expand Up @@ -236,8 +236,8 @@ static int Recv_Cb( void * pvCallerContext,
* @return The number of bytes actually sent.
*/
static int Send_Cb( void * pvCallerContext,
const unsigned char * pucData,
size_t xDataLength )
const unsigned char * pucData,
size_t xDataLength )
{
NetworkContext_t * pNetworkContext = ( NetworkContext_t * ) ( pvCallerContext );
int rc;
Expand Down Expand Up @@ -265,6 +265,7 @@ TransportStatus_t Transport_Disconnect( NetworkContext_t * pNetworkContext )
else
{
int32_t socketStatus;

do
{
socketStatus = iotSocketClose( pNetworkContext->socket );
Expand Down
17 changes: 10 additions & 7 deletions Middleware/ARM/freertos-ota-pal-psa-lib/src/ota_provision.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,20 @@ extern int convert_pem_to_der( const unsigned char * pucInput,
unsigned char * pucOutput,
size_t * pxOlen );

int ota_privision_code_signing_key(psa_key_handle_t * key_handle)
int ota_privision_code_signing_key( psa_key_handle_t * key_handle )
{
uint8_t public_key_der[512];
uint8_t public_key_der[ 512 ];
size_t xLength = 512;
int result;
psa_key_handle_t key_handle_tmp = 0;
psa_status_t status;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;

result = convert_pem_to_der( ( const unsigned char * ) cOTARSAPublicKey,
sizeof( cOTARSAPublicKey ),
public_key_der,
&xLength );
sizeof( cOTARSAPublicKey ),
public_key_der,
&xLength );

if( result != 0 )
{
return result;
Expand All @@ -50,11 +51,13 @@ int ota_privision_code_signing_key(psa_key_handle_t * key_handle)
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH );
psa_set_key_algorithm( &attributes, PSA_ALG_RSA_PSS_ANY_SALT( PSA_ALG_SHA_256 ) );
psa_set_key_type( &attributes, PSA_KEY_TYPE_RSA_PUBLIC_KEY );
psa_set_key_bits(&attributes, 3072);
status = psa_import_key(&attributes, ( const uint8_t *)public_key_der, xLength, &key_handle_tmp );
psa_set_key_bits( &attributes, 3072 );
status = psa_import_key( &attributes, ( const uint8_t * ) public_key_der, xLength, &key_handle_tmp );

if( status == PSA_SUCCESS )
{
*key_handle = key_handle_tmp;
}

return status;
}
18 changes: 9 additions & 9 deletions Middleware/ARM/freertos-ota-pal-psa-lib/src/ota_provision.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
*/

#ifndef _OTA_PROVISION_
#define _OTA_PROVISION_
#include "psa/crypto.h"
#ifdef __cplusplus
extern "C" {
#endif
#define _OTA_PROVISION_
#include "psa/crypto.h"
#ifdef __cplusplus
extern "C" {
#endif

int ota_privision_code_signing_key(psa_key_handle_t * key_handle);
int ota_privision_code_signing_key( psa_key_handle_t * key_handle );

#ifdef __cplusplus
#ifdef __cplusplus
}
#endif
#endif
#endif
#endif /* ifndef _OTA_PROVISION_ */
Loading

0 comments on commit 07e2bc2

Please sign in to comment.