Author Topic: ELF to binary for boot loader  (Read 19128 times)

0 Members and 1 Guest are viewing this topic.

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 6141
  • Country: gb
  • Doing electronics since the 1960s...
Re: ELF to binary for boot loader
« Reply #25 on: August 01, 2021, 06:41:52 am »
Here is the source for a win32 .exe which appends the CRC32 (the inverted JAMCRC) to a file:

Code: [Select]
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>


/*
 *
 * CRC-32/JAMCRC. This is a "rolling" algorithm. Invert the *final* result for ISO-HDLC.
 * Returns 0x098494f3 from "123456789" (9 bytes). Inverting this (at the end) gives 0xcbf43926.
 * Polynomial is 0x04c11db7 and it holds it backwards (0xEDB88320).
 * This version accepts one byte at a time, and maintains the CRC in crcvalue. This makes it suitable
 * for calculating a CRC across a number of data blocks.
 * Speed is approx 400kbytes/sec.
 * crcvalue must be initialised to 0xffffffff by caller, and holds the accumulated CRC as you go along
 *
 */


void crc32(uint8_t input_byte, uint32_t *crcvalue)
{
for (uint32_t j = 0; j < 8; j++)
{
uint32_t mask = (input_byte^*crcvalue) & 1;
*crcvalue >>= 1;
if (mask)
*crcvalue = *crcvalue ^ 0xEDB88320;
input_byte >>= 1;
}
}

int main(int argc, char* argv[])
{
uint32_t crcvalue = 0xffffffff;
FILE* file = NULL;
if (argc > 1)
{
if (argc > 2)
{
int c = 0;
if (!_strnicmp(argv[2], "0x", 2))
c = 2;
crcvalue = strtol(&argv[2][c], NULL, 16);
}
file = fopen(argv[1], "rb");
if (file)
{
while (!feof(file))
{
uint8_t input_byte;
if (fread(&input_byte, sizeof(input_byte), 1, file))
{
crc32(input_byte, &crcvalue);
}
//else
//{
// printf("Before last zero byte = %08X\r\n", crcvalue);
// crc32(0, &crcvalue);
// printf("After last zero byte = %08X\r\n", crcvalue);
//}
}
fclose(file);

crcvalue = ~crcvalue;
file = fopen(argv[1], "ab");
fwrite(&crcvalue, sizeof(uint32_t), 1, file);
fclose(file);
}
else
{
printf("Cannot open file\r\n");
}

file = NULL;
}
else
{
printf("Missing file name\r\n");
}

return 0;
}


An optional 2nd parameter is a different CRC initialisation value (default is 0xffffffff).

Just curious: someone said that anything running out of Cube IDE should be written in Java.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 6141
  • Country: gb
  • Doing electronics since the 1960s...
Re: ELF to binary for boot loader
« Reply #26 on: August 08, 2021, 12:46:27 pm »
I have finished the boot loader and it is programming the flash fine. I will post my code as an update to the other thread... took a few days to get it right.

However I have problems producing the .bin file (to which I am appending the CRC). So currently I am flashing various jpeg files, which obviously don't run too well ;)

The batch file I am using, in the post build steps configuration, and which runs with no errors, is:

Code: [Select]
cd c:\kde420\project1\debug
arm-none-eabi-objdump -h kde2020.elf > objdump.txt
arm-none-eabi-objcopy --strip-debug -O binary kde2020.elf c:\kde420\project1\kde420.bin
cd c:\kde420\project1\
c:\kde420\crcgen\addcrc kde420.bin 0xffffffff


I noticed Cube is already generating a .bin file but that one is also 131MB. Hence I am generating my different kde420.bin file, but that is no smaller.

Clearly objcopy is including stuff which is not in the final program (which is about 240k). The objdump.txt I am creating contains this

