Trying to chase down why __libc_init_array isnt working yet

This commit is contained in:
Ben V. Brown
2022-04-18 22:27:25 +10:00
parent ecf36b9b0a
commit bb28bb45b5
8 changed files with 202 additions and 131 deletions

View File

@@ -80,6 +80,70 @@ SECTIONS
__text_code_end__ = .; __text_code_end__ = .;
} > xip_memory } > xip_memory
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
} >xip_memory AT>xip_memory
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
PROVIDE_HIDDEN (__init_array_end = .);
} >xip_memory AT>xip_memory
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
PROVIDE_HIDDEN (__fini_array_end = .);
} >xip_memory AT>xip_memory
.ctors :
{
/* gcc uses crtbegin.o to find the start of
* the constructors, so we make sure it is
* first. Because this is a wildcard, it
* doesn't matter if the user does not
* actually link against crtbegin.o; the
* linker won't look for a file to match a
* wildcard. The wildcard also means that it
* doesn't matter which directory crtbegin.o
* is in.
*/
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
* the crtend.o file until after the sorted ctors.
* The .ctor section from the crtend file contains the
* end of ctors marker and it must be last
*/
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
} >xip_memory AT>xip_memory
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
} >xip_memory AT>xip_memory
.lalign :
{
. = ALIGN(4);
PROVIDE( _data_lma = . );
} >xip_memory AT>xip_memory
. = ALIGN(4); . = ALIGN(4);
__itcm_load_addr = .; __itcm_load_addr = .;

View File

@@ -78,11 +78,20 @@ _enter:
/* start load code to itcm like. */ /* start load code to itcm like. */
call start_load call start_load
// Register at exit cleanup (not required for embedded)
// la a0, __libc_fini_array
// call atexit
/* Call C/C++ constructor start up code */
call __libc_init_array
jal System_Post_Init jal System_Post_Init
/* At this point we can enter the C runtime's startup file. The arguments /* At this point we can enter the C runtime's startup file. The arguments
* to this function are designed to match those provided to the SEE, just * to this function are designed to match those provided to the SEE, just
* so we don't have to write another ABI. */ * so we don't have to write another ABI. */
//Sets argv,argc to 0/null
csrr a0, mhartid csrr a0, mhartid
li a1, 0 li a1, 0
li a2, 0 li a2, 0

View File

@@ -21,8 +21,8 @@
* *
*/ */
#include <stdint.h>
#include "bl702.h" #include "bl702.h"
#include <stdint.h>
#define __STARTUP_CLEAR_BSS 1 #define __STARTUP_CLEAR_BSS 1
@@ -59,8 +59,7 @@ extern uint32_t __HeapLimit;
// extern uint32_t __zero_table_start__; // extern uint32_t __zero_table_start__;
// extern uint32_t __zero_table_end__; // extern uint32_t __zero_table_end__;
void start_load(void) void start_load(void) {
{
uint32_t *pSrc, *pDest; uint32_t *pSrc, *pDest;
uint32_t *pTable __attribute__((unused)); uint32_t *pTable __attribute__((unused));
@@ -96,7 +95,7 @@ void start_load(void)
*pDest++ = *pSrc++; *pDest++ = *pSrc++;
} }
#ifdef __STARTUP_CLEAR_BSS // #ifdef __STARTUP_CLEAR_BSS
/* Single BSS section scheme. /* Single BSS section scheme.
* *
* The BSS section is specified by following symbols * The BSS section is specified by following symbols
@@ -111,5 +110,5 @@ void start_load(void)
*pDest++ = 0ul; *pDest++ = 0ul;
} }
#endif // #endif
} }

View File

@@ -27,8 +27,7 @@
#ifdef BFLB_EFLASH_LOADER #ifdef BFLB_EFLASH_LOADER
#include "bl702_usb.h" #include "bl702_usb.h"
void USB_DoNothing_IRQHandler(void) void USB_DoNothing_IRQHandler(void) {
{
/* clear all USB int sts */ /* clear all USB int sts */
USB_Clr_IntStatus(32); USB_Clr_IntStatus(32);
} }
@@ -42,21 +41,20 @@ void USB_DoNothing_IRQHandler(void)
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
Vector Table Vector Table
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
#define VECT_TAB_OFFSET 0x00 /*!< Vector Table base offset field. #define VECT_TAB_OFFSET \
0x00 /*!< Vector Table base offset field. \
This value must be a multiple of 0x200. */ This value must be a multiple of 0x200. */
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
System initialization function System initialization function
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void system_bor_init(void) void system_bor_init(void) {
{
HBN_BOR_CFG_Type borCfg = {0 /* pu_bor */, 0 /* irq_bor_en */, 1 /* bor_vth */, 0 /* bor_sel */}; HBN_BOR_CFG_Type borCfg = {0 /* pu_bor */, 0 /* irq_bor_en */, 1 /* bor_vth */, 0 /* bor_sel */};
HBN_Set_BOR_Cfg(&borCfg); HBN_Set_BOR_Cfg(&borCfg);
} }
void SystemInit(void) void SystemInit(void) {
{
uint32_t *p; uint32_t *p;
uint32_t i = 0; uint32_t i = 0;
uint32_t tmpVal = 0; uint32_t tmpVal = 0;
@@ -129,14 +127,13 @@ void SystemInit(void)
#ifdef BFLB_EFLASH_LOADER #ifdef BFLB_EFLASH_LOADER
Interrupt_Handler_Register(USB_IRQn, USB_DoNothing_IRQHandler); Interrupt_Handler_Register(USB_IRQn, USB_DoNothing_IRQHandler);
#endif #endif
/* init bor for all platform */ /* init for for all platform */
system_bor_init(); system_bor_init();
/* global IRQ enable */ /* global IRQ enable */
__enable_irq(); __enable_irq();
} }
void System_Post_Init(void) void System_Post_Init(void) {
{
PDS_Trim_RC32M(); PDS_Trim_RC32M();
HBN_Trim_RC32K(); HBN_Trim_RC32K();
} }

