From b54bcff3e8591a0c3db7d5c0605ee9771a324198 Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Tue, 19 Dec 2023 20:29:01 +0530 Subject: [PATCH 01/14] Add support for strcpy --- src/lib/libc/include/string.h | 7 +++++++ src/lib/libc/string.c | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/src/lib/libc/include/string.h b/src/lib/libc/include/string.h index f6b23f9a..87ad9f15 100644 --- a/src/lib/libc/include/string.h +++ b/src/lib/libc/include/string.h @@ -123,3 +123,10 @@ size_t strnlen(const char *i, size_t size); * ret = pointer to first occurance */ char *strchr_rev(const char *i, int r); + +/* + * Strcpy + * i = destination address + * j = source address + */ +size_t strcpy(char *i, const char *j); diff --git a/src/lib/libc/string.c b/src/lib/libc/string.c index 3ce2e85b..accb3068 100644 --- a/src/lib/libc/string.c +++ b/src/lib/libc/string.c @@ -204,3 +204,8 @@ char *strchr_rev(const char *i, int r) } return ret; } + +size_t strcpy(char *i, const char *j) +{ + return strlcpy(i, j, strlen(j)); +} From d571a3791d2da7188b6eb2276a5a86de9f20c107 Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Thu, 21 Dec 2023 14:30:01 +0530 Subject: [PATCH 02/14] strcpy is now a macro which uses strlcpy - strcpy function has risks buffer overflow, it will now be using strlcpy and strlen internally. --- src/lib/libc/include/string.h | 2 +- src/lib/libc/string.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/lib/libc/include/string.h b/src/lib/libc/include/string.h index 87ad9f15..afb5ee96 100644 --- a/src/lib/libc/include/string.h +++ b/src/lib/libc/include/string.h @@ -129,4 +129,4 @@ char *strchr_rev(const char *i, int r); * i = destination address * j = source address */ -size_t strcpy(char *i, const char *j); +#define strcpy(i, j) strlcpy(i, j, strlen(j)); diff --git a/src/lib/libc/string.c b/src/lib/libc/string.c index accb3068..8577fc4d 100644 --- a/src/lib/libc/string.c +++ b/src/lib/libc/string.c @@ -205,7 +205,3 @@ char *strchr_rev(const char *i, int r) return ret; } -size_t strcpy(char *i, const char *j) -{ - return strlcpy(i, j, strlen(j)); -} From d2ac8e32908f8952a6f62c7a427bb6d90e75a97c Mon Sep 17 00:00:00 2001 From: Pranjal Chanda <40349163+pranjalchanda08@users.noreply.github.com> Date: Sat, 23 Dec 2023 19:29:21 +0530 Subject: [PATCH 03/14] Update sonarcloud.yml --- .github/workflows/sonarcloud.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index a5066287..2d1d2ea7 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -37,10 +37,10 @@ jobs: run: | make get_avr_tc AVR_TC_REPO=https://github.com/VisorFolks/avr-toolchain.git make get_riscv_tc RISC_V_TC_REPO=https://github.com/VisorFolks/risc-v-toolchain.git - - name: Set up JDK 11 - uses: actions/setup-java@v1 + - name: Set up JDK 17 + uses: actions/setup-java@v4.0.0 with: - java-version: 11 + java-version: 17 - name: Download and set up sonar-scanner env: SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip From b894e720d211ebca4b6a227ccdb14cb781c69de1 Mon Sep 17 00:00:00 2001 From: Pranjal Chanda <40349163+pranjalchanda08@users.noreply.github.com> Date: Sat, 23 Dec 2023 19:34:12 +0530 Subject: [PATCH 04/14] Update sonarcloud.yml --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 2d1d2ea7..7f44dfb0 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -38,7 +38,7 @@ jobs: make get_avr_tc AVR_TC_REPO=https://github.com/VisorFolks/avr-toolchain.git make get_riscv_tc RISC_V_TC_REPO=https://github.com/VisorFolks/risc-v-toolchain.git - name: Set up JDK 17 - uses: actions/setup-java@v4.0.0 + uses: actions/setup-java@v1 with: java-version: 17 - name: Download and set up sonar-scanner From 0cc5bd9f3508031c81762f220caf2bb74775adda Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Sun, 24 Dec 2023 12:30:57 +0530 Subject: [PATCH 05/14] Updated status codes to use +ve values. - Using +ve values, will increase the range to 0-65535 for 16b enums Issue: #265 --- src/include/status.h | 106 +++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/src/include/status.h b/src/include/status.h index 0a334037..479171ab 100644 --- a/src/include/status.h +++ b/src/include/status.h @@ -18,72 +18,72 @@ typedef enum status { success = 0x0000, /* Generic error */ - error_generic = -0x0001, - error_func_inval = -0x0002, - error_func_inval_arg = -0x0003, - error_overflow = -0x0004, + error_generic = 0x0001, + error_func_inval = 0x0002, + error_func_inval_arg = 0x0003, + error_overflow = 0x0004, /* Driver related error */ - error_driver = -0x0100, - error_driver_init_done = -0x0101, - error_driver_init_failed = -0x0102, - error_driver_busy = -0x0103, - error_driver_data = -0x0104, + error_driver = 0x0100, + error_driver_init_done = 0x0101, + error_driver_init_failed = 0x0102, + error_driver_busy = 0x0103, + error_driver_data = 0x0104, /* Device related error */ - error_device = -0x0200, - error_device_id_inval = -0x0201, - error_device_inval = -0x0202, - error_device_busy = -0x0203, + error_device = 0x0200, + error_device_id_inval = 0x0201, + error_device_inval = 0x0202, + error_device_busy = 0x0203, /* Visor Call related error */ - error_vcall = -0x0300, - error_vcall_code_inval = -0x0301, + error_vcall = 0x0300, + error_vcall_code_inval = 0x0301, /* Memory related error */ - error_memory = -0x0600, - error_memory_low = -0x0601, + error_memory = 0x0600, + error_memory_low = 0x0601, /* File related error */ - error_file = -0x0700, - error_file_desc = -0x0701, - error_file_exist = -0x0702, - error_file_not_found = -0x0703, - error_file_no_space = -0x0704, - error_file_long_name = -0x0705, - error_file_io = -0x0706, + error_file = 0x0700, + error_file_desc = 0x0701, + error_file_exist = 0x0702, + error_file_not_found = 0x0703, + error_file_no_space = 0x0704, + error_file_long_name = 0x0705, + error_file_io = 0x0706, /* String related error */ - error_string = -0x0800, + error_string = 0x0800, /* Math related error */ - error_math = -0x0900, - error_math_inval_arg = -0x0901, - error_math_large_val = -0x0902, + error_math = 0x0900, + error_math_inval_arg = 0x0901, + error_math_large_val = 0x0902, /* Access related error */ - error_access = -0x0a00, + error_access = 0x0a00, /* System related error */ - error_system = -0x0b00, - error_system_irq_link_fail = -0x0b01, - error_system_irq_unlink_fail = -0x0b02, - error_system_clk_caliberation = -0x0b03, - error_system_prog_fail = -0x0b04, + error_system = 0x0b00, + error_system_irq_link_fail = 0x0b01, + error_system_irq_unlink_fail = 0x0b02, + error_system_clk_caliberation = 0x0b03, + error_system_prog_fail = 0x0b04, /* Network related error */ - error_net = -0x0c00, - error_net_con_timeout = -0x0c01, + error_net = 0x0c00, + error_net_con_timeout = 0x0c01, /* User space related error */ - error_user = -0x0d00, + error_user = 0x0d00, /* IO related error */ - error_io = -0x0e00, + error_io = 0x0e00, /* OS related error */ - error_os = -0x0f00, - error_os_task_overfow = -0x0f01, - error_os_deadlock = -0x0f02, - error_os_invalid_op = -0x0f03, - error_os_sem_get = -0x0f04, - error_os_panic_presched_cb_null = -0x0f05, - error_os_panic_sched_algo_null = -0x0f06, - error_os_panic_os_start_fail = -0x0f07, - error_os_mutex_lock = -0x0f08, - error_os_mutex_unlock = -0x0f09, + error_os = 0x0f00, + error_os_task_overfow = 0x0f01, + error_os_deadlock = 0x0f02, + error_os_invalid_op = 0x0f03, + error_os_sem_get = 0x0f04, + error_os_panic_presched_cb_null = 0x0f05, + error_os_panic_sched_algo_null = 0x0f06, + error_os_panic_os_start_fail = 0x0f07, + error_os_mutex_lock = 0x0f08, + error_os_mutex_unlock = 0x0f09, /* Mesg related error */ - error_mesg = -0x1000, - error_mesg_long = -0x1001, + error_mesg = 0x1000, + error_mesg_long = 0x1001, /* List related error */ - error_list = -0x1100, - error_list_node_exists = -0x1101, - error_list_node_not_found = -0x1102, + error_list = 0x1100, + error_list_node_exists = 0x1101, + error_list_node_not_found = 0x1102, } status_t; From 7813dc1d9085bc6fdfc1970d465c83183dce52a8 Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Sun, 24 Dec 2023 13:47:46 +0530 Subject: [PATCH 06/14] Updated error handling - Added new status code Issue: #265 --- src/driver/interrupt/plic/plic.c | 3 +- src/driver/sysclk/sysclk_prci/sysclk_prci.c | 30 ++++++------------- src/include/status.h | 1 + src/platform/mega_avr/common/hal/adc/adc.c | 14 ++++----- src/platform/mega_avr/common/hal/gpio/gpio.c | 22 +++++++------- src/platform/mega_avr/common/hal/spi/spi.c | 12 ++++---- .../mega_avr/common/hal/timer/timer.c | 9 +++--- src/platform/mega_avr/common/hal/uart/uart.c | 16 +++++----- src/platform/mega_avr/common/hal/wdt/wdt.c | 15 ++++------ .../sifive/common_fe310/hal/clint/clint.c | 3 -- 10 files changed, 53 insertions(+), 72 deletions(-) diff --git a/src/driver/interrupt/plic/plic.c b/src/driver/interrupt/plic/plic.c index 16a17b8c..30a0e14c 100644 --- a/src/driver/interrupt/plic/plic.c +++ b/src/driver/interrupt/plic/plic.c @@ -145,8 +145,7 @@ static bool plic_get_pending(uint32_t irq_id) static void plic_register_irq_handler(uint32_t id, void (* handler)(void)) { - assert(id); - assert(handler); + RET_ON_FAIL(id && handler,); plic_irq_handler[id] = handler; arch_dsb(); } diff --git a/src/driver/sysclk/sysclk_prci/sysclk_prci.c b/src/driver/sysclk/sysclk_prci/sysclk_prci.c index dfa61634..3665f1f2 100644 --- a/src/driver/sysclk/sysclk_prci/sysclk_prci.c +++ b/src/driver/sysclk/sysclk_prci/sysclk_prci.c @@ -37,8 +37,9 @@ static status_t sysclk_setup() istate_t ist; sysclk = (sysclk_port_t *)malloc(sizeof(sysclk_port_t)); - if(!sysclk) - return error_memory_low; + + RET_ON_FAIL(sysclk, error_memory_low); + port = sysclk; arch_visor_call(fetch_dp, clock, 0, 0, &vres); @@ -84,10 +85,8 @@ static status_t sysclk_disable() istate_t ist; sysclk_port_t *port = sysclk; - if(!port) - return error_driver_init_failed; - - assert(port->baddr && port->base_clk); + RET_ON_FAIL(port && port->baddr && port->base_clk, + error_driver_data); lock_acquire(&sysclk_key); arch_di_save_state(&ist); @@ -111,10 +110,9 @@ status_t sysclk_reset() status_t ret; sysclk_port_t *port = sysclk; istate_t ist; - if(!port) - return error_driver_init_failed; - assert(port->baddr && port->base_clk); + RET_ON_FAIL(port && port->baddr && port->base_clk, + error_driver_data); lock_acquire(&sysclk_key); arch_di_save_state(&ist); @@ -136,8 +134,6 @@ static inline void sysclk_set_internal(unsigned int clk _UNUSED) { status_t ret; sysclk_port_t *port = sysclk; - if(!port) - return; ret = prci_hfxocs_enable(port); prci_pll_bypass(port); ret |= prci_hfosc_enable(port); @@ -155,8 +151,6 @@ static inline void sysclk_set_external(void) { status_t ret; sysclk_port_t *port = sysclk; - if(!port) - return; ret = prci_hfosc_enable(port); ret |= prci_hfxocs_enable(port); prci_pll_select_xosc(port); @@ -172,8 +166,6 @@ static inline void sysclk_set_pll(unsigned int clk) { status_t ret; sysclk_port_t *port = sysclk; - if(!port) - return; ret = prci_hfosc_enable(port); ret |= prci_hfxocs_enable(port); prci_pll_bypass(port); @@ -193,10 +185,8 @@ static void sysclk_configure_clk(call_arg_t a0, call_arg_t a1, call_arg_t a2 _UN istate_t ist; clock_type_t type = (clock_type_t) a0; unsigned int clk = (unsigned int) a1; - if(!port) - return; - assert(port->baddr && port->base_clk); + RET_ON_FAIL(port && port->baddr && port->base_clk,); ret->p = 0; ret->size = 0; @@ -239,10 +229,8 @@ static void sysclk_get_freq(call_arg_t a0 _UNUSED, call_arg_t a1 _UNUSED, sysclk_port_t *port = sysclk; istate_t ist; unsigned int getclk; - if(!port) - return; - assert(port->baddr && port->base_clk); + RET_ON_FAIL(port && port->baddr && port->base_clk,); lock_acquire(&sysclk_key); arch_di_save_state(&ist); diff --git a/src/include/status.h b/src/include/status.h index 479171ab..bd840311 100644 --- a/src/include/status.h +++ b/src/include/status.h @@ -22,6 +22,7 @@ typedef enum status error_func_inval = 0x0002, error_func_inval_arg = 0x0003, error_overflow = 0x0004, + error_inval_pointer = 0x0005, /* Driver related error */ error_driver = 0x0100, error_driver_init_done = 0x0101, diff --git a/src/platform/mega_avr/common/hal/adc/adc.c b/src/platform/mega_avr/common/hal/adc/adc.c index fd411596..bc4d6744 100644 --- a/src/platform/mega_avr/common/hal/adc/adc.c +++ b/src/platform/mega_avr/common/hal/adc/adc.c @@ -117,7 +117,7 @@ static inline status_t _adc_config_vref(adc_port_t *port, adc_ref_t vref) status_t adc_setup(adc_port_t *port) { status_t ret = success; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); ret |= platform_clk_en(port->clk_id); _adc_enable(port); ret |= _adc_set_prescaler(port); @@ -132,7 +132,7 @@ status_t adc_setup(adc_port_t *port) status_t adc_shutdown(adc_port_t *port) { status_t ret = success; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); ret |= adc_int_dis(port); _adc_disable(port); ret |= platform_clk_dis(port->clk_id); @@ -149,14 +149,14 @@ bool adc_busy(adc_port_t *port) status_t adc_int_en(adc_port_t *port) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); MMIO8(port->baddr + ADCSRA_OFFSET) |= (1 << ADIE); return success; } status_t adc_int_dis(adc_port_t *port) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); MMIO8(port->baddr + ADCSRA_OFFSET) &= ~(1 << ADIE); return success; } @@ -164,7 +164,7 @@ status_t adc_int_dis(adc_port_t *port) status_t adc_config_pin(adc_port_t *port, uint8_t pin, adc_trig_t trigger, uint8_t resolution, adc_ref_t vref) { status_t ret = success; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); if(pin > N_ADC_PINS) return error_func_inval_arg; ret |= _adc_config_vref(port, vref); @@ -178,8 +178,8 @@ status_t adc_config_pin(adc_port_t *port, uint8_t pin, adc_trig_t trigger, uint8 status_t adc_read(adc_port_t *port, uint16_t *adc_val) { status_t ret = success; - assert(port); - assert(adc_val); + RET_ON_FAIL(port, error_inval_pointer); + RET_ON_FAIL(adc_val, error_inval_pointer); if(MMIO8(port->baddr + ADMUX_OFFSET) & (1 << ADLAR)) { *adc_val = MMIO8(port->baddr + ADCH_OFFSET); diff --git a/src/platform/mega_avr/common/hal/gpio/gpio.c b/src/platform/mega_avr/common/hal/gpio/gpio.c index 63906a37..40604b40 100644 --- a/src/platform/mega_avr/common/hal/gpio/gpio.c +++ b/src/platform/mega_avr/common/hal/gpio/gpio.c @@ -28,7 +28,7 @@ status_t gpio_pin_alloc(gpio_port_t *port, uint8_t portID, uint8_t pinID) gpio_module_t *dp; unsigned char flag; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); lock_acquire(&gpio_lock); flag = 0; @@ -62,7 +62,7 @@ status_t gpio_pin_alloc(gpio_port_t *port, uint8_t portID, uint8_t pinID) status_t gpio_pin_mode(const gpio_port_t *port, gpio_mode_t mode) { uintptr_t pbaddr; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); uint8_t pin = port->pin; pbaddr = port->pbaddr; @@ -84,7 +84,7 @@ status_t gpio_pin_mode(const gpio_port_t *port, gpio_mode_t mode) status_t gpio_pin_free(gpio_port_t *port) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); lock_acquire(&gpio_lock); sysdbg4("Releasing GPIO Pin %d on Port, %d", port->pin, port->port); port_status[port->port] &= ~(1 << port->pin); @@ -97,21 +97,21 @@ status_t gpio_pin_free(gpio_port_t *port) status_t gpio_pin_set(const gpio_port_t *port) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); MMIO8(port->pbaddr + PORT_OFFSET) |= (1 << port->pin); return success; } status_t gpio_pin_clear(const gpio_port_t *port) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); MMIO8(port->pbaddr + PORT_OFFSET) &= ~(1 << port->pin); return success; } status_t gpio_pin_toggle(const gpio_port_t *port) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); MMIO8(port->pbaddr + PORT_OFFSET) ^= (1 << port->pin); return success; } @@ -128,7 +128,7 @@ status_t gpio_port_alloc(gpio_port_t *port, uint8_t portID) gpio_module_t *dp; unsigned char flag = 0; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); lock_acquire(&gpio_lock); if(port_status[portID]) @@ -160,7 +160,7 @@ status_t gpio_port_alloc(gpio_port_t *port, uint8_t portID) status_t gpio_port_mode(const gpio_port_t *port, gpio_mode_t mode) { uintptr_t pbaddr; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); uint8_t value = port->pin; pbaddr = port->pbaddr; @@ -182,7 +182,7 @@ status_t gpio_port_mode(const gpio_port_t *port, gpio_mode_t mode) status_t gpio_port_free(gpio_port_t *port) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); lock_acquire(&gpio_lock); sysdbg4("Releasing GPIO Port, %d", port->port); port_status[port->port] = 0; @@ -195,7 +195,7 @@ status_t gpio_port_free(gpio_port_t *port) status_t gpio_port_write(const gpio_port_t *port, gpio_parallel_t val) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); // MegaAVR has 8-bit i/o modules, value to write should be 8-bit wide MMIO8(port->pbaddr + PORT_OFFSET) = (uint8_t)(val & 0xff); return success; @@ -203,7 +203,7 @@ status_t gpio_port_write(const gpio_port_t *port, gpio_parallel_t val) status_t gpio_port_read(const gpio_port_t *port, gpio_parallel_t *val) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); // MegaAVR has 8-bit i/o modules, value returned is 8-bit wide *val = (gpio_parallel_t)MMIO8(port->pbaddr + PIN_OFFSET); return success; diff --git a/src/platform/mega_avr/common/hal/spi/spi.c b/src/platform/mega_avr/common/hal/spi/spi.c index 2c01ad36..9e2c3d9d 100644 --- a/src/platform/mega_avr/common/hal/spi/spi.c +++ b/src/platform/mega_avr/common/hal/spi/spi.c @@ -26,7 +26,7 @@ status_t spi_master_setup(spi_port_t *port, dataframe_format_t df_format, clk_po status_t ret = success; uint8_t spcr_value = 0; gpio_port_t spi_mosi, spi_miso, spi_sck, spi_ss; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); platform_clk_en(port->clk_id); spcr_value |= (1 << SPE) | (1 << MSTR); switch(port->fdiv) @@ -69,7 +69,7 @@ status_t spi_slave_setup(spi_port_t *port, dataframe_format_t df_format, clk_pol status_t ret = success; uint8_t spcr_value = 0; gpio_port_t spi_mosi, spi_miso, spi_sck, spi_ss; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); platform_clk_en(port->clk_id); spcr_value |= (1 << SPE); switch(port->fdiv) @@ -121,28 +121,28 @@ bool spi_trx_done(spi_port_t *port) status_t spi_int_en(spi_port_t *port) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); MMIO8(port->baddr + SPCR_OFFSET) |= (1 << SPIE); return success; } status_t spi_int_dis(spi_port_t * port) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); MMIO8(port->baddr + SPCR_OFFSET) &= ~(1 << SPIE); return success; } status_t spi_tx(spi_port_t *port, char data) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); MMIO8(port->baddr + SPDR_OFFSET) = data; return success; } status_t spi_rx(spi_port_t *port, char *data) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); *data = MMIO8(port->baddr + SPDR_OFFSET); return success; } diff --git a/src/platform/mega_avr/common/hal/timer/timer.c b/src/platform/mega_avr/common/hal/timer/timer.c index 9bf7892c..524b0df7 100644 --- a/src/platform/mega_avr/common/hal/timer/timer.c +++ b/src/platform/mega_avr/common/hal/timer/timer.c @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -28,7 +27,7 @@ status_t timer_setup(const timer_port_t *port, unsigned int mode, unsigned int p { status_t ret; unsigned id; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); id = port->port_id & 0xf0; ret = platform_clk_en(port->clk_id); if(id == 0 || id == 0x20) @@ -60,7 +59,7 @@ status_t timer_shutdown(const timer_port_t *port) { status_t ret = success; unsigned id; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); id = port->port_id & 0xf0; if(id == 0 || id == 0x20) { @@ -82,7 +81,7 @@ status_t timer_shutdown(const timer_port_t *port) status_t timer_read(const timer_port_t *port, size_t *value) { unsigned id; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); id = port->port_id & 0xf0; if(id == 0 || id == 0x20) *value = timer8_read(port); @@ -96,7 +95,7 @@ status_t timer_pwm_set(const timer_port_t *port, bool invert, size_t value) { status_t ret = success; unsigned id; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); id = port->port_id & 0xf0; if(id == 0 || id == 0x20) { diff --git a/src/platform/mega_avr/common/hal/uart/uart.c b/src/platform/mega_avr/common/hal/uart/uart.c index 7b734aab..af452e4b 100644 --- a/src/platform/mega_avr/common/hal/uart/uart.c +++ b/src/platform/mega_avr/common/hal/uart/uart.c @@ -27,7 +27,7 @@ status_t uart_setup(uart_port_t *port, direction_t d, parity_t p) { status_t ret = success; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); MMIO8(port->baddr + UCSRA_OFFSET) = 0x00; platform_clk_en(port->clk_id); vret_t vres; @@ -94,7 +94,7 @@ status_t uart_setup(uart_port_t *port, direction_t d, parity_t p) status_t uart_shutdown(uart_port_t *port) { status_t ret = success; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); if(port->tx_irq) { ret |= uart_tx_int_dis(port); @@ -140,7 +140,7 @@ bool uart_frame_error(const uart_port_t *port) status_t uart_tx(const uart_port_t *port, const char data) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); while(!uart_buffer_available(port)) arch_nop(); MMIO8(port->baddr + UDR_OFFSET) = data; @@ -149,7 +149,7 @@ status_t uart_tx(const uart_port_t *port, const char data) status_t uart_rx(const uart_port_t *port, char *data) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); if(uart_frame_error(port)) return error_driver_data; *data = MMIO8(port->baddr + UDR_OFFSET); @@ -158,28 +158,28 @@ status_t uart_rx(const uart_port_t *port, char *data) status_t uart_tx_int_en(const uart_port_t *port) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); MMIO8(port->baddr + UCSRB_OFFSET) |= (1 << TXCIE); return success; } status_t uart_tx_int_dis(const uart_port_t *port) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); MMIO8(port->baddr + UCSRB_OFFSET) &= ~(1 << TXCIE); return success; } status_t uart_rx_int_en(const uart_port_t *port) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); MMIO8(port->baddr + UCSRB_OFFSET) |= (1 << RXCIE); return success; } status_t uart_rx_int_dis(const uart_port_t *port) { - assert(port); + RET_ON_FAIL(port, error_inval_pointer); MMIO8(port->baddr + UCSRB_OFFSET) &= ~(1 << RXCIE); return success; } diff --git a/src/platform/mega_avr/common/hal/wdt/wdt.c b/src/platform/mega_avr/common/hal/wdt/wdt.c index 4421c1d3..2fc1590c 100644 --- a/src/platform/mega_avr/common/hal/wdt/wdt.c +++ b/src/platform/mega_avr/common/hal/wdt/wdt.c @@ -61,7 +61,7 @@ status_t wdt_setup(const wdt_port_t *port) { status_t ret; istate_t istate; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); if(port->wdt_handler == NULL) return error_func_inval_arg; @@ -93,7 +93,7 @@ status_t wdt_setup(const wdt_port_t *port) status_t wdt_shutdown(const wdt_port_t *port) { istate_t istate; - assert(port); + RET_ON_FAIL(port, error_inval_pointer); lock_acquire(&wdt_lock); arch_di_save_state(&istate); arch_wdt_reset(); @@ -123,8 +123,8 @@ status_t wdt_set_timeout(const wdt_port_t *port) status_t ret = success; uint8_t timeout; istate_t istate; - assert(port); - assert(port->timeout <= 9); + RET_ON_FAIL(port, error_inval_pointer); + RET_ON_FAIL(port->timeout <= 9, error_driver_data); timeout = get_timeout(port->timeout); if(timeout) @@ -153,7 +153,6 @@ status_t wdt_set_timeout(const wdt_port_t *port) */ void wdt_hush(const wdt_port_t *port _UNUSED) { - assert(port); arch_wdt_reset(); } @@ -166,10 +165,9 @@ void wdt_hush(const wdt_port_t *port _UNUSED) * * @return status: return the execution status of wdt_sre */ -status_t wdt_sre(const wdt_port_t *port) +status_t wdt_sre(const wdt_port_t *port _UNUSED) { istate_t istate; - assert(port); uint8_t val = MMIO8(WDTCSR); val |= (1 << WDE); @@ -195,10 +193,9 @@ status_t wdt_sre(const wdt_port_t *port) * * @return status: return the execution status of wdt_srd */ -status_t wdt_srd(const wdt_port_t *port) +status_t wdt_srd(const wdt_port_t *port _UNUSED) { istate_t istate; - assert(port); uint8_t val = MMIO8(WDTCSR); val &= ~(1 << WDE); diff --git a/src/platform/sifive/common_fe310/hal/clint/clint.c b/src/platform/sifive/common_fe310/hal/clint/clint.c index bd1adf56..a21ffc30 100644 --- a/src/platform/sifive/common_fe310/hal/clint/clint.c +++ b/src/platform/sifive/common_fe310/hal/clint/clint.c @@ -58,7 +58,6 @@ static status_t clint_exit() status_t clint_send_softirq(size_t core_id) { - assert(port->baddr); if(core_id >= N_CORES) return error_func_inval_arg; MMIO32(port->baddr + MSIP_OFFSET(core_id)) = 1; @@ -68,7 +67,6 @@ status_t clint_send_softirq(size_t core_id) status_t clint_config_tcmp(size_t core_id, uint64_t value) { - assert(port->baddr); if(core_id >= N_CORES) return error_func_inval_arg; MMIO64(port->baddr + MTCMP_OFFSET(core_id)) = value; @@ -78,7 +76,6 @@ status_t clint_config_tcmp(size_t core_id, uint64_t value) uint64_t clint_read_time() { - assert(port->baddr); uint64_t time_stamp; time_stamp = MMIO64(port->baddr + MTIME_OFFSET); return time_stamp; From 4ca5849d585d1058e275e7eba426c1cdb419020a Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Mon, 1 Jan 2024 07:57:48 +0530 Subject: [PATCH 07/14] Fix for arch_ei_restore_state Issue: #267 --- src/arch/riscv/32/i/terravisor/arch.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/arch/riscv/32/i/terravisor/arch.c b/src/arch/riscv/32/i/terravisor/arch.c index 5f0c286c..e5196892 100644 --- a/src/arch/riscv/32/i/terravisor/arch.c +++ b/src/arch/riscv/32/i/terravisor/arch.c @@ -93,6 +93,7 @@ void arch_di_save_state(istate_t *istate) void arch_ei_restore_state(istate_t *istate) { asm volatile("csrs mie, %0" : : "r" (*istate)); + arch_ei(); } static cpu_sleep_t sleep_flag[N_CORES]; From ce87773bc7e2b262d56ac57df4eab0748ebabbda Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Mon, 1 Jan 2024 08:01:05 +0530 Subject: [PATCH 08/14] Additional fixes and cosmetic updates for status codes Issue: #265 --- src/driver/driver.c | 2 +- src/include/status.h | 6 +++++- src/platform/mega_avr/common/hal/adc/adc.c | 14 +++++++------- src/platform/mega_avr/common/hal/spi/spi.c | 13 +++++++------ src/platform/sifive/common_fe310/hal/clint/clint.c | 6 ++---- src/visor/terravisor/services/driver/timer.c | 4 ++-- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/driver/driver.c b/src/driver/driver.c index e9ea2519..c56a838e 100644 --- a/src/driver/driver.c +++ b/src/driver/driver.c @@ -202,7 +202,7 @@ status_t driver_register(device_t *dev _UNUSED) ret = dev->driver_setup(); (ret == success) ? syslog(pass, "Started %s\n", dev->name) : - syslog(fail, "Couldn't start %s (Err: -%p)\n", dev->name, -ret); + syslog(fail, "Couldn't start %s (Err: %p)\n", dev->name, ret); exit: return ret; } diff --git a/src/include/status.h b/src/include/status.h index bd840311..381d030d 100644 --- a/src/include/status.h +++ b/src/include/status.h @@ -16,7 +16,7 @@ typedef enum status { - success = 0x0000, + success = 0x0000, /* Generic error */ error_generic = 0x0001, error_func_inval = 0x0002, @@ -62,6 +62,7 @@ typedef enum status error_system_irq_unlink_fail = 0x0b02, error_system_clk_caliberation = 0x0b03, error_system_prog_fail = 0x0b04, + error_system_inval_cpu = 0x0b05, /* Network related error */ error_net = 0x0c00, error_net_con_timeout = 0x0c01, @@ -88,3 +89,6 @@ typedef enum status error_list_node_exists = 0x1101, error_list_node_not_found = 0x1102, } status_t; + +#define STATUS_CHECK_POINTER(x) RET_ON_FAIL(x, error_inval_pointer) +#define STATUS_CHECK_COREID(x) RET_ON_FAIL((x <= N_CORES), error_system_inval_cpu) diff --git a/src/platform/mega_avr/common/hal/adc/adc.c b/src/platform/mega_avr/common/hal/adc/adc.c index bc4d6744..f6763e41 100644 --- a/src/platform/mega_avr/common/hal/adc/adc.c +++ b/src/platform/mega_avr/common/hal/adc/adc.c @@ -117,7 +117,7 @@ static inline status_t _adc_config_vref(adc_port_t *port, adc_ref_t vref) status_t adc_setup(adc_port_t *port) { status_t ret = success; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); ret |= platform_clk_en(port->clk_id); _adc_enable(port); ret |= _adc_set_prescaler(port); @@ -132,7 +132,7 @@ status_t adc_setup(adc_port_t *port) status_t adc_shutdown(adc_port_t *port) { status_t ret = success; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); ret |= adc_int_dis(port); _adc_disable(port); ret |= platform_clk_dis(port->clk_id); @@ -149,14 +149,14 @@ bool adc_busy(adc_port_t *port) status_t adc_int_en(adc_port_t *port) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); MMIO8(port->baddr + ADCSRA_OFFSET) |= (1 << ADIE); return success; } status_t adc_int_dis(adc_port_t *port) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); MMIO8(port->baddr + ADCSRA_OFFSET) &= ~(1 << ADIE); return success; } @@ -164,7 +164,7 @@ status_t adc_int_dis(adc_port_t *port) status_t adc_config_pin(adc_port_t *port, uint8_t pin, adc_trig_t trigger, uint8_t resolution, adc_ref_t vref) { status_t ret = success; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); if(pin > N_ADC_PINS) return error_func_inval_arg; ret |= _adc_config_vref(port, vref); @@ -178,8 +178,8 @@ status_t adc_config_pin(adc_port_t *port, uint8_t pin, adc_trig_t trigger, uint8 status_t adc_read(adc_port_t *port, uint16_t *adc_val) { status_t ret = success; - RET_ON_FAIL(port, error_inval_pointer); - RET_ON_FAIL(adc_val, error_inval_pointer); + STATUS_CHECK_POINTER(port); + STATUS_CHECK_POINTER(adc_val); if(MMIO8(port->baddr + ADMUX_OFFSET) & (1 << ADLAR)) { *adc_val = MMIO8(port->baddr + ADCH_OFFSET); diff --git a/src/platform/mega_avr/common/hal/spi/spi.c b/src/platform/mega_avr/common/hal/spi/spi.c index 9e2c3d9d..65328d08 100644 --- a/src/platform/mega_avr/common/hal/spi/spi.c +++ b/src/platform/mega_avr/common/hal/spi/spi.c @@ -26,7 +26,7 @@ status_t spi_master_setup(spi_port_t *port, dataframe_format_t df_format, clk_po status_t ret = success; uint8_t spcr_value = 0; gpio_port_t spi_mosi, spi_miso, spi_sck, spi_ss; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); platform_clk_en(port->clk_id); spcr_value |= (1 << SPE) | (1 << MSTR); switch(port->fdiv) @@ -69,7 +69,7 @@ status_t spi_slave_setup(spi_port_t *port, dataframe_format_t df_format, clk_pol status_t ret = success; uint8_t spcr_value = 0; gpio_port_t spi_mosi, spi_miso, spi_sck, spi_ss; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); platform_clk_en(port->clk_id); spcr_value |= (1 << SPE); switch(port->fdiv) @@ -121,28 +121,29 @@ bool spi_trx_done(spi_port_t *port) status_t spi_int_en(spi_port_t *port) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); MMIO8(port->baddr + SPCR_OFFSET) |= (1 << SPIE); return success; } status_t spi_int_dis(spi_port_t * port) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); MMIO8(port->baddr + SPCR_OFFSET) &= ~(1 << SPIE); return success; } status_t spi_tx(spi_port_t *port, char data) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); MMIO8(port->baddr + SPDR_OFFSET) = data; return success; } status_t spi_rx(spi_port_t *port, char *data) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); + STATUS_CHECK_POINTER(data); *data = MMIO8(port->baddr + SPDR_OFFSET); return success; } diff --git a/src/platform/sifive/common_fe310/hal/clint/clint.c b/src/platform/sifive/common_fe310/hal/clint/clint.c index a21ffc30..b62971c9 100644 --- a/src/platform/sifive/common_fe310/hal/clint/clint.c +++ b/src/platform/sifive/common_fe310/hal/clint/clint.c @@ -58,8 +58,7 @@ static status_t clint_exit() status_t clint_send_softirq(size_t core_id) { - if(core_id >= N_CORES) - return error_func_inval_arg; + STATUS_CHECK_COREID(core_id); MMIO32(port->baddr + MSIP_OFFSET(core_id)) = 1; arch_dsb(); return success; @@ -67,8 +66,7 @@ status_t clint_send_softirq(size_t core_id) status_t clint_config_tcmp(size_t core_id, uint64_t value) { - if(core_id >= N_CORES) - return error_func_inval_arg; + STATUS_CHECK_COREID(core_id); MMIO64(port->baddr + MTCMP_OFFSET(core_id)) = value; arch_dsb(); return success; diff --git a/src/visor/terravisor/services/driver/timer.c b/src/visor/terravisor/services/driver/timer.c index 77bdbd0c..f722e61b 100644 --- a/src/visor/terravisor/services/driver/timer.c +++ b/src/visor/terravisor/services/driver/timer.c @@ -93,8 +93,8 @@ status_t timer_release_device() * programs to link timer event call back functions. * * @brief This is a helper function which lets other programs to link - * timer event call back functions. It allows to link onlt 1 callback - * which will be exeuted as part of timer ISR handler. + * timer event call back functions. It allows to link only 1 callback + * which will be executed as part of timer ISR handler. * * @param[in] p: period of timer irq * @param[in] cb: call back function pointer From c33f79140665eb588c2998a742ee6c294041db2d Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Mon, 1 Jan 2024 08:39:32 +0530 Subject: [PATCH 09/14] Fixed error handling in platform timer - Minor bugfix in status check coreid Issue: #237 #265 --- src/driver/sysclk/sysclk_prci/sysclk_prci.c | 2 ++ src/include/status.h | 2 +- .../sifive/common_fe310/platform/plat_timer.c | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/driver/sysclk/sysclk_prci/sysclk_prci.c b/src/driver/sysclk/sysclk_prci/sysclk_prci.c index 3665f1f2..50ffade3 100644 --- a/src/driver/sysclk/sysclk_prci/sysclk_prci.c +++ b/src/driver/sysclk/sysclk_prci/sysclk_prci.c @@ -186,6 +186,7 @@ static void sysclk_configure_clk(call_arg_t a0, call_arg_t a1, call_arg_t a2 _UN clock_type_t type = (clock_type_t) a0; unsigned int clk = (unsigned int) a1; + ret->status = error_inval_pointer; RET_ON_FAIL(port && port->baddr && port->base_clk,); ret->p = 0; @@ -230,6 +231,7 @@ static void sysclk_get_freq(call_arg_t a0 _UNUSED, call_arg_t a1 _UNUSED, istate_t ist; unsigned int getclk; + ret->status = error_inval_pointer; RET_ON_FAIL(port && port->baddr && port->base_clk,); lock_acquire(&sysclk_key); diff --git a/src/include/status.h b/src/include/status.h index 381d030d..aeca9748 100644 --- a/src/include/status.h +++ b/src/include/status.h @@ -91,4 +91,4 @@ typedef enum status } status_t; #define STATUS_CHECK_POINTER(x) RET_ON_FAIL(x, error_inval_pointer) -#define STATUS_CHECK_COREID(x) RET_ON_FAIL((x <= N_CORES), error_system_inval_cpu) +#define STATUS_CHECK_COREID(x) RET_ON_FAIL((x < N_CORES), error_system_inval_cpu) diff --git a/src/platform/sifive/common_fe310/platform/plat_timer.c b/src/platform/sifive/common_fe310/platform/plat_timer.c index 0e6f9ab2..40bbc91d 100644 --- a/src/platform/sifive/common_fe310/platform/plat_timer.c +++ b/src/platform/sifive/common_fe310/platform/plat_timer.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -50,7 +51,13 @@ static void plat_tmr_isr(void) { arch_di_mtime(); uint64_t t = clint_read_time(); - clint_config_tcmp(arch_core_index(), (t + ticks)); + status_t ret = clint_config_tcmp(arch_core_index(), (t + ticks)); + if(ret) + { + syslog_stdout_enable(); + syslog(fail, "Failed to configure timer, Err = %p\n", ret); + plat_panic_handler(); + } arch_ei_mtime(); if(tmr_cb != NULL) @@ -119,7 +126,13 @@ static void plat_timer_set_period(unsigned int p) ticks = plat_get_timer_ticks_msec(tm->clk); ticks *= p; nt = ticks + clint_read_time(); - clint_config_tcmp(arch_core_index(), nt); + status_t ret = clint_config_tcmp(arch_core_index(), nt); + if(ret) + { + syslog_stdout_enable(); + syslog(fail, "Failed to configure timer, Err = %p\n", ret); + plat_panic_handler(); + } arch_ei_mtime(); } From 23db466540755c75334c0abc97f6451d1b2bfa46 Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Mon, 1 Jan 2024 13:22:29 +0530 Subject: [PATCH 10/14] Updated status code on HAL Issue: #265 --- src/platform/mega_avr/common/hal/gpio/gpio.c | 22 +++++++++---------- .../mega_avr/common/hal/timer/timer.c | 8 +++---- src/platform/mega_avr/common/hal/uart/uart.c | 16 +++++++------- src/platform/mega_avr/common/hal/wdt/wdt.c | 6 ++--- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/platform/mega_avr/common/hal/gpio/gpio.c b/src/platform/mega_avr/common/hal/gpio/gpio.c index 40604b40..1d543770 100644 --- a/src/platform/mega_avr/common/hal/gpio/gpio.c +++ b/src/platform/mega_avr/common/hal/gpio/gpio.c @@ -28,7 +28,7 @@ status_t gpio_pin_alloc(gpio_port_t *port, uint8_t portID, uint8_t pinID) gpio_module_t *dp; unsigned char flag; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); lock_acquire(&gpio_lock); flag = 0; @@ -62,7 +62,7 @@ status_t gpio_pin_alloc(gpio_port_t *port, uint8_t portID, uint8_t pinID) status_t gpio_pin_mode(const gpio_port_t *port, gpio_mode_t mode) { uintptr_t pbaddr; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); uint8_t pin = port->pin; pbaddr = port->pbaddr; @@ -84,7 +84,7 @@ status_t gpio_pin_mode(const gpio_port_t *port, gpio_mode_t mode) status_t gpio_pin_free(gpio_port_t *port) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); lock_acquire(&gpio_lock); sysdbg4("Releasing GPIO Pin %d on Port, %d", port->pin, port->port); port_status[port->port] &= ~(1 << port->pin); @@ -97,21 +97,21 @@ status_t gpio_pin_free(gpio_port_t *port) status_t gpio_pin_set(const gpio_port_t *port) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); MMIO8(port->pbaddr + PORT_OFFSET) |= (1 << port->pin); return success; } status_t gpio_pin_clear(const gpio_port_t *port) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); MMIO8(port->pbaddr + PORT_OFFSET) &= ~(1 << port->pin); return success; } status_t gpio_pin_toggle(const gpio_port_t *port) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); MMIO8(port->pbaddr + PORT_OFFSET) ^= (1 << port->pin); return success; } @@ -128,7 +128,7 @@ status_t gpio_port_alloc(gpio_port_t *port, uint8_t portID) gpio_module_t *dp; unsigned char flag = 0; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); lock_acquire(&gpio_lock); if(port_status[portID]) @@ -160,7 +160,7 @@ status_t gpio_port_alloc(gpio_port_t *port, uint8_t portID) status_t gpio_port_mode(const gpio_port_t *port, gpio_mode_t mode) { uintptr_t pbaddr; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); uint8_t value = port->pin; pbaddr = port->pbaddr; @@ -182,7 +182,7 @@ status_t gpio_port_mode(const gpio_port_t *port, gpio_mode_t mode) status_t gpio_port_free(gpio_port_t *port) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); lock_acquire(&gpio_lock); sysdbg4("Releasing GPIO Port, %d", port->port); port_status[port->port] = 0; @@ -195,7 +195,7 @@ status_t gpio_port_free(gpio_port_t *port) status_t gpio_port_write(const gpio_port_t *port, gpio_parallel_t val) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); // MegaAVR has 8-bit i/o modules, value to write should be 8-bit wide MMIO8(port->pbaddr + PORT_OFFSET) = (uint8_t)(val & 0xff); return success; @@ -203,7 +203,7 @@ status_t gpio_port_write(const gpio_port_t *port, gpio_parallel_t val) status_t gpio_port_read(const gpio_port_t *port, gpio_parallel_t *val) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); // MegaAVR has 8-bit i/o modules, value returned is 8-bit wide *val = (gpio_parallel_t)MMIO8(port->pbaddr + PIN_OFFSET); return success; diff --git a/src/platform/mega_avr/common/hal/timer/timer.c b/src/platform/mega_avr/common/hal/timer/timer.c index 524b0df7..801e49fd 100644 --- a/src/platform/mega_avr/common/hal/timer/timer.c +++ b/src/platform/mega_avr/common/hal/timer/timer.c @@ -27,7 +27,7 @@ status_t timer_setup(const timer_port_t *port, unsigned int mode, unsigned int p { status_t ret; unsigned id; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); id = port->port_id & 0xf0; ret = platform_clk_en(port->clk_id); if(id == 0 || id == 0x20) @@ -59,7 +59,7 @@ status_t timer_shutdown(const timer_port_t *port) { status_t ret = success; unsigned id; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); id = port->port_id & 0xf0; if(id == 0 || id == 0x20) { @@ -81,7 +81,7 @@ status_t timer_shutdown(const timer_port_t *port) status_t timer_read(const timer_port_t *port, size_t *value) { unsigned id; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); id = port->port_id & 0xf0; if(id == 0 || id == 0x20) *value = timer8_read(port); @@ -95,7 +95,7 @@ status_t timer_pwm_set(const timer_port_t *port, bool invert, size_t value) { status_t ret = success; unsigned id; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); id = port->port_id & 0xf0; if(id == 0 || id == 0x20) { diff --git a/src/platform/mega_avr/common/hal/uart/uart.c b/src/platform/mega_avr/common/hal/uart/uart.c index af452e4b..0243875f 100644 --- a/src/platform/mega_avr/common/hal/uart/uart.c +++ b/src/platform/mega_avr/common/hal/uart/uart.c @@ -27,7 +27,7 @@ status_t uart_setup(uart_port_t *port, direction_t d, parity_t p) { status_t ret = success; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); MMIO8(port->baddr + UCSRA_OFFSET) = 0x00; platform_clk_en(port->clk_id); vret_t vres; @@ -94,7 +94,7 @@ status_t uart_setup(uart_port_t *port, direction_t d, parity_t p) status_t uart_shutdown(uart_port_t *port) { status_t ret = success; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); if(port->tx_irq) { ret |= uart_tx_int_dis(port); @@ -140,7 +140,7 @@ bool uart_frame_error(const uart_port_t *port) status_t uart_tx(const uart_port_t *port, const char data) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); while(!uart_buffer_available(port)) arch_nop(); MMIO8(port->baddr + UDR_OFFSET) = data; @@ -149,7 +149,7 @@ status_t uart_tx(const uart_port_t *port, const char data) status_t uart_rx(const uart_port_t *port, char *data) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); if(uart_frame_error(port)) return error_driver_data; *data = MMIO8(port->baddr + UDR_OFFSET); @@ -158,28 +158,28 @@ status_t uart_rx(const uart_port_t *port, char *data) status_t uart_tx_int_en(const uart_port_t *port) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); MMIO8(port->baddr + UCSRB_OFFSET) |= (1 << TXCIE); return success; } status_t uart_tx_int_dis(const uart_port_t *port) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); MMIO8(port->baddr + UCSRB_OFFSET) &= ~(1 << TXCIE); return success; } status_t uart_rx_int_en(const uart_port_t *port) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); MMIO8(port->baddr + UCSRB_OFFSET) |= (1 << RXCIE); return success; } status_t uart_rx_int_dis(const uart_port_t *port) { - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); MMIO8(port->baddr + UCSRB_OFFSET) &= ~(1 << RXCIE); return success; } diff --git a/src/platform/mega_avr/common/hal/wdt/wdt.c b/src/platform/mega_avr/common/hal/wdt/wdt.c index 2fc1590c..a4732543 100644 --- a/src/platform/mega_avr/common/hal/wdt/wdt.c +++ b/src/platform/mega_avr/common/hal/wdt/wdt.c @@ -61,7 +61,7 @@ status_t wdt_setup(const wdt_port_t *port) { status_t ret; istate_t istate; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); if(port->wdt_handler == NULL) return error_func_inval_arg; @@ -93,7 +93,7 @@ status_t wdt_setup(const wdt_port_t *port) status_t wdt_shutdown(const wdt_port_t *port) { istate_t istate; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); lock_acquire(&wdt_lock); arch_di_save_state(&istate); arch_wdt_reset(); @@ -123,7 +123,7 @@ status_t wdt_set_timeout(const wdt_port_t *port) status_t ret = success; uint8_t timeout; istate_t istate; - RET_ON_FAIL(port, error_inval_pointer); + STATUS_CHECK_POINTER(port); RET_ON_FAIL(port->timeout <= 9, error_driver_data); timeout = get_timeout(port->timeout); From 6038f345acd79eee8fd9601cc3d7d276bb61adef Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Mon, 1 Jan 2024 14:39:22 +0530 Subject: [PATCH 11/14] Add use_prng guard for bootloader limitations Issue: #236 --- .vscode/settings.json | 2 +- src/arch/riscv/32/i/terravisor/arch.c | 1 + src/arch/riscv/32/i/terravisor/init.c | 2 ++ src/platform/sifive/common_fe310/platform/platform.c | 4 ++++ src/platform/sifive/fe310g002-bl/config.mk | 8 ++++++++ src/platform/sifive/fe310g002/config.mk | 7 +++++++ src/platform/sifive/qemu-sifive-e-bl/config.mk | 2 ++ src/platform/sifive/qemu-sifive-e/config.mk | 7 +++++++ 8 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index a87eceea..743059ae 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,7 +20,7 @@ "editor.trimAutoWhitespace": true, "editor.autoClosingQuotes": "always", "editor.autoClosingBrackets": "always", - "editor.wordBasedSuggestions": "matchingDocuments", + "editor.wordBasedSuggestions": "true", "editor.insertSpaces": false, "editor.autoIndent": "advanced", "editor.detectIndentation": true, diff --git a/src/arch/riscv/32/i/terravisor/arch.c b/src/arch/riscv/32/i/terravisor/arch.c index 45f41db4..cd526266 100644 --- a/src/arch/riscv/32/i/terravisor/arch.c +++ b/src/arch/riscv/32/i/terravisor/arch.c @@ -161,6 +161,7 @@ _WEAK void arch_unhandled_irq() while(1) arch_wfi(); } + /** * arch_rseed_capture * diff --git a/src/arch/riscv/32/i/terravisor/init.c b/src/arch/riscv/32/i/terravisor/init.c index f6b780bb..f1594330 100644 --- a/src/arch/riscv/32/i/terravisor/init.c +++ b/src/arch/riscv/32/i/terravisor/init.c @@ -24,8 +24,10 @@ void _NAKED init() { arch_di(); asm volatile("la tp, _tls_start"); +#if USE_PRNG /* Capture unique seed value before memory initialization */ arch_rseed_capture(); +#endif /* Boot framework */ #if CCSMP == 0 engine(); diff --git a/src/platform/sifive/common_fe310/platform/platform.c b/src/platform/sifive/common_fe310/platform/platform.c index a1ac700d..ee8c6684 100644 --- a/src/platform/sifive/common_fe310/platform/platform.c +++ b/src/platform/sifive/common_fe310/platform/platform.c @@ -25,13 +25,17 @@ void platform_early_setup() { status_t ret = success; +#if USE_PRNG unsigned int temp_randomnumber = rand(); +#endif ret |= platform_copy_data(); ret |= platform_copy_itim(); ret |= platform_bss_clear(); ret |= platform_init_heap(); ret |= platform_resources_setup(); +#if USE_PRNG srand(temp_randomnumber); +#endif syslog_stdout_disable(); driver_setup("mslog"); diff --git a/src/platform/sifive/fe310g002-bl/config.mk b/src/platform/sifive/fe310g002-bl/config.mk index b3c3b1a4..47e4b9ec 100644 --- a/src/platform/sifive/fe310g002-bl/config.mk +++ b/src/platform/sifive/fe310g002-bl/config.mk @@ -104,4 +104,12 @@ $(eval $(call add_define,BOOTLOADER)) USE_TIMER ?= 0 $(eval $(call add_define,USE_TIMER)) #====================================================================== + +#====================================================================== +# Bootloader +# \ PRNG: Use upgraded PRNG +#====================================================================== +USE_PRNG ?= 0 +$(eval $(call add_define,USE_PRNG)) +#====================================================================== #====================================================================== diff --git a/src/platform/sifive/fe310g002/config.mk b/src/platform/sifive/fe310g002/config.mk index fb8cae0e..46f1a1eb 100644 --- a/src/platform/sifive/fe310g002/config.mk +++ b/src/platform/sifive/fe310g002/config.mk @@ -98,3 +98,10 @@ $(eval $(call add_define,PRCI_CLK)) USE_TIMER ?= 1 $(eval $(call add_define,USE_TIMER)) #====================================================================== + +#====================================================================== +# PRNG: Use upgraded prng +#====================================================================== +USE_PRNG ?= 1 +$(eval $(call add_define,USE_PRNG)) +#====================================================================== diff --git a/src/platform/sifive/qemu-sifive-e-bl/config.mk b/src/platform/sifive/qemu-sifive-e-bl/config.mk index f74229dd..dde401a5 100644 --- a/src/platform/sifive/qemu-sifive-e-bl/config.mk +++ b/src/platform/sifive/qemu-sifive-e-bl/config.mk @@ -96,6 +96,8 @@ $(eval $(call add_define,PRCI_CLK)) # Bootload Configuration #====================================================================== USE_TIMER ?= 0 +USE_PRNG := 0 $(eval $(call add_define,USE_TIMER)) +$(eval $(call add_define,USE_PRNG)) $(eval $(call add_define,BOOTLOADER)) #====================================================================== diff --git a/src/platform/sifive/qemu-sifive-e/config.mk b/src/platform/sifive/qemu-sifive-e/config.mk index 621d25f0..60aeb7d6 100644 --- a/src/platform/sifive/qemu-sifive-e/config.mk +++ b/src/platform/sifive/qemu-sifive-e/config.mk @@ -98,3 +98,10 @@ $(eval $(call add_define,PRCI_CLK)) USE_TIMER ?= 1 $(eval $(call add_define,USE_TIMER)) #====================================================================== + +#====================================================================== +# PRNG: Use upgraded prng +#====================================================================== +USE_PRNG ?= 1 +$(eval $(call add_define,USE_PRNG)) +#====================================================================== From 66f7eb91e90fbc6db51aad1e25e72c66f998af06 Mon Sep 17 00:00:00 2001 From: Shubhangi Ingle Date: Wed, 3 Jan 2024 19:22:15 +0530 Subject: [PATCH 12/14] Pseudo Random number generation update Issue: #236 --- .vscode/settings.json | 2 +- src/arch/riscv/32/i/terravisor/arch.c | 11 +++++++++++ src/arch/riscv/32/i/terravisor/include/arch.h | 1 + src/arch/riscv/32/i/terravisor/init.c | 3 ++- src/platform/sifive/common_fe310/platform/platform.c | 6 ++++-- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index afd7a788..a87eceea 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,7 +20,7 @@ "editor.trimAutoWhitespace": true, "editor.autoClosingQuotes": "always", "editor.autoClosingBrackets": "always", - "editor.wordBasedSuggestions": true, + "editor.wordBasedSuggestions": "matchingDocuments", "editor.insertSpaces": false, "editor.autoIndent": "advanced", "editor.detectIndentation": true, diff --git a/src/arch/riscv/32/i/terravisor/arch.c b/src/arch/riscv/32/i/terravisor/arch.c index e5196892..45f41db4 100644 --- a/src/arch/riscv/32/i/terravisor/arch.c +++ b/src/arch/riscv/32/i/terravisor/arch.c @@ -16,6 +16,7 @@ #include #include #include +#include static void arch_vcall_handler() { @@ -160,3 +161,13 @@ _WEAK void arch_unhandled_irq() while(1) arch_wfi(); } +/** + * arch_rseed_capture + * + * @brief This function is intended to capture unique seed value + */ +void arch_rseed_capture() +{ + extern uintptr_t *_bss_start; + srand(*_bss_start); +} diff --git a/src/arch/riscv/32/i/terravisor/include/arch.h b/src/arch/riscv/32/i/terravisor/include/arch.h index c60066f7..58751f2e 100644 --- a/src/arch/riscv/32/i/terravisor/include/arch.h +++ b/src/arch/riscv/32/i/terravisor/include/arch.h @@ -181,3 +181,4 @@ static inline void arch_dmb() bool arch_suspended_state_was(cpu_sleep_t); void arch_signal_suspend(cpu_sleep_t); void arch_signal_resume(void); +void arch_rseed_capture(); diff --git a/src/arch/riscv/32/i/terravisor/init.c b/src/arch/riscv/32/i/terravisor/init.c index bda25383..f6b780bb 100644 --- a/src/arch/riscv/32/i/terravisor/init.c +++ b/src/arch/riscv/32/i/terravisor/init.c @@ -24,8 +24,9 @@ void _NAKED init() { arch_di(); asm volatile("la tp, _tls_start"); + /* Capture unique seed value before memory initialization */ + arch_rseed_capture(); /* Boot framework */ - #if CCSMP == 0 engine(); #else diff --git a/src/platform/sifive/common_fe310/platform/platform.c b/src/platform/sifive/common_fe310/platform/platform.c index db5f52b6..a1ac700d 100644 --- a/src/platform/sifive/common_fe310/platform/platform.c +++ b/src/platform/sifive/common_fe310/platform/platform.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -20,15 +21,17 @@ #include #include + void platform_early_setup() { status_t ret = success; - + unsigned int temp_randomnumber = rand(); ret |= platform_copy_data(); ret |= platform_copy_itim(); ret |= platform_bss_clear(); ret |= platform_init_heap(); ret |= platform_resources_setup(); + srand(temp_randomnumber); syslog_stdout_disable(); driver_setup("mslog"); @@ -110,4 +113,3 @@ void platform_cpu_setup() arch_ei(); return; } - From 3fe5b81342ba797cae8e4b9617fde4665002b767 Mon Sep 17 00:00:00 2001 From: Shubhangi Ingle Date: Wed, 3 Jan 2024 21:12:27 +0530 Subject: [PATCH 13/14] Added support for true random number generation for avr platform Issue: #236 --- .vscode/settings.json | 4 +--- src/arch/avr/8/common_5x_6/terravisor/arch.c | 12 ++++++++++++ src/arch/avr/8/common_5x_6/terravisor/include/arch.h | 3 +++ src/arch/avr/8/common_5x_6/terravisor/init.c | 4 +++- src/platform/mega_avr/common/platform/platform.c | 8 ++++---- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index afd7a788..1846aa58 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -39,9 +39,7 @@ "*.sx": "c", "*.{c,c.dev.c.temp,c.tmp,c.old,h,h.dev,h.old,h.temp,h.tmp)": "C", "*.{cpp,cpp.dev,cpp.temp,cpp.tmp,cpp.old}": "C++", - "*.{S,S.old,S.dev.S.temp,S.tmp,s.old,s.temp,s.tmp,s.dev,asm,asm.old,asm.dev.asm.temp,asm.tmp,inc,inc.old,inc.temp,inc.tmp,ld,ld.old,ld.temp,ld.tmp,ld.sx,ld.sx.old,ld.sx.temp,ld.sx.tmp,lst}": "coffeescript", - "cc_os_sched.h": "c", - "cc_os.h": "c" + "*.{S,S.old,S.dev.S.temp,S.tmp,s.old,s.temp,s.tmp,s.dev,asm,asm.old,asm.dev.asm.temp,asm.tmp,inc,inc.old,inc.temp,inc.tmp,ld,ld.old,ld.temp,ld.tmp,ld.sx,ld.sx.old,ld.sx.temp,ld.sx.tmp,lst}": "coffeescript" }, "files.autoSave": "afterDelay", "files.autoSaveDelay": 100, diff --git a/src/arch/avr/8/common_5x_6/terravisor/arch.c b/src/arch/avr/8/common_5x_6/terravisor/arch.c index b1db93e9..7dd6f095 100644 --- a/src/arch/avr/8/common_5x_6/terravisor/arch.c +++ b/src/arch/avr/8/common_5x_6/terravisor/arch.c @@ -18,6 +18,7 @@ #include #include #include +#include /** * arch_early_setup - This function is called in the early stages of boot @@ -139,3 +140,14 @@ void arch_signal_resume(void) { sleep_flag = resume; } + +/** + * arch_rseed_capture + * + * @brief This function is intended to capture unique seed value + */ +void arch_rseed_capture() +{ + extern uintptr_t *_bss_start; + srand(*_bss_start); +} diff --git a/src/arch/avr/8/common_5x_6/terravisor/include/arch.h b/src/arch/avr/8/common_5x_6/terravisor/include/arch.h index 5c7f212b..ec195ffb 100644 --- a/src/arch/avr/8/common_5x_6/terravisor/include/arch.h +++ b/src/arch/avr/8/common_5x_6/terravisor/include/arch.h @@ -119,3 +119,6 @@ bool arch_suspended_state_was(cpu_sleep_t); void arch_signal_suspend(cpu_sleep_t); void arch_signal_resume(void); #endif + +void arch_rseed_capture(); + diff --git a/src/arch/avr/8/common_5x_6/terravisor/init.c b/src/arch/avr/8/common_5x_6/terravisor/init.c index 3a640c63..f5177381 100644 --- a/src/arch/avr/8/common_5x_6/terravisor/init.c +++ b/src/arch/avr/8/common_5x_6/terravisor/init.c @@ -13,6 +13,7 @@ #include #include #include +#include extern uint16_t stack_start; @@ -33,7 +34,8 @@ void _NAKED init() { /* Set resisters to architecturally defined reset */ zero_reg(); - + /* Capture unique seed value before memory initialization */ + arch_rseed_capture(); /* Boot framework */ engine(); diff --git a/src/platform/mega_avr/common/platform/platform.c b/src/platform/mega_avr/common/platform/platform.c index 6af19823..c67657d5 100644 --- a/src/platform/mega_avr/common/platform/platform.c +++ b/src/platform/mega_avr/common/platform/platform.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -37,19 +38,19 @@ uint8_t reset_syndrome; * Function like bss clear, data copy, clock reset, etc are called * in this function. As reset_syndrome is bss variable, it must be * updated only after the bss is cleared. Ideally it should be - * updated at last. < ! > This function should be made to run on + * updated at last. < ! > This function should be made to run on * boot core only! */ void platform_early_setup() { status_t ret = success; - + unsigned int temp_randomnumber = rand(); /* Setup platform memories */ ret |= platform_copy_data(); ret |= platform_bss_clear(); ret |= platform_init_heap(); ret |= platform_resources_setup(); - + srand(temp_randomnumber); /* Setup memory syslogger */ driver_setup("mslog"); @@ -133,4 +134,3 @@ void _NAKED plat_panic_handler_callback() syslog(info, "SP=%p\tSREG = %p\n", frame, frame->sreg); exit(EXIT_FAILURE); } - From 22922b107fa9af70df41886442d5994bdbfc3634 Mon Sep 17 00:00:00 2001 From: Akash Kollipara Date: Mon, 1 Jan 2024 16:04:28 +0530 Subject: [PATCH 14/14] Cosmetic Fix --- src/arch/avr/8/common_5x_6/terravisor/arch.c | 4 ++-- src/arch/avr/8/common_5x_6/terravisor/init.c | 2 +- src/arch/riscv/32/i/terravisor/arch.c | 4 ++-- src/arch/riscv/32/i/terravisor/init.c | 4 ++-- src/platform/mega_avr/common/platform/platform.c | 2 +- src/platform/sifive/common_fe310/platform/platform.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/arch/avr/8/common_5x_6/terravisor/arch.c b/src/arch/avr/8/common_5x_6/terravisor/arch.c index 7dd6f095..dc7c6230 100644 --- a/src/arch/avr/8/common_5x_6/terravisor/arch.c +++ b/src/arch/avr/8/common_5x_6/terravisor/arch.c @@ -148,6 +148,6 @@ void arch_signal_resume(void) */ void arch_rseed_capture() { - extern uintptr_t *_bss_start; - srand(*_bss_start); + extern uintptr_t *_bss_start; + srand(*_bss_start); } diff --git a/src/arch/avr/8/common_5x_6/terravisor/init.c b/src/arch/avr/8/common_5x_6/terravisor/init.c index f5177381..fab85dc0 100644 --- a/src/arch/avr/8/common_5x_6/terravisor/init.c +++ b/src/arch/avr/8/common_5x_6/terravisor/init.c @@ -35,7 +35,7 @@ void _NAKED init() /* Set resisters to architecturally defined reset */ zero_reg(); /* Capture unique seed value before memory initialization */ - arch_rseed_capture(); + arch_rseed_capture(); /* Boot framework */ engine(); diff --git a/src/arch/riscv/32/i/terravisor/arch.c b/src/arch/riscv/32/i/terravisor/arch.c index cd526266..def7d996 100644 --- a/src/arch/riscv/32/i/terravisor/arch.c +++ b/src/arch/riscv/32/i/terravisor/arch.c @@ -169,6 +169,6 @@ _WEAK void arch_unhandled_irq() */ void arch_rseed_capture() { - extern uintptr_t *_bss_start; - srand(*_bss_start); + extern uintptr_t *_bss_start; + srand(*_bss_start); } diff --git a/src/arch/riscv/32/i/terravisor/init.c b/src/arch/riscv/32/i/terravisor/init.c index f1594330..b4e62202 100644 --- a/src/arch/riscv/32/i/terravisor/init.c +++ b/src/arch/riscv/32/i/terravisor/init.c @@ -25,8 +25,8 @@ void _NAKED init() arch_di(); asm volatile("la tp, _tls_start"); #if USE_PRNG - /* Capture unique seed value before memory initialization */ - arch_rseed_capture(); + /* Capture unique seed value before memory initialization */ + arch_rseed_capture(); #endif /* Boot framework */ #if CCSMP == 0 diff --git a/src/platform/mega_avr/common/platform/platform.c b/src/platform/mega_avr/common/platform/platform.c index c67657d5..4bc99ff2 100644 --- a/src/platform/mega_avr/common/platform/platform.c +++ b/src/platform/mega_avr/common/platform/platform.c @@ -50,7 +50,7 @@ void platform_early_setup() ret |= platform_bss_clear(); ret |= platform_init_heap(); ret |= platform_resources_setup(); - srand(temp_randomnumber); + srand(temp_randomnumber); /* Setup memory syslogger */ driver_setup("mslog"); diff --git a/src/platform/sifive/common_fe310/platform/platform.c b/src/platform/sifive/common_fe310/platform/platform.c index ee8c6684..c743a714 100644 --- a/src/platform/sifive/common_fe310/platform/platform.c +++ b/src/platform/sifive/common_fe310/platform/platform.c @@ -26,7 +26,7 @@ void platform_early_setup() { status_t ret = success; #if USE_PRNG - unsigned int temp_randomnumber = rand(); + unsigned int temp_randomnumber = rand(); #endif ret |= platform_copy_data(); ret |= platform_copy_itim();