Code: [Select]
kde2020.elf:     file format elf32-littlearm

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 loader_bss    00000000  2001064c  2001064c  00090000  2**0
                  CONTENTS
  1 KDE_loader    0000064c  20010000  08002c48  00030000  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .isr_vector   00000188  08000000  08000000  00010000  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .b_main.o     000011a4  08000188  08000188  00010188  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  4 .45dbxx.o     000009b0  0800132c  0800132c  0001132c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  5 .KDE_loader.o 00000000  08001cdc  08001cdc  00090000  2**0
                  CONTENTS
  6 .main_stub.o  00000008  08008000  08008000  00038000  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  7 .main.o       000002c0  08008008  08008008  00038008  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  8 .text         000382c0  080082d0  080082d0  000382d0  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  9 .ARM.exidx    00000008  08040590  08040590  00070590  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 10 .init_array   00000008  08040598  08040598  00070598  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 11 .fini_array   00000004  080405a0  080405a0  000705a0  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 12 .data         00000f6c  20000000  08001cdc  00020000  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 13 .KDE_loader   0000064c  08002c48  08002c48  00022c48  2**0
                  ALLOC
 14 .bss          0000ddac  20000f70  20000f70  00090f70  2**3
                  ALLOC
 15 .main_heap    00000004  2000ed1c  2000ed1c  00090f70  2**0
                  ALLOC
 16 .ccmram       00010000  10000000  10000000  00080000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 17 .ARM.attributes 00000030  00000000  00000000  00090000  2**0
                  CONTENTS, READONLY
 18 .debug_info   00079159  00000000  00000000  00090030  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 19 .debug_abbrev 00010d81  00000000  00000000  00109189  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 20 .debug_aranges 00003eb8  00000000  00000000  00119f10  2**3
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 21 .debug_ranges 00003948  00000000  00000000  0011ddc8  2**3
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 22 .debug_macro  000417ae  00000000  00000000  00121710  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 23 .debug_line   00062b3d  00000000  00000000  00162ebe  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 24 .debug_str    001128f3  00000000  00000000  001c59fb  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 25 .comment      00000053  00000000  00000000  002d82ee  2**0
                  CONTENTS, READONLY
 26 .debug_frame  0000d4c4  00000000  00000000  002d8344  2**2
                  CONTENTS, READONLY, DEBUGGING, OCTETS

It looks like I should have only this (I do want initialised DATA included, obviously)



Any ideas on how to achieve this?

I've been looking at various references e.g. https://sourceware.org/binutils/docs/binutils/objcopy.html but none of the --strip... options I have tried make any difference.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1837
  • Country: de
Re: ELF to binary for boot loader
« Reply #27 on: August 08, 2021, 01:19:52 pm »
My understanding is that all sections tagged with "LOAD" are included in the bin file, and all gaps between the load addresses of the included sections are included, too, and filled.
The section .ccmram is tagged with "LOAD" too, and there seems to be a larger gap between .data and .ccram.

Edit: So if I did not overlook anything, I'd expect the .bin file to contain the load address range 0x08000000 - 0x1000ffff (which implies a file size of 134283264 bytes)
« Last Edit: August 08, 2021, 01:47:17 pm by gf »
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 6141
  • Country: gb
  • Doing electronics since the 1960s...
Re: ELF to binary for boot loader
« Reply #28 on: August 08, 2021, 01:53:47 pm »
Yeah... after much hacking I found this gives me a 258k file

arm-none-eabi-objcopy -S --strip-all -R .bss -R .main_heap -R .ccmram -O binary kde2020.elf output.bin

which seems to contain the right stuff - at least in the beginning :)

FWIW I am running the Cube post build stuff out of a batch file. I didn't find any way to add multiple command lines. Some people online said they did but Cube didn't preserve their order, but putting them in a .bat sidestepped that.

AND IT IS RUNNING THE CODE! :) Took a few days' coding.
« Last Edit: August 08, 2021, 02:05:24 pm by peter-h »
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1837
  • Country: de
Re: ELF to binary for boot loader
« Reply #29 on: August 08, 2021, 02:00:47 pm »
Sure, with -R you can exclude sections. But the actual question is, why did .ccram become a loadable section in the first place, if it is not suposed to become part of the flash? I guess this is a bug in the linker script?
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 6141
  • Country: gb
  • Doing electronics since the 1960s...
