Jump to content


Photo

Why am i unable to place code in custom ROM (SECRET_IROM1 )section?

arm keil stm32

  • Please log in to reply
4 replies to this topic

#1 Maccle

Maccle

    Serf

  • Lurker
  • 1 posts

Posted 02 March 2018 - 04:37 PM

I am trying to place a variable named secret_key at location 0x08002000 in STM32Nucleo-board which has STM32L476RG(www.kynix.com/Parts/158001/STM32L476RGT6.html) on board with 1MB flash.

Question 1: Why am i unable to place code in custom ROM (SECRET_IROM1 )section?
Question 2: What is the mistake i am doing?

I am still newbie to Linker topic.

I am able to do it(still do not undestnad, why other RO section also follows my new address of secret_key variable) if i define the address which is in the default section for RO in the scatter file. If i create a new section, mapping is not happening. I can see the address assigned as expected but the value of the secret_key is not visible at that location.

below image shows what happens when i declare the address out of range from the default section.

Code section where variable is declared:

unsigned long long int array4[6]={0};
unsigned long long int array[6]={12};

unsigned long long int arra2[4] = {0x1111111111111111,0x2222222222222222,0x3333333333333333,0x4444444444444444};
const long secret_key[3] __attribute__((section(".ARM.__at_0x8001800"))) = {0xABABABAB,0xCDCDCDCD, 0xEFEFEFEF};
extern int addsum(int, int);

int main()
       {
    long long int array3[100] = {1,2,3,4,5,6,7};
    array[1] = arra2[1] - array[0]+array3[1]*2+array3[2]*2+addsum(array[1],array[2])+array4[2]+(int)secret_key[0];
    while(1);
}

Memory map below:

dxqSA.jpg

 

Scatter file contents below:

; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************

LR_IROM1 0x08000000 0x00100000  {    ; load region size_region
  ER_IROM1 0x08000000 0x00002000  {  ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$$Sections)
   .ANY (+RO)
  }

  SECRET_IROM1 0x08002000 0x00000030  {  ; load address = execution address
  *(.ARM.__at_0x8001800) ; secret key
  }

  RW_IRAM1 0x20000000 0x00000100  {  ; RW data
   project2.o (+RW)
   }

  RW_IRAM2 0x20000100 0x00000100  {  ; RW data
   project2.o (+ZI)
   }

  RW_IRAM3 0x20000200 0x00000300  {  ; RW data
   project.o (+ZI)   
  }

  RW_IRAM4 0x20000500 0x00000200  {  ; RW data
   project.o (+RW)   
  }

  RW_IRAM5 0x20000700 0x00001000  {  ; RW data
   .ANY (+RW,+ZI)   
  }
}

Second case: where it doesn't work

Code here:

unsigned long long int array4[6]={0};
unsigned long long int array[6]={12};

unsigned long long int arra2[4] = {0x1111111111111111,0x2222222222222222,0x3333333333333333,0x4444444444444444};
const long secret_key[3] __attribute__((section(".ARM.__at_0x8002100"))) = {0xABABABAB,0xCDCDCDCD, 0xEFEFEFEF};
extern int addsum(int, int);

int main()
       {
    long long int array3[100] = {1,2,3,4,5,6,7};
    array[1] = arra2[1] - array[0]+array3[1]*2+array3[2]*2+addsum(array[1],array[2])+array4[2]+(int)secret_key[0];
    while(1);
}

associated scatter file here:

; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************

LR_IROM1 0x08000000 0x00100000  {    ; load region size_region
  ER_IROM1 0x08000000 0x00001800  {  ; load address = execution address
   *.o (RESET, +First)
   *(InRoot$$Sections)
   .ANY (+RO)
  }

  SECRET_IROM1 0x08002100 0x00000030  {  ; load address = execution address
  *(.ARM.__at_0x8002100) ; secret key
  }

  RW_IRAM1 0x20000000 0x00000100  {  ; RW data
   project2.o (+RW)
   }

  RW_IRAM2 0x20000100 0x00000100  {  ; RW data
   project2.o (+ZI)
   }

  RW_IRAM3 0x20000200 0x00000300  {  ; RW data
   project.o (+ZI)   
  }

  RW_IRAM4 0x20000500 0x00000200  {  ; RW data
   project.o (+RW)   
  }

  RW_IRAM5 0x20000700 0x00001000  {  ; RW data
   .ANY (+RW,+ZI)   
  }
}

memory map below:

DXDex.jpg


Edited by Maccle, 02 March 2018 - 04:39 PM.


#2 Rybags

Rybags

    Immortal

  • Super Hero
  • 35,847 posts

Posted 02 March 2018 - 04:52 PM

Why is the high byte of the address 08?  According to that page it's only a 1 Megabit flash on that microcontroller which = 128K which would have a highest possible address of 1FFFF.

 

(not real big on C programming here so it might not be your problem)



#3 Jeruselem

Jeruselem

    Guru

  • Atomican
  • 15,000 posts
  • Location:Not Trump-Land

Posted 02 March 2018 - 08:23 PM

From this ... I'm no  expert BTW with these ARM thingos

https://jcastellssal...cortex-m0-boot/

 

The firmware/app code lives in 0x08002000.


“We’re not going to stop the wheel. I’m going to break the wheel.” - Daenerys Targaryen

 

"We have some of the most beautiful hookers in the world" - Putin to Trump


#4 Rybags

Rybags

    Immortal

  • Super Hero
  • 35,847 posts

Posted 02 March 2018 - 08:35 PM

I should have thought of that... and it looks like his code does consider that base address.  Likely boot time code might be location fixed, generally it's higher level stuff that's relocatable.

 

I would also assume there should be PC based emulation available so you'd not needlessly have to reflash every time you want a trivial change during development.



#5 Jeruselem

Jeruselem

    Guru

  • Atomican
  • 15,000 posts
  • Location:Not Trump-Land

Posted 02 March 2018 - 09:39 PM

I got no idea but I spotted the bootloader lives around 0x08000000 so relocating to address somewhere less problematic else might be a good idea.

 

http://blog.atollic....ng-a-bootloader

 

bootloader1.png?t=1519133233324&width=48


Edited by Jeruselem, 02 March 2018 - 09:46 PM.

“We’re not going to stop the wheel. I’m going to break the wheel.” - Daenerys Targaryen

 

"We have some of the most beautiful hookers in the world" - Putin to Trump





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users