Bare metal embedded lecture-4: Writing linker scripts and section placement

Поділитися
Вставка
  • Опубліковано 12 січ 2025

КОМЕНТАРІ • 84

  • @ahbarahad3203
    @ahbarahad3203 Рік тому +12

    I have been searching for something exactly like this for months on end, tried a dozen books, searched countless tutorials on the internet but i think this is hands down the best resource for arm bare metal programming, only wish i had discovered it earlier

    • @jundo374
      @jundo374 5 місяців тому

      Yeah, same issue, but for me, it's only been about one week. One week ago, I didn't even know what an MCU was.

  • @pitankar
    @pitankar 4 роки тому +51

    This is pure gold! Thanks for doing this. When you put this course up for sale, do let me know. I'll buy it :)
    I've bought all your courses already.

    • @MA-td2ic
      @MA-td2ic 4 роки тому +4

      me too :) they deserve every penny spent :D
      I am hoping that they also make a series for advanced communication interface stacks topics (i.e. LWIP, TLS, ethernet, wifi, etc...)

    • @vb9950
      @vb9950 3 роки тому

      Check Udemy

    • @FastbitEmbeddedBrainAcademy
      @FastbitEmbeddedBrainAcademy  2 роки тому +3

      Thank you Piyush for your support

    • @bobweiram6321
      @bobweiram6321 2 роки тому +4

      LOL! I was about to make the same exact statement, so I will take it a step further. These videos are exceptionally good and pure Iridium. Iridium is more rare and more expensive than gold. I believe it also has the highest melting point.

  • @ulysses_grant
    @ulysses_grant 2 роки тому +10

    Hi Kiran,
    Why do you use - 4 in SRAM2 origin calculation? (Timestamp: 10:56)
    Thanks so much for the video!

  • @padmaraghunathan4849
    @padmaraghunathan4849 3 роки тому +3

    The best ever course on linker scripts, thanks a lot Sir !!!

  • @pranit2112
    @pranit2112 4 роки тому +18

    Can you suggest books referred here, which covers all these things?

  • @prometheus05developer68
    @prometheus05developer68 4 роки тому +1

    I love you for this precise and on-point explanation of Linker scripts!

  • @AndresFH7233
    @AndresFH7233 Рік тому +1

    This class was great, I've already purchased the full course on udemy.

  • @24deepakjoy
    @24deepakjoy 4 роки тому +2

    What a stuff. So encouraging.. pls continue this series, there’s lot more to learn. 👍

  • @DimaS-nq4rq
    @DimaS-nq4rq 4 роки тому +2

    Thank you, will buy the course at a full price when it will be released!!

  • @vevasam
    @vevasam Рік тому

    @12:00 We mentioed SRAM1 and SRAM2 memories as just SRAM as they both occupy contiguous memory locations on the processor memory map. Shouldn't this be the case, we would define them explicitly in the MEMORY layout. Isn't it? Please corect me if I am wrong.

  • @anasskhaldi7840
    @anasskhaldi7840 Рік тому

    Think you for your patience and your explanation

  • @HimanshuSharma-du9nz
    @HimanshuSharma-du9nz 4 роки тому +2

    First of all thank you sir for this series its really helpful at this time.
    I been working on QEMU emulator, it will be really helpful if you could make a educational video on this topic.

  • @jimkokko5
    @jimkokko5 4 роки тому +4

    Thank you so much for these videos!
    Just wanted to add the following: I'm following along with an STM32L452RE, and in the .map file I could see that my .isr_vector table as well as any Handlers I had defined in my startup file were discarded (basically mapped to address 0x0). It turns out that instead of `*(.isr_vector)` I needed to write `KEEP(*(.isr_vector))`; the symbols are otherwise thrown away because they are not referenced somewhere else in the .o files. Just thought I'd put that out there for anyone who got stuck like me.

  • @sirajtayyabkhan6820
    @sirajtayyabkhan6820 2 роки тому

    True value addition on UA-cam! ✔

  • @omercaylan6623
    @omercaylan6623 4 роки тому +2

    Hi Kiran, thanks for everything, will you explain the "GROUP"section? How to set stack and heap and where is the stack pointer stored after set in startup?

  • @bennguyen1313
    @bennguyen1313 2 роки тому

    The fpga/board designers suddenly said 'here is another 4k memory block at address 0x40000000. How can I
    1) add it to the existing memory pool so that the linker uses it as it pleases.. and/or
    2) add it as a separate section, so that is not available for linker's general use but rather is used only for specific variables
    For example in the case of #2 above, I added in the linker's MEMORY section :
    memblock (rw) : ORIGIN = 0x40000000, LENGTH = 4k
    And at the bottom of the SECTION portion, I added:
    .NEWBLOCK (NOLOAD):
    {
    . = ALIGN(8);
    * (NEWBLOCK);
    } > memblock
    But when I declare a variable attempting to place it in that section,
    char initialized_array[100] __attribute__ ((section ("NEWBLOCK"))) = { 0 };
    int non_init_data __attribute__ ((section ("NEWBLOCK")));
    It links fine (optimazation set to 0/none), yet these variables are located in in the same space any other variable (i.e. not 0x40000000)!
    I've tried with and without the NOLOAD, adding KEEP.. adding bss to the var declaration like section(".bss.NEWBLOCK") but nothing seems to map it correctly!

  • @jdwlsn
    @jdwlsn 7 місяців тому

    Great Stuff, Curious why you made SRAM attribute RWX did you plan to store instructions in the same place as data?

  • @MohamedMohamed-zg5hg
    @MohamedMohamed-zg5hg 3 роки тому +1

    Thank you so much for this .
    I have a question is what happened if linker script is not provided to the linker ?

  • @pitankar
    @pitankar 4 роки тому +3

    I am thinking on this for quite some time now. The FLASH starts at 0x08000000 and because the isr_vector is put first, the stack pointer value is stored at 0x08000000. Is that correct?
    If so, then when the microcontroller powers up the PC would be pointing at 0x00 (please correct me if I am wrong). My understanding is that for the cortex controllers the stack pointer value needs to be stored at 0x00. But in our case it is at 0x08000000. I am a bit confused as to how the controller will pickup the stackpointer value if FLASH doesn't start at 0x0. Can you please help me understand? Am I missing something?

    • @FastbitEmbeddedBrainAcademy
      @FastbitEmbeddedBrainAcademy  4 роки тому +7

      Thats a good question . The processor produces 0x00000000 but the STM32 internal design maps it to 0x08000000 based on the settings of boot pins. so by default 0x00000000 mapped to 0x08000000 in stm32.

    • @pitankar
      @pitankar 4 роки тому +1

      Fastbit Embedded Brain Academy thanks. Now the story is complete :)

    • @Eren-yl2qi
      @Eren-yl2qi 4 роки тому

      Hi, When power up MCU and reset mechanism release the reset condition,it means reset interrupt occured and than cpu internally read(not by code just fetch it internally) 0x08000004 address and branch to actual reset handler function to execute.In the reset handler first thing to do read 0x08000000 by our code and set it to process stack pointer or main stack pointer to set up c function call environment.PC counter never points 0x08000000 address because it is initial stack address pointer it is not a opcode.This is architecture specific mechanism.

    • @khoahuynh6884
      @khoahuynh6884 4 роки тому

      to people who confuse, you may want to check this video, ua-cam.com/video/3brOzLJmeek/v-deo.html

    • @ixnisarg
      @ixnisarg 4 роки тому

      @@FastbitEmbeddedBrainAcademy is that written in any sort of document? for other controllers where to find?

  • @jankeshchakravarthy9389
    @jankeshchakravarthy9389 Рік тому +1

    hi kiran - why do you subtract 4 while calculating SRAM2 ORIGIN ?

  • @sevenfernns
    @sevenfernns 10 місяців тому

    Hi, thanks for the tutorial. One question, I checked the reference manual for stm32f407xx and it says that SRAM1 has a size of 112KB, how come we write it as 116KB in this linker script? thanks!
    EDIT: I checked other comments and it seems it was a mistake, SRAM1 indeed has a size of 112KB.

  • @linkc598
    @linkc598 6 місяців тому

    video of the week! thank you.

  • @fawad9407
    @fawad9407 4 роки тому +2

    Thank you so much for this, this is exactly what I needed and you explained it so well

  • @DevendraGuptaProfile
    @DevendraGuptaProfile 2 роки тому

    Sir on the slide linker script symbol: I guess the address are allocated after linking before that every object file maintain relocatable address against the symbols, please correct me if I m wrong.

  • @emiemi295
    @emiemi295 Рік тому

    Hey, i bought your course and it s amazing, but i would like to know how to write the linker script for an arduino(ex: atmega328p chip) and i don t know how to set the memory command because the arduino doesn t have a memory map from what i found or any other explanation on how to load the global variables into sram, any tips would be very helpful, thanks!!

  • @gauravpuri8716
    @gauravpuri8716 2 роки тому

    Very Nice set of videos!!! thanks a lot

  • @Monk-wv4ub
    @Monk-wv4ub 4 роки тому +1

    Which book should we refer for this course .

  • @yasirarafat9946
    @yasirarafat9946 3 роки тому

    Wish I could press like button 1000 times. :)

  • @Monk-wv4ub
    @Monk-wv4ub 4 роки тому +1

    Wonderful lecture .

  • @AlifSayAwais
    @AlifSayAwais 2 роки тому

    what if we remove attributes like xrw and rw ?

  • @amitdhiman420
    @amitdhiman420 4 роки тому +5

    why is 4 subtracted from SRAM 2 Origin??

  • @2605mac
    @2605mac 4 роки тому

    What IDE should I use to comfortably programming the stm32 husarion board? Are there any ide's that have libraries for it built in?

    • @vladimirtatarchevskiy5886
      @vladimirtatarchevskiy5886 4 роки тому

      Use Atollic True Studio. It's free and accessible to download from the st.com website.

  • @danielwarzecha2007
    @danielwarzecha2007 3 роки тому +1

    at 11:09 why do you -4??

    • @kirtikumarbaba
      @kirtikumarbaba Рік тому

      I also had same question. maybe a mistake?

  • @mohamedessam2760
    @mohamedessam2760 4 роки тому

    at the end of the lecture, you make _sbss = . ; and you've said location counter is tracking VMA, so the location counter is equal to SRAM , due to that it will overwite the .data section .. am i wrong ??

  • @miguelduran900
    @miguelduran900 4 роки тому

    Which one of the courses in fastbitlab page cover these topics?

  • @rahulkumar-bf4cq
    @rahulkumar-bf4cq 3 роки тому

    can you make tutorial on FOTA

  • @sad_old_git
    @sad_old_git 3 роки тому

    Does anyone have experience converting scatter files (Keil toolchain equivalent) to linker scripts?

  • @Ibrahimkhan-qo5vw
    @Ibrahimkhan-qo5vw Рік тому

    Hi ..are these knowledge available on udemy ...I have taken some advanced course...but can any one provide link for these video where this topics are covered want to buy

    • @FastbitEmbeddedBrainAcademy
      @FastbitEmbeddedBrainAcademy  Рік тому

      Hi, these videos are part of this course www.udemy.com/course/embedded-system-programming-on-arm-cortex-m3m4/

  • @codeplug
    @codeplug 3 роки тому

    Doubt: Why do we load .data to Flash first and then to SRAM? Why not we directly load it into SRAM like we do for .bss section?

    • @ghislainmj
      @ghislainmj 3 роки тому +1

      I am also wandering.
      Somebody commented before that ".data needs to be initialized somewhere". i am wandering what that means ?

    • @codeplug
      @codeplug 3 роки тому +1

      @@ghislainmj I guess I figured it out - it means you have to store that data somewhere on flash. This is needed because SRAM will lose data on restart. If we store the data directly on SRAM it will be gone after first reset/restart.

    • @ghislainmj
      @ghislainmj 3 роки тому +1

      @@codeplug that makes sense. very nice

    • @codeplug
      @codeplug 3 роки тому

      @Martin LibTec yes I meant power off. Thanks for correcting

  • @karthiknmurthy
    @karthiknmurthy 4 роки тому

    Very good Tutorial...

  • @benjwill3828
    @benjwill3828 3 роки тому +1

    thank you, very helpful!

  • @selvalooks
    @selvalooks 2 роки тому

    perfect , clean and clear !!!

  • @abhijeetraghuwanshi527
    @abhijeetraghuwanshi527 2 роки тому

    can you share the ppt please

  • @jagadeeshgottapu6115
    @jagadeeshgottapu6115 4 роки тому

    GNU compiler is there in website for 32 bit system which is mentioned in first lecture. My system is 64 bit. Will it work on my system or not. Please confirm.

  • @mislavkulas4422
    @mislavkulas4422 4 роки тому +3

    you have write SRAM1 = 116k and SRAM2 = 16k. Why you didnt then write SRAM 132k but you write it 128k?

    • @FastbitEmbeddedBrainAcademy
      @FastbitEmbeddedBrainAcademy  4 роки тому +4

      Hi. Thats a mistake. SRAM1 is 112K not 116K

    • @ulysses_grant
      @ulysses_grant 10 місяців тому +2

      @@FastbitEmbeddedBrainAcademyThank you. I'm still wondering why you put "-4" there in the calculation anyway.

  • @thineshwarv993
    @thineshwarv993 4 роки тому

    hi sir, you have not told anything about stack pointer initialization(plzz.. correct me if i am wrong).

    • @brianthompson876
      @brianthompson876 11 місяців тому

      He also didn't cover how to create the Interrupt Vector Table (a.k.a .isr_vector section) in the C or assembly code. This comment may be old, but for anyone else who is curious: The Stack Pointer Register is always initialized with the very first long word in the vector table. The default linker script for cortex-m4 processors for CMSIS has a __StackTop symbol that is calculated as at the top of the SRAM (as long as it is an 8 byte aligned address) which can be used at the top of the vector table which initializes the Stack Pointer Register on startup.
      In assembly use: `.long __StackTop` at the top of the vector table.
      In C use: `extern uint_32_t __StackTop;` then put `(void (*)(void))(&__StackTop)` at the top of the vector table.
      If you'd rather not define the symbol in the linker script:
      `#define __StackTop `
      ... In vector table ...
      `(void (*)(void))__StackTop`

  • @ravitejaj473
    @ravitejaj473 Рік тому

    Thank you very much.....✨💫🌟

  • @TSS_CLIPS
    @TSS_CLIPS 8 місяців тому

    Super lecture.

  • @hownottobeanengineer3927
    @hownottobeanengineer3927 2 роки тому

    very nice lecture

  • @Danielmelvin7
    @Danielmelvin7 4 роки тому

    Awesome stuff!!

  • @hgl9590
    @hgl9590 4 роки тому

    Hi,
    Can we just load the .data section to SRAM, i.e. set LMA to SRAM, so that we do not need to copy the the .data in the Reset_Handler().

    • @stana.281
      @stana.281 3 роки тому

      You have to initialize the data in SRAM from somewhere

  • @mogasatigopikrishna2025
    @mogasatigopikrishna2025 4 роки тому

    Please upload lec5 .

  • @raghul1208
    @raghul1208 3 роки тому

    thank you for the content

  • @ashutoshtiwari2611
    @ashutoshtiwari2611 Рік тому

    10 crore bahut sahi

  • @mohamedessam4704
    @mohamedessam4704 4 роки тому +1

    at the end of the lecture, you make _sbss = . ; and you've said location counter is tracking VMA, so the location counter is equal to SRAM , due to that it will overwite the .data section .. am i wrong ??