Re: ELF to binary for boot loader
« Reply #30 on: August 08, 2021, 02:10:05 pm »
Yes course there is a bug in my linkfile :) I am right on the edge with those.

I now need a reboot function, for the boot loader, which doesn't need calling any of the ST stuff. I condensed this out of one of the HAL... things but it just hangs. I will work on it but maybe somebody knows something right off

Code: [Select]
static void reboot(void)
{
  __ASM volatile ("dsb 0xF":::"memory"); // Ensure all outstanding memory accesses included
                                                // buffered write are completed before reset
  SCB->AIRCR  = (uint32_t)((0x5FAUL << 16) | (SCB->AIRCR & 0x700) | 0 ); // Keep priority group unchanged
  __ASM volatile ("dsb 0xF":::"memory"); // Ensure completion of memory access

  for(;;) // wait until reset
  {
  __ASM volatile ("nop");
  }
}
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Online cv007

  • Super Contributor
  • ***
  • Posts: 1069
Re: ELF to binary for boot loader
« Reply #31 on: August 08, 2021, 03:07:18 pm »
bit 3- SYSRESETREQ - needs to be set.
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 6141
  • Country: gb
  • Doing electronics since the 1960s...
Re: ELF to binary for boot loader
« Reply #32 on: August 08, 2021, 04:00:36 pm »
Nothing in the RM, strangely enough. This is in core_cm4.h and did eventually work. I originally tried to simplify it a bit - not a good idea :)

Code: [Select]
__NO_RETURN __STATIC_INLINE void __NVIC_SystemReset(void)
{
  __DSB();                                                          /* Ensure all outstanding memory accesses included
                                                                       buffered write are completed before reset */
  SCB->AIRCR  = (uint32_t)((0x5FAUL << SCB_AIRCR_VECTKEY_Pos)    |
                           (SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk) |
                            SCB_AIRCR_SYSRESETREQ_Msk    );         /* Keep priority group unchanged */
  __DSB();                                                          /* Ensure completion of memory access */

  for(;;)                                                           /* wait until reset */
  {
    __NOP();
  }
}


In case anyone is interested, this is my linkfile

Code: [Select]
/* Entry Point */
ENTRY(Reset_Handler)

/* Reference boot block stuff to ensure that it gets linked-in - not sure if these do anything */
/* EXTERN(b_boot) */
/* EXTERN(KDE_loader) */


/* Highest address of the main stack. This stack is only for startup code, boot loader, and ISRs. The RTOS has its own. */
 /*  _estack = 0x20020000;  */    /* stack in 128K RAM */
 _estack = 0x10010000;    /* stack in  64k CCM - note: configTOTAL_HEAP_SIZE + min_stack_size must not exceed 64k) */
 
/* top of RAM for _sbrk - top of heap check */
 _top = 0x20020000;

/* Heap and stack sizes */
 
_Min_Heap_Size  = 0x0000;     /* 21/7/21 set to zero to prevent heap/stack conflict check from blowing up due to boot loader area  */
_Min_Stack_Size = 0x4000;     /* 16k stack - in CCM */

/* Specify the memory areas */
/* CCMRAM added PH 12/5/2021 - cannot use with DMA */
MEMORY
{
FLASH_BOOT (rx)     : ORIGIN = 0x08000000, LENGTH = 32K
FLASH_APP (rx)      : ORIGIN = 0x08008000, LENGTH = 1024K-32K
RAM (xrw)           : ORIGIN = 0x20000000, LENGTH = 128K
MEMORY_B1 (rx)      : ORIGIN = 0x60000000, LENGTH = 0K
CCMRAM (rw)         : ORIGIN = 0x10000000, LENGTH = 64K
}

