Weird error on bootloader code

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm currently building a bootloader for my atmega4809 uC. When i use the standard bootloader as described in the manual, everything works fine when compiling the code.

But when i try to add some extra code, the bootloader doesn't compile.

I try to add a simple crc8 to the data that is send to the microcontroller. To make sure the right code is flashing on the uC.

 

/*
 * Main boot function
 * Put in the constructors section (.ctors) to save Flash.
 * Naked attribute used since function prologue and epilogue is unused
 */
__attribute__((naked)) __attribute__((section(".ctors"))) void boot(void)
{
	/* Initialize system for AVR GCC support, expects r1 = 0 */
	asm volatile("clr r1");

	/* Check if entering application or continuing to bootloader */
	if(!is_bootloader_requested()) {
		/* Enable Boot Section Lock */
		NVMCTRL.CTRLB = NVMCTRL_BOOTLOCK_bm;

		/* Go to application, located immediately after boot section */
		app_t app = (app_t)(BOOT_SIZE / sizeof(app_t));
		app();
	}

	/* Initialize communication interface */
	init_uart();
	init_status_led();

	/*
	 * Start programming at start for application section
	 * Subtract MAPPED_PROGMEM_START in condition to handle overflow on large flash sizes
	 */
#ifdef _PROGRAM
	uint8_t *app_ptr = (uint8_t *)MAPPED_APPLICATION_START;
	uint8_t Check_data[8];
	uint8_t count = 0;
	uint8_t crc_received, crc;
	while(app_ptr - MAPPED_PROGMEM_START <= (uint8_t *)PROGMEM_END) {
		/* Receive and echo data before loading to memory */
		uint8_t rx_data = uart_receive();
		uint8_t *temp_ptr;
		uart_send(rx_data);
		/*combine the data received for later crc*/
		if(count == 0){
			temp_ptr = app_ptr;
		}
		Check_data[count] = rx_data;
		count++;
		/* Incremental load to page buffer before writing to Flash */
		*app_ptr = rx_data;
		app_ptr++;
		
		if(count>=8){
			count = 0;
			crc = 0;
			crc_received = uart_receive();
			
			for (uint8_t i=0; i<8 ;i++){
				crc =  Check_data[i];
			}
			if(!(crc == crc_received)){
				app_ptr = temp_ptr;
			}
		}
		
		if(!((uint16_t)app_ptr % MAPPED_PROGMEM_PAGE_SIZE)) {
			/* Page boundary reached, Commit page to Flash */
			_PROTECTED_WRITE_SPM(NVMCTRL.CTRLA, NVMCTRL_CMD_PAGEERASEWRITE_gc);
			while(NVMCTRL.STATUS & NVMCTRL_FBUSY_bm);

			toggle_status_led();
		}
	}
#endif // _PROGRAM
#ifdef _DEBUG
	__builtin_avr_delay_cycles(10000000);
	toggle_status_led();
	__builtin_avr_delay_cycles(10000000);
	toggle_status_led();
	__builtin_avr_delay_cycles(10000000);
	toggle_status_led();
#endif // _DEBUG
	/* Issue system reset */
	_PROTECTED_WRITE(RSTCTRL.SWRR, RSTCTRL_SWRE_bm);
}

The code itself ain't pretty, but i spread out the code to see on what part the compiler is hanging.

The error i get is:
Error        in expand_assignment, at expr.c:4874    BootLoader

 

The line i pointing to the line :

Check_data[count] = rx_data;

When i comment that part of the program out, i get to next error:
Error        in emit_move_insn, at expr.c:3601    BootLoader

The line here is:

__attribute__((naked)) __attribute__((section(".ctors"))) void boot(void)

I don't know what next to look for. Also, what problem is there in the program?

The bootloader program itself is not to big for the memory assigned.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The error messages you quote are useless - they don't actually show the text of the error message. Please show the build output.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry, my bad.

Here are the build outputs:

 

------ Build started: Project: BootLoader, Configuration: Debug AVR ------
Build started.
Project "BootLoader.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project ".........\BootLoader\BootLoader.cproj" (target "Build" depends on it):
    Task "RunCompilerTask"
        Shell Utils Path C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils
        C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all --jobs 12 --output-sync
        .././boot.c: In function 'boot':
        .........\BootLoader\boot.c(89,21): error: in expand_assignment, at expr.c:4874
           Check_data[count] = rx_data;
                             ^
        Please submit a full bug report,
        with preprocessed source if appropriate.
        See <http://www.atmel.com> for instructions.
        make: *** [boot.o] Error 1
        Building file: .././boot.c
        Invoking: AVR/GNU C Compiler : 5.4.0
        "C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe"  -x c -funsigned-char -funsigned-bitfields -DDEBUG  -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\include"  -Os -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega4809 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega4809" -c -std=gnu99 -MD -MP -MF "boot.d" -MT"boot.d" -MT"boot.o"   -o "boot.o" ".././boot.c"
   .........\BootLoader\Debug\Makefile(76,1): error: recipe for target 'boot.o' failed
    Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "BootLoader.cproj" -- FAILED.
Done building project "BootLoader.cproj" -- FAILED.

Build FAILED.

 

 

......... is the rest of my folder structure

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK well that does not actually help very much - I think you'll have to raise a bug report with the compiler developers. they will want a complete buildable project to investigate.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As a workaround, OP might try compiling as C++.

extern "C" can prevent name-mangling where necessary.

It might even work.

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i have send a ticket to Microchip with this problem and got a response.

It seems like compiler bug. Thank you for bringing this issue and we will report this to our concern team.
As a work around, please define app_str as 16-bit pointer (uint16_t *app_ptr).

It appears that this fixes the problem for now. Hope this will be fixed in the next update

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think the error message refers to an identified error in the gcc compiler, in file expr.c, at line 4874.

There is an assert at that line.

 

          if (!MEM_P (to_rtx))
            {
              /* We can get constant negative offsets into arrays with broken
                 user code.  Translate this to a trap instead of ICEing.  */
              gcc_assert (TREE_CODE (offset) == INTEGER_CST);
              expand_builtin_trap ();
              to_rtx = gen_rtx_MEM (BLKmode, const0_rtx);
            }