Cannot get SAME70 bootloader working

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

Hi,

 

I am trying to implement the bootloader provided by Atmel for the SAMV7/SAME7 (search "AT16743: SAM V7/E7/S7 Safe and Secure Bootloader") to a user board.

 

First issue: internal SHA1 hash return wrong value.

 

Looking at the PC-tools code (AES_BOOTLOADER.pl), the hash is performed on the whole file minus 128 bytes

	$truncate_size = $filesize - 128;
	open $fh, ">>" ,$input_file;
	truncate $fh,$truncate_size;
	close ($fh);
	unless(open $in,$input_file) {
		warn "$0 $!";
		next;
	}
	binmode($in);
	my $sha1_out = Digest::SHA1->new;
	$sha1_out->addfile($in);
	my $sha1 = $sha1_out->hexdigest;

But inside bootloader code :

CalculateICM(pUserApplicationData->u32UserApplicationStartAddress, 
			(pUserApplicationData->u32UserApplicationAllocationSize - sizeof(TS_SHA_Digest)), (U32*)u32SHA_1_Digest);

only 64 bytes (sizeof(TS_SHA_Digest)) are removed from the application code. I corrected that by removing also 128 bytes as in PC-tools, but no more success, SHA1 hash is always bad.

 

So at the moment, I force the Hash verification to true to go next step of booloader.

 

The second issue concerns the jump to the ResetHandlet at the end of the bootloader, when the pointer of function is called the application crash.

 

	/** Call Application reset handler */
	fpApplicationResetHandler = (fpJumpHandler)(*((U32*)(pUserApplicationData->u32UserApplicationStartAddress + 4)));
	(*fpApplicationResetHandler)();

what I don't understand is that at the beginning of the code is (u32UserApplicationStartAddress ):

 

0x0040C000  e8 83 40 20 3d 1e 41 00

 

So the vector of the Resethandler point to 0x00411E3D

 

But in the .map file it is written that:

 .text.Reset_Handler
        0x00411e3c       0x80 src/ASF/sam/utils/cmsis/same70/source/templates/gcc/startup_same70.o
        0x00411e3c                Reset_Handler

is it normal that the address is shifted by one ?

 

Does anyone has experiment of this bootloader and can give me some help ?

 

Tanks in advance

 

TG

 

 

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

Bit 0 is not included in the address used (i.e., the used address is always even). Bit 0 is used for the "T" bit that when 1 selects thumb instructions (it  will always be 1 for SAME70 since only thumb instructions are supported).

/Lars

 

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

Thanks Lajon for the explanation, I read that about the BX instruction, but I didn't know if the use of the thumb instructions set was automatically applied.

So this is not the explanation of why my system crashes after the jump to the application.

 

To know what happens, it could be great to be able to continue in debug from the bootloader to the application. But I haven't found a way to debug both  bootloader and application projects, simultaneously in Atmel Studio. I did that in the past with other projects (also bootaloader and app) in MPLAB, but searching in forums, it seems that this is not possible in Atmel Studio. Does anyone have more information on this point ?

 

TG