/* Define output sections */
SECTIONS
{
 
/* loader_bss and loader sections must come first, in order to override the
     wildcards in subsequent sections */
  loader_bss _loader_end :
  {
  _loader_bss_start = .;
  *KDE_loader.o(.bss*)
  . = ALIGN(4);
  _loader_bss_end = .;
}

/* General purpose buffer for loader usage, b_main.c and KDE_loader.c.
   Done this way to avoid spurious section overlap errors; the loader reboots when done
   so it can use any RAM it wants */
  buffer1=0x10000000; /* base of CCM */
 
  /* RAM based loader is linked to execute here */
  KDE_loader 0x20010000 : AT(_loader_loadaddr)
  {
  _loader_start = .;
  *KDE_loader.o(.text*)
  *KDE_loader.o(.rodata*)
  *KDE_loader.o(.data*)
  *KDE_loader.o(.common*)
  *KDE_loader.o(.ARM.attributes)
  . = ALIGN(4);
  _loader_end = .;
  }
 
  _loader_size = SIZEOF(KDE_loader);
 


  /* Place modules into FLASH, starting at the bottom (0x08000000)
     The line "*b_main.o (.text .text* .rodata .rodata*)" is important, but for some reason
     (probably the reset_handler reference) is not needed for isr_vector */
 
   
    /* Startup code */
  .isr_vector :
  {
    . = ALIGN(4);
    KEEP(*(.isr_vector))
    . = ALIGN(4);
  } >FLASH_BOOT
 
  .b_main.o :
  {
    . = ALIGN(4);
    KEEP(*(.b_main.o))
    *b_main.o (.text .text* .rodata .rodata*)
    . = ALIGN(4);
  } >FLASH_BOOT
 
  .45dbxx.o :
  {
    . = ALIGN(4);
    KEEP(*(.45dbxx.o))
    *45dbxx.o (.text .text* .rodata .rodata*)
    . = ALIGN(4);
  } >FLASH_BOOT
 
  /* === other boot block stuff will go here === */
 
 
  /* KDE_loader.o - goes last in the bottom block which makes it easier to check the block usage
     by checking _loader_end_in_flash in the .map file */
 
  .KDE_loader.o :
  {
    . = ALIGN(4);
    KEEP(*(.KDE_loader.o))
    *KDE_loader.o (.text .text* .rodata .rodata*)
    . = ALIGN(4);
      _loader_end_in_flash = .;
  } >FLASH_BOOT
 
  /* The rest of the KDE code goes here, loaded at base+32k, starting with a stub and then the real main() */

  .main_stub.o :
  {
    . = ALIGN(4);
    KEEP(*(.main_stub.o))
    *main_stub.o (.text .text* .rodata .rodata*)
    . = ALIGN(4);
  } >FLASH_APP
   
  .main.o :
  {
    . = ALIGN(4);
    KEEP(*(.main.o))
    *main.o (.text .text* .rodata .rodata*)
    . = ALIGN(4);
  } >FLASH_APP
 
/* This collects all other stuff, which gets loaded into FLASH after main.o above */
 
  .text :
  {
    . = ALIGN(4);
    *(.text)           /* .text sections (code) */
    *(.text*)          /* .text* sections (code) */
    *(.rodata)         /* .rodata sections (constants, strings, etc.) */
    *(.rodata*)        /* .rodata* sections (constants, strings, etc.) */
    *(.glue_7)         /* glue arm to thumb code */
    *(.glue_7t)        /* glue thumb to arm code */
*(.eh_frame)

    KEEP (*(.init))
    KEEP (*(.fini))

    . = ALIGN(4);
    _etext = .;        /* define a global symbol at end of code */
} >FLASH_APP

/* this is for __libc_init_array() */

.preinit_array     :
  {
    PROVIDE_HIDDEN (__preinit_array_start = .);
    KEEP (*(.preinit_array*))
    PROVIDE_HIDDEN (__preinit_array_end = .);
  } >FLASH_APP
  .init_array :
  {
    PROVIDE_HIDDEN (__init_array_start = .);
    KEEP (*(SORT(.init_array.*)))
    KEEP (*(.init_array*))
    PROVIDE_HIDDEN (__init_array_end = .);
  } >FLASH_APP
  .fini_array :
  {
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(.fini_array*))
    KEEP (*(SORT(.fini_array.*)))
    PROVIDE_HIDDEN (__fini_array_end = .);
  } >FLASH_APP


