MQX application don't run succesfully after 'go' of FNET bootloader I have a similar problem. However, I change all my .ld linker and I still don't make my mqx application works.
This is my .ld
ENTRY(__boot)
/*
_cfm - to keep vectors.c variables
__init_hardware - must be used from bsp.a, not from librt.a
*/
/*EXTERN(_cfm __init_hardware)*/
EXTERN(__vector_table ram_vector rom_vector)
MEMORY
{
/*fnet_bootloader (RX) : ORIGIN = 0x00000000, LENGTH = 0x0000C000*/
vectorrom (RX): ORIGIN = 0x0000C000, LENGTH = 0x00000420
/*cfmprotrom (R): ORIGIN = 0x00000400, LENGTH = 0x00000010*/
rom (RX): ORIGIN = 0x0000C420, LENGTH = 0x0007FBE0 - 0x0000C420 /*Code + Const data */
/* rom (RX): ORIGIN = 0x0000C420, LENGTH = 0x0007FBE0*/ /*Code + Const data */
ram (RW): ORIGIN = 0x1FFF0000, LENGTH = 0x00020000 /* SRAM - RW data*/
/* ram (RW): ORIGIN = 0x1FFF8000, LENGTH = 0x00020000 */ /* SRAM - RW data*/
/* kernel space starts after RAM variables (Location of MQX Kernel data + MQX heap) */
end_of_kd (RW): ORIGIN = 0x2000FFF0, LENGTH = 0x00000000
/* Boot stack reused by MQX Kernel data */
bstack (RW): ORIGIN = 0x2000FA00, LENGTH = 0x00000200 /* Boot stack */
end_bstack (RW): ORIGIN = 0x2000FC00, LENGTH = 0x00000000 /* Boot stack end address requires 4B alignment */
/* fnet_params (RW) : ORIGIN = 0x0007F800,LENGTH = 0x00001000*/
}
SECTIONS
{
__INTERNAL_SRAM_BASE = 0x1FFF0000;
__INTERNAL_SRAM_SIZE = 0x00020000;
/* __INTERNAL_FLASH_BASE = 0x00000000 + 0x0000C000;*/
/* __INTERNAL_FLASH_SIZE = 0x00080000 - 0x0000C000;*/
__INTERNAL_FLASH_BASE = 0x00000000;
__INTERNAL_FLASH_SIZE = 0x00080000;
__INTERNAL_FLEXNVM_BASE = 0;
__INTERNAL_FLEXNVM_SIZE = 0;
__EXTERNAL_MRAM_BASE = 0x70000000;
__EXTERNAL_MRAM_SIZE = 0x00080000;
__EXTERNAL_MRAM_ROM_BASE = 0x70000000;
__EXTERNAL_MRAM_ROM_SIZE = 0x00000000;
__EXTERNAL_MRAM_RAM_BASE = 0x70000000;
__EXTERNAL_MRAM_RAM_SIZE = 0x00080000;
__EXTERNAL_LCD_BASE = 0x60000000;
__EXTERNAL_LCD_SIZE = 0x1FFFF;
__EXTERNAL_LCD_DC_BASE = 0x60010000;
/* MQX link time configurations */
__DEFAULT_PROCESSOR_NUMBER = 1;
__DEFAULT_INTERRUPT_STACK_SIZE = 1024;
__KERNEL_DATA_VERIFY_ENABLE = 0; /* Test SDRAM read/write */
/* Flashx configurations */
__FLASHX_SECT_SIZE = 0x800;
.vectors :
{
__vector_table = .;
__VECTOR_TABLE_ROM_START = __vector_table;
KEEP(*(.vectors_rom))
. = ALIGN (0x4);
} > vectorrom
/* Flash protection bits */
/*.cfmprotect :*/
/*{*/
/* KEEP(*(.cfmconfig))*/
/* . = ALIGN (0x4);*/
/*} > cfmprotrom*/
.text :
{
*(KERNEL)
*(.text*)
*(.rodata*)
/* unwind exception frame */
KEEP(*(.eh_frame))
KEEP(*(.eh_frame_hdr))
/* constructors */
. = ALIGN(0x8);
KEEP (*crtbegin.o(.ctors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*crtend.o(.ctors))
/* destructors */
KEEP (*crtbegin.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*crtend.o(.dtors))
/* preinit_array */
__preinit_array_start = .;
KEEP (*(.preinit_array*))
__preinit_array_end = .;
/* init_array */
__init_array_start = .;
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array*))
__init_array_end = .;
/* fini_array */
__fini_array_start = .;
KEEP (*(SORT(.fini_array.*)))
KEEP (*(.fini_array*))
__fini_array_end = .;
/* gnu arm zero table */
. = ALIGN(4);
__zero_table_start__ = .;
LONG (_bss_start)
LONG (_bss_end - _bss_start)
__zero_table_end__ = .;
/* gnu arm copy table */
. = ALIGN(4);
__copy_table_start__ = .;
LONG (LOADADDR(.data))
LONG (_data_start)
LONG (_data_end - _data_start)
__copy_table_end__ = .;
} > rom
/* unwind exception frame */
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)
} > rom
.ARM :
{
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} > rom
/* create _etext symbol which keep
relocation(execution) address of "code" end */
_etext :
{
. = ALIGN(0x4);
_etext = .;
} > rom
.data :
{
. = ALIGN(128);
_data_start = .;
__VECTOR_TABLE_RAM_START = .;
KEEP(*(.vectors_ram))
. = ALIGN(512);
__BDT_BASE = .;
*(.usb_bdt)
__BDT_END = .;
*(.data*)
. = ALIGN(4);
_data_end = .;
_edata = .;
} > ram AT> rom
.rom_end_data :
{
_rom_data_end = .;
} > rom
.bss :
{
. = ALIGN(4);
_bss_start = .;
*(.bss*)
*(COMMON)
. = ALIGN(4);
_bss_end = .;
} > ram
.kernel_data :
{
. = ALIGN(0x10);
__KERNEL_DATA_START = .;
} > ram
.end_of_kernel_data :
{
__KERNEL_DATA_END = .;
__KERNEL_AREA_END = .;
} > end_of_kd
.boot_stack :
{
_stack_end = .;
} > bstack
.end_of_boot_stack :
{
stack_addr = .;
__SP_INIT = .;
__BOOT_STACK_ADDRESS = .;
} > end_bstack
/* fill "__S_romp" table with memory region(s) to perform "rom to ram copy" */
_romp_at = _etext + SIZEOF(.data);
.romp : AT(_romp_at)
{
__S_romp = _romp_at;
LONG(_etext); /* source (rom) address */
LONG(_data_start); /* target (ram) address */
LONG(_edata - _data_start); /* size */
/*Cambios para Álamo*/
/*LONG(__copy_table_end__); *//* source (rom) address */
/*LONG(ADDR(.data));*/ /* target (ram) address */
/*LONG(SIZEOF(.data));*/ /* size */
/* null terminated */
LONG(0);
LONG(0);
LONG(0);
}
/* user flash area starts here */
_flashx_start = _etext + SIZEOF(.data) + SIZEOF(.romp); /*Cambios para Álamo*/
/*_flashx_start = __INTERNAL_FLASH_BASE + __FLASHX_SECT_SIZE;*/
/* flashx working area spans across the whole rest of Flash memory */
/*_flashx_start = _rom_data_end;*/
__FLASHX_START_ADDR = ((_flashx_start + __FLASHX_SECT_SIZE - 1) / __FLASHX_SECT_SIZE) * __FLASHX_SECT_SIZE;
__FLASHX_END_ADDR = __INTERNAL_FLASH_BASE + __INTERNAL_FLASH_SIZE;
_end = .;
}
My comp.c is this
/*HEADER**********************************************************************
*
* Copyright 2013 Freescale Semiconductor, Inc.
*
* This software is owned or controlled by Freescale Semiconductor.
* Use of this software is governed by the Freescale MQX RTOS License
* distributed with this Material.
* See the MQX_RTOS_LICENSE file distributed for more details.
*
* Brief License Summary:
* This software is provided in source form for you to use free of charge,
* but it is not open source software. You are allowed to use this software
* but you cannot redistribute it or derivative works of it in source form.
* The software may be used only in connection with a product containing
* a Freescale microprocessor, microcontroller, or digital signal processor.
* See license agreement file for full license terms including other restrictions.
*****************************************************************************
*
* Comments:
*
* This file contains runtime support for the ARM GCC.
*
*
*END************************************************************************/
#include <stdio.h>
#include "mqx.h"
void *malloc(_mem_size);
void *calloc(_mem_size, _mem_size);
void *realloc(void*,_mem_size);
void free(void *);
void exit(int);
void _exit(int);
void init_hardware(void);
void __libc_init_array(void);
void __libc_fini_array(void);
void atexit(void *);
int main(void);
void *__dso_handle = NULL;
/*!
* \brief Dummy function which avoid GCC to register destructors of global objects.
* By default GCC use '__cxa_atexit' function which register destructors to
* LIFO. When LIFO is full, it performs malloc, but at this point there is
* no heap, so malloc fails.
*
* \return int
*/
int __cxa_atexit (void (*fn) (void *), void *arg, void *d)
{
return 0;
}
/*!
* \brief Perform custom action before main
*/
void _init(void)
{
;
}
/*!
* \brief Perform custom action before exit
*/
void _fini(void)
{
;
}
/*!
* \brief Override C/C++ runtime heap allocation function
*
* \param bytes
*
* \return pointer
*/
void *malloc(_mem_size bytes)
{
return _mem_alloc_system(bytes);
}
/*!
* \brief Override C/C++ reentrant runtime heap allocation function
*
* \param reent
* \param nbytes
*
* \return pointer
*/
void *_malloc_r(void *reent, size_t nbytes)
{
return _mem_alloc_system(nbytes);
}
/*!
* \brief Override C/C++ runtime heap deallocation
*
* \param n
* \param z
*
* \return pointer
*/
void *calloc(_mem_size n, _mem_size z)
{
return _mem_alloc_system_zero(n*z);
}
/*!
* \brief Override C/C++ runtime heap reallocation function in IAR's DLIB
*
* \param ptr
* \param bytes
*
* \return pointer
*/
void *realloc(void* ptr,_mem_size bytes)
{
return _mem_realloc(ptr,bytes);
}
/*!
* \brief Override C/C++ runtime heap deallocation function
*
* \param p
*/
void free(void *p)
{
_mem_free(p);
}
typedef struct {
uint32_t * TARGET;
uint32_t BYTESIZE;
} STARTUP_ZEROTABLE_STRUCT, * STARTUP_ZEROTABLE_STRUCT_PTR;
typedef struct {
uint32_t * SOURCE;
uint32_t * TARGET;
uint32_t BYTESIZE;
} STARTUP_COPYTABLE_STRUCT, * STARTUP_COPYTABLE_STRUCT_PTR;
extern STARTUP_ZEROTABLE_STRUCT __zero_table_start__[];
extern STARTUP_ZEROTABLE_STRUCT __zero_table_end__[];
extern STARTUP_COPYTABLE_STRUCT __copy_table_start__[];
extern STARTUP_COPYTABLE_STRUCT __copy_table_end__[];
/*!
* \brief setup zero sections, copy sections
*/
void data_startup(void)
{
register uint32_t offset, i;
// TODO: address alignment assertion
/* zero sections */
for (i = 0; &__zero_table_start__[i] < __zero_table_end__; i++)
{
for (
offset = 0;
offset < __zero_table_start__[i].BYTESIZE;
offset += sizeof(uint32_t)
)
(*(uint32_t*)((void*)__zero_table_start__[i].TARGET + offset)) = 0;
}
// TODO: address alignment & overlapping assertion
/* copy sections */
for (i = 0; &__copy_table_start__[i] < __copy_table_end__; i++)
{
for (
offset = 0;
offset < __copy_table_start__[i].BYTESIZE;
offset += sizeof(uint32_t)
)
(*(uint32_t*)((void*)__copy_table_start__[i].TARGET + offset))
= (*(uint32_t*)((void*)__copy_table_start__[i].SOURCE + offset));
}
}
/*!
* \brief Perform necessary toolchain startup routines before main()
*/
void toolchain_startup(void)
{
/****Cambios para Álamo****/
// asm("LDR r4,=0x00");
// asm("LDR sp, [r4]");
// asm("LDR r5, [r4]");
// asm("MSR MSP, r5");
// asm("LDR r4,=0x04");
// asm("LDR r5, [r4]");
// asm("BLX r5");
// _mqx_exit(0);
// initialize necessary hardware (clocks, ddr, ...)
init_hardware();
// initialize data - copy and zero sections
// static variables can be used on return
data_startup(); /*Cambios para Álamo*/
/*Cambios para Álamo*/
/***Copiar de ROM a RAM*/
// zero_fill_bss();
// __copy_rom_sections_to_ram();
// register destructor calls of static objects
atexit(__libc_fini_array);
// run constructor calls of static objects
__libc_init_array();
// run main, if return go to exit
//SCB_VTOR = (uint32_t)0x1FFF0000; /*Cambios para Álamo , Inicio del Vector RAM*/
exit(main());
}
/*!
* \brief Required implementation
*
* \param status
*/
void _exit(int status)
{
// disable all interrupts, run infinite loop
__asm("cpsid i");
while(1);
}
/*!
* \brief Required implementation, we don't use this legacy feature for more information
* see http//www.unix.com/man-page/FreeBSD/2/sbrk/
*
* \param increment
*/
void *_sbrk(intptr_t increment)
{
_exit(-1);
}