View File

@@ -133,7 +133,7 @@
#define MIN_BOOST_TEMP_C 250 // The min settable temp for boost mode °C #define MIN_BOOST_TEMP_C 250 // The min settable temp for boost mode °C
#define MIN_BOOST_TEMP_F 480 // The min settable temp for boost mode °F #define MIN_BOOST_TEMP_F 480 // The min settable temp for boost mode °F
#define POW_PD 0 #define POW_PD 1
#define POW_QC 0 #define POW_QC 0
#define POW_DC 1 #define POW_DC 1
#define POW_QC_20V 1 #define POW_QC_20V 1

View File

@@ -60,9 +60,11 @@ bool USBPowerDelivery::negotiationComplete() {
} }
bool USBPowerDelivery::fusbPresent() { bool USBPowerDelivery::fusbPresent() {
if (detectionState == 0) { if (detectionState == 0) {
MSG((char *)"FUSB Probe\r\n");
if (fusb.fusb_read_id()) { if (fusb.fusb_read_id()) {
detectionState = 1; detectionState = 1;
} }
MSG((char *)"FUSB Probe - %d\r\n", detectionState);
} }
return detectionState == 1; return detectionState == 1;
} }

View File

@@ -25,7 +25,7 @@ void startPOWTask(void const *argument __unused) {
postRToSInit(); postRToSInit();
// You have to run this once we are willing to answer PD messages // You have to run this once we are willing to answer PD messages
// Setting up too early can mean that we miss the ~20ms window to respond on some chargers // Setting up too early can mean that we miss the ~20ms window to respond on some chargers
// MSG((char *)"POW_PD\r\n"); MSG((char *)"POW_PD\r\n");
#if POW_PD #if POW_PD
USBPowerDelivery::start(); USBPowerDelivery::start();
// Crank the handle at boot until we are stable and waiting for IRQ // Crank the handle at boot until we are stable and waiting for IRQ

View File

@@ -312,7 +312,7 @@ $(shell find $(DEVICE_BSP_DIR) -type d \( $(EXCLUDED_DIRS) \) -prune -false -o
$(shell find $(SOURCE_MIDDLEWARES_DIR) -type f -name '*.cpp') $(shell find $(SOURCE_MIDDLEWARES_DIR) -type f -name '*.cpp')
# code optimisation ------------------------------------------------------------ # code optimisation ------------------------------------------------------------
OPTIM=-Os -flto -finline-small-functions -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections -fshort-enums -fsingle-precision-constant -ffreestanding -fno-common OPTIM=-Os -finline-small-functions -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections -fshort-enums -fsingle-precision-constant -ffreestanding -fno-common
# global defines --------------------------------------------------------------- # global defines ---------------------------------------------------------------
GLOBAL_DEFINES += $(DEV_GLOBAL_DEFS) -D USE_RTOS_SYSTICK -D MODEL_$(model) GLOBAL_DEFINES += $(DEV_GLOBAL_DEFS) -D USE_RTOS_SYSTICK -D MODEL_$(model)
@@ -388,8 +388,8 @@ CHECKOPTIONS= -Wall \
-Winline \ -Winline \
-Wshadow \ -Wshadow \
-Wno-unused-parameter \ -Wno-unused-parameter \
-Wdouble-promotion \ -Wdouble-promotion
-Werror