/* Initialized data sections goes into RAM, load LMA copy after code */
  .data :
  {
    . = ALIGN(4);
    _sdata = .;        /* create a global symbol at data start */
    *(.data)           /* .data sections */
    *(.data*)          /* .data* sections */
      . = ALIGN(4);
    _edata = .;        /* define a global symbol at data end */
  } >RAM  AT >FLASH_BOOT

  /* used by the startup to initialize data */
  _sidata = LOADADDR(.data);

/* dummy placeholder in flash for loader section, to count flash usage */
  .KDE_loader :
  {
  . = . + SIZEOF(KDE_loader);
  } AT >FLASH_BOOT
 
  _loader_loadaddr = LOADADDR(.KDE_loader);
 
  /* Uninitialized data section */
  . = ALIGN(4);
  .bss :
  {
    /* This is used by the startup in order to initialize the .bss section */
    _sbss = .;         /* define a global symbol at bss start */
    __bss_start__ = _sbss;
    *(.bss)
    *(.bss*)
    *(COMMON)

    . = ALIGN(4);
    _ebss = .;         /* define a global symbol at bss end */
    __bss_end__ = _ebss;
  } >RAM

  /* The heap ends up after BSS in main RAM */
  /* This also checks that the top of the heap doesn't hit the bottom of the stack i.e. how much RAM left */
  /* User_heap_stack section, used to check that there is enough RAM left */
 
  /* ._user_heap_stack : */
  /* This check is basically disabled because _Min_Heap_Size=0 above */
  .main_heap :
  {
    . = ALIGN(8);
    PROVIDE ( end = . );
    PROVIDE ( _end = . );
    . = . + _Min_Heap_Size;
  /*   . = . + _Min_Stack_Size; */  /* PH 14/5/2021 stack is in CCM, not here */
    . = ALIGN(8);
} >RAM
  /*   } >CCMRAM */


/* MEMORY_bank1 section, code must be located here explicitly            */
/* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */
/* Not used 14/5/2021 - was apparently used for LCD display on ST dev kit */
  .memory_b1_text :
  {
    *(.mb1text)        /* .mb1text sections (code) */
    *(.mb1text*)       /* .mb1text* sections (code)  */
    *(.mb1rodata)      /* read-only data (constants) */
    *(.mb1rodata*)
} >MEMORY_B1
 
/* CCM-RAM section
  *
  * IMPORTANT NOTE!
  * If variables placed in this section must be zero initialized,
  * the startup code needs to be modified to initialize this section.
  * Done PH 12/5/2021
  */
  .ccmram :
  {
    . = ALIGN(4);
    _sccmram = .;       /* create a global symbol at ccmram start */
    *(.ccmram)
    *(.ccmram*)
   
    . = ALIGN(4);
    _eccmram = .;       /* create a global symbol at ccmram end */
  } >CCMRAM

  /* Remove information from the standard libraries */
  /DISCARD/ :
  {
    libc.a ( * )
    libm.a ( * )
    libgcc.a ( * )
  }

  .ARM.attributes 0 : { *(.ARM.attributes) }
}


When I get around to it I will post my flashing code here
https://www.eevblog.com/forum/microcontrollers/32f417-best-way-to-program-the-flash-from-ram-based-code/new/#new

A lot of work went into it.
« Last Edit: August 08, 2021, 04:22:50 pm by peter-h »
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2867
  • Country: us
Re: ELF to binary for boot loader
« Reply #33 on: August 09, 2021, 06:26:56 am »
The reference manual for ARM MCUs only covers the information specific to that part: bus architecture, memory layout, peripherals, that sort of thing.  The operation of the core, of which the NVIC is part, is going to be the same as any other part with the same core (notwithstanding options like caches, FPU, etc).  So there's no point in including those details because they're already adequate covered by the ARM architecture reference material--and being the ones who designed the core, ARM are in a better position to document that stuff anyway. 

So for a comprehensive understanding of an ARM part you really the datasheet for electrical/performance, the reference manual for operational and peripheral information, and the relevant ARM documentation for how the core works
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1837
  • Country: de
Re: ELF to binary for boot loader
« Reply #34 on: August 09, 2021, 11:15:03 am »
Quote
Sure, with -R you can exclude sections. But the actual question is, why did .ccram become a loadable section in the first place, if it is not suposed to become part of the flash? I guess this is a bug in the linker script?

