I am using TWRK60 + IAR6.1 + MQX3.7
I want to use flashx to save my data to a fixed location.
After I run this code, I get base_addr is 0x10800.
flash_hdl = fopen("flashx:", NULL);
/* Enable sector cache */
_io_ioctl(flash_hdl, FLASH_IOCTL_ENABLE_SECTOR_CACHE, NULL);
error_code = ioctl(flash_hdl, FLASH_IOCTL_GET_BASE_ADDRESS, &base_addr);
The flash start address in the linker script "C:\Program Files\Freescale\Freescale MQX 3.7\lib\twrk60n512.cw10\bsp\intflash.lcf" is 0x000000, why do I get 0x10800?
How can I set this base_addr to a fixed address? for example 0x20000.
Solved! Go to Solution.
Hi Bugs,
Glad to help.
I would use s19/s-record or binary file to store rather than ELF as ELF is much harder to decode and has much extra bulk to it (i.e. size).
I have code example attached in the Lodaer.c file FlashApplication() function that will parse a s-record or raw binary or CodeWarrior binary file and then program it to flash.
The higher level application is actually a bootloader and hopefully by Q4 Freescale will have a www.freescale.com/bootlader website with serveral different kinds of bootloader to choose from.
Hope this helps.
Regards,
David
Hi Bugs,
Let me try to explain what I've done with a MCF52259 project and FLASHX.
The linker file defines the memory map with:
___INTERNAL_SRAM_BASE = 0x20000000;
___INTERNAL_SRAM_SIZE = 0x00010000;
___INTERNAL_FLASH_BASE = 0x00000000;
___INTERNAL_FLASH_SIZE = 0x00080000;
___EXTERNAL_MRAM_BASE = 0x10000000;
___EXTERNAL_MRAM_SIZE = 0x00080000;
___EXTERNAL_MRAM_ROM_BASE = 0x10000000;
___EXTERNAL_MRAM_ROM_SIZE = 0x00000000;
___EXTERNAL_MRAM_RAM_BASE = 0x10000000;
___EXTERNAL_MRAM_RAM_SIZE = 0x00080000;
Then later in the linker file the size of the flash we want to control using FLASHX gets defined with:
___FLASHX_START_ADDR = 0x14000;
___FLASHX_END_ADDR = ___INTERNAL_FLASH_BASE + ___INTERNAL_FLASH_SIZE;
___FLASHX_SECT_SIZE = 0x1000;
In the processor bsp header file m52259evb.h there is a default BSPCFG_FLASHX_SIZE. To over ride this in the user_config.h I add:
#define BSPCFG_FLASHX_SIZE 0x6C000 //DES 0x80000 - 0x14000(BootloaderFromUSBStick size) = 0x6C000
#define BSPCFG_ENABLE_FLASHX 1
So the BSPCFG_FLASHX_SIZE is the size of the remaining internal flash above the 0x14000 address. In my application I have a bootloader using 0x0 thru 0x14000.
The bsp loads the flashx drive in init_bsp.c with:
/* install internal flash */
#if BSPCFG_ENABLE_FLASHX
_mcf5225_internal_flash_install("flashx:", BSPCFG_FLASHX_SIZE);
#endif
The flash_mcf5225.h grabs the linker variables and pulls them into the RTOS source code:
#define FLASHX_START_ADDR ((uint_32)__FLASHX_START_ADDR)
#define FLASHX_END_ADDR ((uint_32)__FLASHX_END_ADDR)
#define FLASHX_SECT_SIZE ((uint_32)__FLASHX_SECT_SIZE)
flash_mcf52xx.c has the _mcf5225_internal_flash_install() function that initializes the flashx structure.
Interesting part here is that when you open the flashx device to use it from your application code space:
flash = fopen("flashx:",0); //DES open the flash driver
then the instead of accessing flash starting at 0x14000 thru 0x80000, you access it from 0x0 thru 0x6c000. This was the confusing part for me BTW.
I do believe we could simplify this in the future.
Hope this helps.
Regards,
David
Hello,
I've tried to follow your instructions but I had no success...
I'm using MQX 3.8 with TWR52259 and I think that maybe there are some changes made in MQX 3.8.
In lcf file I've changed:
vectorrom (RX): ORIGIN = 0x00004010, LENGTH = 0x00000400
# rom (RX): ORIGIN = 0x00004410, LENGTH = 0x0007BBF0 # Code + Const data
rom (RX): ORIGIN = 0x00004410, LENGTH = 0x0003BBF0 # Code + Const data
ram (RW): ORIGIN = 0x20000000, LENGTH = 0x00010000 # SRAM - RW data
,,,
___FLASHX_START_ADDR = 0x00040000;
___FLASHX_END_ADDR = ___INTERNAL_FLASH_BASE + ___INTERNAL_FLASH_SIZE;
In init_flashx.c I'vechanged:
const FLASHX_FILE_BLOCK _bsp_flashx_file_blocks[] = {
// { "bank0", 0x00000000, (uint_32) __FLASHX_END_ADDR },
{ "bank0", 0x00040000, (uint_32) __FLASHX_END_ADDR },
{ "" , (uint_32) __FLASHX_START_ADDR, (uint_32) __FLASHX_END_ADDR },
{ NULL , 0, 0 }
};
Compilation and linking works fine ( MQX and my Application) but when writing, function _io_flashx_write returns IO_ERROR_WRITE_ACCESS because: fd_ptr->LOCATION >= fd_ptr->SIZE
I'm using the USB bootloader + Application with the a normal configuration:
Bootloader : 0x00000000 to 0x00003FFF
Application : 0x00004000 to 0x0003FFFF
From here I want to store variables from 0x00040000 to 0x007FFFFF. And I cannot do it.
Please can you help me?
thank you in advance.
Hi,
I've discovered that in file init_flashx.c there is a definition that can be modified to add more memory banks. I've added the 'bank1' :
const FLASHX_FILE_BLOCK _bsp_flashx_file_blocks[] = {
{ "bank0", 0x00000000, (uint_32) __FLASHX_END_ADDR },
// { "" , (uint_32) __FLASHX_START_ADDR, (uint_32) __FLASHX_END_ADDR },
{ "bank1" , (uint_32) __FLASHX_START_ADDR, (uint_32) __FLASHX_END_ADDR },
{ NULL , 0, 0 }
};
With this, I think that it will work !
DavidS,
Thanks to instructions.
Beside that, I have to change vectors.c, because I use IAR-6
#ifdef __ICCARM__#if 0 ///< remove this. I want to place flashx in fixed start point. GLi #pragma language=extended #pragma segment="CSTACK" #pragma location = ".flashx" #pragma segment=".flashx" const uchar __FLASHX_START_ADDR[1];#else extern const uchar __FLASHX_START_ADDR[];#endif#else #pragma define_section flashx ".flashx" far_abs R __declspec(flashx) const uchar __FLASHX_START_ADDR[1];#endif
BTW, I am going to save my ELF program in the flashx partition, how can my bootloader load this ELF program? Please give me some ideas.
Thanks
Hi Bugs,
Glad to help.
I would use s19/s-record or binary file to store rather than ELF as ELF is much harder to decode and has much extra bulk to it (i.e. size).
I have code example attached in the Lodaer.c file FlashApplication() function that will parse a s-record or raw binary or CodeWarrior binary file and then program it to flash.
The higher level application is actually a bootloader and hopefully by Q4 Freescale will have a www.freescale.com/bootlader website with serveral different kinds of bootloader to choose from.
Hope this helps.
Regards,
David
Hi Bugs,
It is a bit convoluted but I'll try to explain as I see it and I'm referencing a MCF52259 implementation.
In the linker file the memory map is defined with:
___INTERNAL_SRAM_BASE = 0x20000000;
___INTERNAL_SRAM_SIZE = 0x00010000;
___INTERNAL_FLASH_BASE = 0x00000000;
___INTERNAL_FLASH_SIZE = 0x00080000;
___EXTERNAL_MRAM_BASE = 0x10000000;
___EXTERNAL_MRAM_SIZE = 0x00080000;
___EXTERNAL_MRAM_ROM_BASE = 0x10000000;
___EXTERNAL_MRAM_ROM_SIZE = 0x00000000;
___EXTERNAL_MRAM_RAM_BASE = 0x10000000;
___EXTERNAL_MRAM_RAM_SIZE = 0x00080000;