Did you possibly place any initialized data in your .ccram section?
Seems that the section does have some contents:

Code: [Select]
16 .ccmram       00010000  10000000  10000000  00080000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 6141
  • Country: gb
  • Doing electronics since the 1960s...
Re: ELF to binary for boot loader
« Reply #35 on: August 09, 2021, 12:08:54 pm »
There should be nothing initialised in the CCM.

The CCM is 64k, which is allocated as

48k for the FreeRTOS "buffer" (it runs all the processes, including their stacks, in there) and 16k general stack (used by main() before the RTOS starts, and by ISRs, and of course by the boot loader which basically gets control instead of (most of) main().

I have no variables like
uint64_t fred=55;
in the CCM.

Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1837
  • Country: de
Re: ELF to binary for boot loader
« Reply #36 on: August 09, 2021, 01:17:30 pm »
Hmm. Tried a small test pogram:

Code: [Select]
char buffer[1024] __attribute__((section(".ccram")));


Unllike regular uninitialized global variables (which either become common, or go into bss w/o "CONTENTS" or "LOAD" tag), gcc obviously does initialize buffer[] with zeros.

Code: [Select]
$ objdump -h -s x.o

Sektionen:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         00000000  0000000000000000  0000000000000000  00000040  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .data         00000000  0000000000000000  0000000000000000  00000040  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00000000  0000000000000000  0000000000000000  00000040  2**0
                  ALLOC
  3 .ccram        00000400  0000000000000000  0000000000000000  00000040  2**5
                  CONTENTS, ALLOC, LOAD, DATA
  4 .comment      0000002a  0000000000000000  0000000000000000  00000440  2**0
                  CONTENTS, READONLY
  5 .note.GNU-stack 00000000  0000000000000000  0000000000000000  0000046a  2**0
                  CONTENTS, READONLY
Inhalt von Abschnitt .ccram:
 0000 00000000 00000000 00000000 00000000  ................
 0010 00000000 00000000 00000000 00000000  ................
 0020 00000000 00000000 00000000 00000000  ................
 0030 00000000 00000000 00000000 00000000  ................
 0040 00000000 00000000 00000000 00000000  ................
 0050 00000000 00000000 00000000 00000000  ................
 0060 00000000 00000000 00000000 00000000  ................
 0070 00000000 00000000 00000000 00000000  ................
 0080 00000000 00000000 00000000 00000000  ................
 0090 00000000 00000000 00000000 00000000  ................
 00a0 00000000 00000000 00000000 00000000  ................
 00b0 00000000 00000000 00000000 00000000  ................
 00c0 00000000 00000000 00000000 00000000  ................
 00d0 00000000 00000000 00000000 00000000  ................
 00e0 00000000 00000000 00000000 00000000  ................
 00f0 00000000 00000000 00000000 00000000  ................
 0100 00000000 00000000 00000000 00000000  ................
 0110 00000000 00000000 00000000 00000000  ................
 0120 00000000 00000000 00000000 00000000  ................
 0130 00000000 00000000 00000000 00000000  ................
 0140 00000000 00000000 00000000 00000000  ................
 0150 00000000 00000000 00000000 00000000  ................
 0160 00000000 00000000 00000000 00000000  ................
 0170 00000000 00000000 00000000 00000000  ................
 0180 00000000 00000000 00000000 00000000  ................
 0190 00000000 00000000 00000000 00000000  ................
 01a0 00000000 00000000 00000000 00000000  ................
 01b0 00000000 00000000 00000000 00000000  ................
 01c0 00000000 00000000 00000000 00000000  ................
 01d0 00000000 00000000 00000000 00000000  ................
 01e0 00000000 00000000 00000000 00000000  ................
 01f0 00000000 00000000 00000000 00000000  ................
 0200 00000000 00000000 00000000 00000000  ................
 0210 00000000 00000000 00000000 00000000  ................
 0220 00000000 00000000 00000000 00000000  ................
 0230 00000000 00000000 00000000 00000000  ................
 0240 00000000 00000000 00000000 00000000  ................
 0250 00000000 00000000 00000000 00000000  ................
 0260 00000000 00000000 00000000 00000000  ................
 0270 00000000 00000000 00000000 00000000  ................
 0280 00000000 00000000 00000000 00000000  ................
 0290 00000000 00000000 00000000 00000000  ................
 02a0 00000000 00000000 00000000 00000000  ................
 02b0 00000000 00000000 00000000 00000000  ................
 02c0 00000000 00000000 00000000 00000000  ................
 02d0 00000000 00000000 00000000 00000000  ................
 02e0 00000000 00000000 00000000 00000000  ................
 02f0 00000000 00000000 00000000 00000000  ................
 0300 00000000 00000000 00000000 00000000  ................
 0310 00000000 00000000 00000000 00000000  ................
 0320 00000000 00000000 00000000 00000000  ................
 0330 00000000 00000000 00000000 00000000  ................
 0340 00000000 00000000 00000000 00000000  ................
 0350 00000000 00000000 00000000 00000000  ................
 0360 00000000 00000000 00000000 00000000  ................
 0370 00000000 00000000 00000000 00000000  ................
 0380 00000000 00000000 00000000 00000000  ................
 0390 00000000 00000000 00000000 00000000  ................
 03a0 00000000 00000000 00000000 00000000  ................
 03b0 00000000 00000000 00000000 00000000  ................
 03c0 00000000 00000000 00000000 00000000  ................
 03d0 00000000 00000000 00000000 00000000  ................
 03e0 00000000 00000000 00000000 00000000  ................
 03f0 00000000 00000000 00000000 00000000  ................
Inhalt von Abschnitt .comment:
 0000 00474343 3a202855 62756e74 7520372e  .GCC: (Ubuntu 7.
 0010 352e302d 33756275 6e747531 7e31382e  5.0-3ubuntu1~18.
 0020 30342920 372e352e 3000               04) 7.5.0.


Edit: I wonder whether

    .ccmram (NOLOAD) :
    {
        ...
    }


in the linker script helps?
« Last Edit: August 09, 2021, 01:37:35 pm by gf »
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 6141
  • Country: gb
  • Doing electronics since the 1960s...
Re: ELF to binary for boot loader
« Reply #37 on: August 09, 2021, 07:46:08 pm »
Do you mean that if one allocates say 16k of CCM to a buffer, you end up with a 16k block of 0x00 in the initialised DATA?

It wouldn't actually get copied to CCM because my startup (the st... .s bit) doesn't have any code for that.

I excluded that section from the binary output anyway, with

arm-none-eabi-objcopy -S --strip-all -R .bss -R .main_heap -R .ccmram -O binary kde2020.elf c:\kde420\project1\factory0.dat

so I am ok with it... but this was probably responsible for the 131MB bin file :)
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1837
  • Country: de
Re: ELF to binary for boot loader
« Reply #38 on: August 09, 2021, 08:09:04 pm »
Quote
Do you mean that if one allocates say 16k of CCM to a buffer, you end up with a 16k block of 0x00 in the initialised DATA?

Obviously, but the 16k of zeros are stored as contents of the .ccram section, not in the .data section.
Just do an objdump -h -s on the .o file, in order to check.

Quote
but this was probably responsible for the 131MB bin file

In your objdump output, the section .ccram is tagged with LOAD, therefore it is included in the .bin file (unless you exclude it explicitly).
And if both, .data and .ccram are included, then the huge gap between .data and .ccram is included as well in the .bin file.
The .bin file represents a memory dump of contiguous load addresses, so any gaps between incuded sections have to be filled.
 

Offline peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 6141
  • Country: gb
  • Doing electronics since the 1960s...
Re: ELF to binary for boot loader
« Reply #39 on: August 09, 2021, 09:38:49 pm »
"Just do an objdump -h -s on the .o file, in order to check."

This is the section list

Code: [Select]
project1.elf:     file format elf32-littlearm

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 loader_bss    00000000  20010860  20010860  00090000  2**0
                  CONTENTS
  1 KDE_loader    00000860  20010000  08002c98  00030000  2**3
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .isr_vector   00000188  08000000  08000000  00010000  2**0
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
  3 .b_main.o     000011f4  08000188  08000188  00010188  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  4 .45dbxx.o     000009b0  0800137c  0800137c  0001137c  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  5 .KDE_loader.o 00000000  08001d2c  08001d2c  00090000  2**0
                  CONTENTS
  6 .main_stub.o  00000008  08008000  08008000  00038000  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  7 .main.o       000002c0  08008008  08008008  00038008  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  8 .text         000383f0  080082d0  080082d0  000382d0  2**4
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  9 .ARM.exidx    00000008  080406c0  080406c0  000706c0  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, DATA
 10 .init_array   00000008  080406c8  080406c8  000706c8  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 11 .fini_array   00000004  080406d0  080406d0  000706d0  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 12 .data         00000f6c  20000000  08001d2c  00020000  2**3
                  CONTENTS, ALLOC, LOAD, DATA
 13 .KDE_loader   00000860  08002c98  08002c98  00022c98  2**0
                  ALLOC
 14 .bss          0000ddac  20000f70  20000f70  00090f70  2**3
                  ALLOC
 15 .main_heap    00000004  2000ed1c  2000ed1c  00090f70  2**0
                  ALLOC
 16 .ccmram       00010000  10000000  10000000  00080000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
 17 .ARM.attributes 00000030  00000000  00000000  00090000  2**0
                  CONTENTS, READONLY
 18 .debug_info   0007935a  00000000  00000000  00090030  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 19 .debug_abbrev 00010da6  00000000  00000000  0010938a  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 20 .debug_aranges 00003ec0  00000000  00000000  0011a130  2**3
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 21 .debug_ranges 00003938  00000000  00000000  0011dff0  2**3
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 22 .debug_macro  000417ae  00000000  00000000  00121928  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 23 .debug_line   00062dcb  00000000  00000000  001630d6  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 24 .debug_str    001128fe  00000000  00000000  001c5ea1  2**0
                  CONTENTS, READONLY, DEBUGGING, OCTETS
 25 .comment      00000053  00000000  00000000  002d879f  2**0
                  CONTENTS, READONLY
 26 .debug_frame  0000d4d4  00000000  00000000  002d87f4  2**2
                  CONTENTS, READONLY, DEBUGGING, OCTETS

I see a 64k CCM block there, not 16k. Could be this bit in the linkfile

Code: [Select]
MEMORY
{
FLASH_BOOT (rx)     : ORIGIN = 0x08000000, LENGTH = 32K
FLASH_APP (rx)      : ORIGIN = 0x08008000, LENGTH = 1024K-32K
RAM (xrw)           : ORIGIN = 0x20000000, LENGTH = 128K
MEMORY_B1 (rx)      : ORIGIN = 0x60000000, LENGTH = 0K
CCMRAM (rw)         : ORIGIN = 0x10000000, LENGTH = 64K
}

"The .bin file represents a memory dump of contiguous load addresses, so any gaps between incuded sections have to be filled."

Sure; I see that. However this wheel must have been re-invented by so many already, because sure as hell Cube is not sending 131MB to the STLINK debugger :) They must be doing "something".

Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline gf

  • Super Contributor
  • ***
  • Posts: 1837
  • Country: de
Re: ELF to binary for boot loader
« Reply #40 on: August 09, 2021, 09:53:58 pm »
"Just do an objdump -h -s on the .o file, in order to check."
This is the section list

I meant the .o file where the ccram buffer is defined, not the final .elf.
The .map file generated by the linker may interesting too, as it tells in detail the input sections and .o files which have been included into each output section, and at which address.
 

Offline abyrvalg

  • Frequent Contributor
  • **
  • Posts: 898
  • Country: es
Re: ELF to binary for boot loader
« Reply #41 on: August 09, 2021, 09:58:03 pm »
.bss* section names are recognized by as/ld and treated as NOLOAD automatically (see GNU as manual section 4.2). You either need to specify NOLOAD type (as gf already advised, I would prefer this way too, explicit is better than implicit) or name it somehow like .bss.ccmram.
Manuals are cool :-+
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->