background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

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

input logo icon
Video tags
|

Video tags

arm cortex
cortex m4
arm embedded
bare metal embedded
embedded systems tutorial
stm32 tutorial
arm programming tutorial
keil programming
stm32cube
microcontroller
microcontroller programming
embedded software
stm32 discovery board
cross toolchain
build process
embedded projects
stm32
object file
makefile
linker script
linker script command
linker script from scratch
Subtitles
|

Subtitles

00:00:00
in this lecture let us understand about
00:00:01
linker scripts
00:00:03
first of all let's learn what exactly is
00:00:06
a linker script linker script is a text
00:00:09
file which explains how different
00:00:11
sections of the object files should be
00:00:14
merged to create an output file
00:00:18
linker and locator combination assigns
00:00:21
unique absolute addresses to different
00:00:25
sections of the output files by
00:00:27
referring to the address information
00:00:29
mentioned in the linker script linker
00:00:33
script also includes the code and data
00:00:35
memory address and size information
00:00:39
so inside the linker script you have to
00:00:41
mention the various memories which are
00:00:44
present on your target board and also
00:00:46
you have to mention the size and address
00:00:49
information
00:00:51
linka scripts are written using a new
00:00:53
linker command language and GNU linker
00:00:57
script has the file extension of dot LD
00:01:01
you must supply linker script at the
00:01:05
linking face to the linker using - T
00:01:08
option we'll see that when we run the
00:01:11
command
00:01:12
to write a linker script you have to
00:01:15
first understand different commands used
00:01:18
to explain various things in the linker
00:01:22
script there are commands like entry
00:01:25
memory sections keep a line and at I
00:01:28
mean there are many commands but I have
00:01:30
just listed here some of the important
00:01:32
commands
00:01:33
first let's explore about the entry
00:01:35
command this command you have to use to
00:01:39
set the entry point address information
00:01:42
in the header of final year left file
00:01:47
generated what this command does is it
00:01:50
just a populate entry point address
00:01:53
information in the LF file header that's
00:01:57
it in our case reset handler is the
00:02:01
entry point into the application because
00:02:05
that is the first piece of code that
00:02:07
executes right after the processor reset
00:02:10
isn't it the debugger uses this
00:02:14
information to locate the first function
00:02:17
to execute this is actually not a
00:02:21
mandatory command to use but this is
00:02:24
required when you debug the e.l.f file
00:02:27
using the debugger such as gdb this is
00:02:30
given just for the debugger say strictly
00:02:33
speaking it is not required this is how
00:02:36
you should use the entry command entry
00:02:39
and in the parenthesis you have to give
00:02:42
the symbol name that is the function
00:02:44
name which is an entry point into your
00:02:47
application in our case we are going to
00:02:49
write something like this entry reset
00:02:51
handler where this at handler is a
00:02:54
function name or you can also call that
00:02:56
symbol
00:02:57
let's use the entry command and let me
00:03:00
get back to this memory come on let's
00:03:02
head over to my workspace and let's
00:03:04
create one linker script here you have
00:03:08
to give the file extension dot LD but
00:03:11
let me open my come on front here
00:03:16
I'm going to create one linker script
00:03:18
let me call it as stm32 LS a linker
00:03:24
script and I'm going to give the
00:03:26
extension dot LD
00:03:30
here it is let me open this file first
00:03:36
let's use the entry command you can use
00:03:39
the entry command so make sure that all
00:03:41
our capital letters after that open the
00:03:44
parentheses and here you have to give
00:03:46
the a symbol name symbol name is you
00:03:50
have to refer to your startup code here
00:03:55
this is our entry point let's copy this
00:03:59
function name and paste here that's it
00:04:02
there is no semicolon here you should
00:04:04
not give any semicolon this will set the
00:04:07
entry point address in the final e.l.f
00:04:10
which you are going to generate next
00:04:13
let's explore about the memory command
00:04:16
this command allows you to describe the
00:04:19
different memories present in the target
00:04:21
and start address and size information
00:04:24
the linker uses information mentioned in
00:04:28
this command to assign addresses to
00:04:32
merge sections that is what we call as
00:04:35
relocation our sections must be
00:04:38
relocated to different addresses that is
00:04:41
done by the address what you mentioned
00:04:42
in the linker script by using the memory
00:04:45
command the information is given under
00:04:47
this command also helps the linker to
00:04:48
calculate the core and data memory
00:04:51
consumed so far by the application and
00:04:54
throw an error message if data code heap
00:04:58
or stack areas cannot fit into our level
00:05:01
size by using memory command you can
00:05:05
fine tune various memories available in
00:05:08
your target and allow different sections
00:05:10
to occupy different memory area
00:05:12
typically one linker script has one
00:05:15
memory command so you will generally
00:05:18
find only one memory command inside a
00:05:21
linker script let's see the syntax of
00:05:24
memory command you had to use the name
00:05:28
memory here that's a command name which
00:05:31
must be in capital letters then you have
00:05:33
to do the body of that come on and
00:05:35
inside the body you can write many
00:05:38
statements in this format the memory
00:05:42
statement has three parts this is a
00:05:45
label this is a worry gene comma Lent a
00:05:52
label will have its own attribute
00:05:54
attribute list
00:05:57
a tribute if used it is optional
00:05:59
actually but if used you have to give
00:06:02
that in the parentheses
00:06:04
label : origin and comma length let's
00:06:11
understand what exactly the label label
00:06:16
defines name of the memory region it is
00:06:19
just a label or a user-defined name
00:06:22
given to a particular memory region this
00:06:26
name will be later referenced by other
00:06:29
parts of the linker script by using this
00:06:32
statement you just give a name for a
00:06:34
memory region which is present in your
00:06:36
target and after that using this very
00:06:41
gene name this is a standard key word of
00:06:44
the linker you have to use exactly like
00:06:46
this using this name you have to mention
00:06:50
the worry gene address or the start
00:06:52
address of that memory region that's why
00:06:56
this defines religion address of the
00:06:58
memory region after that you have to
00:07:01
mention the length information defines
00:07:04
the length information of the memory
00:07:05
region again you have to use the
00:07:07
standard name length here length is
00:07:11
equal to you have to mention the size
00:07:13
here don't worry when we see the example
00:07:15
it will get cleared memory command may
00:07:19
have multiple such statements
00:07:22
let's move forward let's talk about this
00:07:25
attribute this defines the attribute
00:07:28
list of the memory region valid
00:07:31
attribute list must be made up of these
00:07:34
characters which are mentioned in this
00:07:37
table if you mention are here then that
00:07:41
means read only Section W means read and
00:07:44
write sections X means sections
00:07:47
containing executable code like that you
00:07:50
can mention these attributes either in
00:07:52
capital letters or in small letters and
00:07:55
you can also combine two or more
00:07:59
attribute letters so we'll see that when
00:08:02
we do an exercise let's move forward
00:08:05
let's take an example of our
00:08:08
microcontroller stm32f4 VD t6 which has
00:08:12
1 MB of flash size and it has s Ram one
00:08:18
of 112 kilobytes and sram2 of 16
00:08:22
kilobytes let's see how we can write a
00:08:25
memory command for this let's type the
00:08:28
command memory and then give the body by
00:08:31
using these curly brackets after that
00:08:34
let's define our level memory regions of
00:08:38
our target in our target our 3 memory
00:08:41
regions are available flash sram1 and
00:08:44
sram2 first let's explain the first
00:08:48
memory region first give the label for
00:08:51
the memory region let me call that code
00:08:54
memory or you can also call it as Rob or
00:08:58
you can also call it as flash so any
00:09:01
name you wish you can give I will just
00:09:03
use flash and attribute list you have to
00:09:07
give in the parentheses I would give a
00:09:10
readable and executable because flash
00:09:13
memory contains code isn't it
00:09:16
that is not writable by the user program
00:09:20
that's why I would vomit w here I would
00:09:24
just use read end executable : let's
00:09:29
write the origin for that you have to
00:09:31
use the standard name origin is equal to
00:09:35
what is the original flash 0 cross 0 8 0
00:09:40
0 0 0 0 0 comma length is equal 2024
00:09:49
kilobytes for the kilobytes you can
00:09:52
write k that will be expanded to number
00:09:55
of kilobytes or you have to mention
00:09:58
after multiplying with a thousand 24
00:10:01
years otherwise just mentioned k here so
00:10:04
that is a correct syntax no problem and
00:10:06
after that let's explain the sram1
00:10:09
sram1 you can read write execute you can
00:10:14
even execute code from s wrap origin is
00:10:19
equal to 0 cross 2 0 0 0 0 0 0 0 and
00:10:25
length is equal to 160 k as ram 2 again
00:10:33
attribute i can use RW x origin is equal
00:10:39
to here you can use so what is the
00:10:42
origin of s ramp to the end of SRAM 1 is
00:10:45
nothing but origin of SRAM 2 and you can
00:10:48
calculate something like this you can
00:10:49
copy this here plus
00:10:52
this 116 K minus 4 year today
00:10:58
this is the origin or you can calculate
00:11:02
the final value and you can write it
00:11:04
after that length is equal to 16 K if
00:11:10
you have more memories in your
00:11:12
microcontroller than you can mention
00:11:13
them only if you have any plan to use
00:11:16
them in the linker script otherwise need
00:11:18
not to mention for example backup SRAM
00:11:22
so this microcontroller also has backup
00:11:24
a strap that you can explain here and if
00:11:28
your microcontroller has CCM memory and
00:11:30
if you have any plan to use that by
00:11:32
using the linker script then you can
00:11:34
explain the CCM memory and various other
00:11:36
things for our example we only want to
00:11:41
use SRAM and the flash that's why I
00:11:46
would just Club this sram1 and sram2 to
00:11:51
just make it as SRAM I would not need
00:11:54
these two segregations here since in
00:11:58
this example we are just using flash as
00:12:00
our ROM and SRAM as our readwrite memory
00:12:03
I would just use two statements here I
00:12:07
would just consider SRAM 1 & 2 as whole
00:12:11
SRAM that's why I would just write SRAM
00:12:15
here and I would just write it 128k
00:12:21
your memory come on which explains two
00:12:23
memory regions one is code memory that
00:12:26
is this one and another one is data
00:12:29
memory which is estra so let's explore
00:12:33
about sections command sections command
00:12:36
is used to create different output
00:12:39
sections in the final e.l.f generated
00:12:43
this is an important command by which
00:12:45
you can instruct the linker how to merge
00:12:48
the input sections to ield an outer
00:12:51
section this command also controls the
00:12:54
order in which different output sections
00:12:57
appear in the final
00:12:58
LF file generated by using this command
00:13:03
you also mention the placement of a
00:13:06
section in a memory region for example
00:13:08
you can instruct the linker to place the
00:13:12
dot text section in the flash memory
00:13:15
region which is described by the memory
00:13:18
command let's see one example of
00:13:19
sections command or to use this command
00:13:22
so it all starts with the command
00:13:25
keyword section this is a standard
00:13:28
keywords you have to write in all
00:13:30
capital letters and after that this is a
00:13:33
body
00:13:35
factions command is used to create
00:13:37
different number of output sections in
00:13:42
the output file for example in this case
00:13:45
the output file generated will contain
00:13:48
two sections one is dot text section and
00:13:52
another one is dot data section
00:13:55
this command instruct the linker to
00:13:59
create two sections in the final output
00:14:02
file generated in this case the output
00:14:06
file is nothing but dot e.l.f file the
00:14:10
sections will appear exactly in this
00:14:12
order
00:14:14
first dot text section will appear
00:14:16
followed by dot data section let's take
00:14:19
this example this is one of the output
00:14:22
section which we want to create here
00:14:25
this is a label of the output section
00:14:27
this label can be anything it depends on
00:14:30
you you can give any name you want but
00:14:32
you have to follow some standard naming
00:14:35
convention this is the output section
00:14:37
name this is a body and this gives the
00:14:41
address information to the linker and
00:14:43
the locator where to place this section
00:14:46
in the memory this is a combination of
00:14:49
VMA and LMA where element stands for
00:14:52
load memory address and VMA stands for
00:14:56
virtual memory address and more on that
00:14:57
we'll see later how to use the syntax
00:15:00
property but this actually gives the
00:15:03
section placement information in the
00:15:06
memory this output section is used to
00:15:09
merge all other sections of individual
00:15:15
input files
00:15:16
how many input files will have got in
00:15:18
your project so we have got three input
00:15:21
files isn't it main dot o any d dot o
00:15:24
and we have one more start up daughter
00:15:26
as I described in the earlier slides and
00:15:29
each object file contains its own
00:15:33
different sections like text data BSS
00:15:36
constant by using this output section we
00:15:40
are going to merge all sections of input
00:15:45
files like this let's use this text
00:15:49
section to merge all is our vector
00:15:53
section of all input files merge all dot
00:15:57
text section of all input files and
00:15:59
merge all dot ro data section of all
00:16:03
input files
00:16:05
after that just mentioned our dressier
00:16:07
where those sections should go and after
00:16:13
that let's use another output section
00:16:15
dot data to merge our data section of
00:16:19
all in files let's edit our linker
00:16:22
script to create some output sections
00:16:25
I'm going to write sections here and I'm
00:16:29
going to open the brackets the first
00:16:32
output section what I want to see in the
00:16:34
output PLF generated is at the dot txt
00:16:40
this is the name of the output section
00:16:42
or label you have to give : and its body
00:16:50
here let's merge text section of Maine
00:16:57
dotto early dotto and startup daughter
00:17:03
how do you write this you can use one
00:17:06
shorthand notation so you can mention
00:17:09
something like this you can use dot txt
00:17:13
of all input files you can use the
00:17:16
wild-card character e of stock asterisk
00:17:20
you can use this denotes consider dot
00:17:23
txt of all input files instead of
00:17:27
writing dot txt of Maine dot o LD dot Oh
00:17:30
Charlotte oh you can use this shorter
00:17:32
notation if you again refer to this
00:17:35
diagram this explains storage of final
00:17:38
executable in code memory the initial
00:17:41
code space must contain the vector table
00:17:43
after that only the dot tex action
00:17:47
should appear we have to follow this
00:17:50
order otherwise our application will not
00:17:52
work properly that's why what you have
00:17:55
to do is you have to first merge the dot
00:17:59
is our underscore vector section dot is
00:18:02
our underscore vector of all input files
00:18:06
you can use wildcard character for this
00:18:10
application it is not required because
00:18:12
there is only one is our vector section
00:18:14
but that's okay this is a generic
00:18:17
statement
00:18:19
after that according to our diagram we
00:18:23
want to place dot Auto data let's do
00:18:27
that star off dot our Oh ditto this
00:18:32
output section comprises of all these
00:18:35
individual files section we just created
00:18:40
one output section that is dot txt now
00:18:43
you have to decide where you wish to
00:18:47
store this section in the memory that
00:18:50
means you have to mention a two memory
00:18:55
regions for this section one is VMA and
00:18:59
another one is LM a where we ma stands
00:19:02
for virtual memory address and LM a
00:19:04
stands for load memories before that you
00:19:07
have to ask one question so do you
00:19:08
relocate this section in your startup
00:19:11
code no we don't relocate this this is
00:19:15
going to be stored in the wrong space
00:19:18
ROM in our cases flash
00:19:22
it doesn't have any relocatable address
00:19:24
that means VMA and LMA are saved for
00:19:27
this section that is flash this section
00:19:33
should go to flash and flash begins from
00:19:36
here that's why next step is you have to
00:19:40
mention the section placement by using
00:19:43
the symbol greater than what you do is
00:19:47
give a greater than symbol and here you
00:19:50
have to mention the VMA then use the
00:19:52
command at greater than symbol give
00:19:56
space and now mention the LMA we MA in
00:20:00
this case is flash and LM a is also
00:20:03
flash once the linker sees this what it
00:20:08
does is it generates absolute addresses
00:20:11
for this section and that address is
00:20:16
fall in the memory region what you
00:20:20
mentioned in the VMA after that the
00:20:23
linker also generates load addresses for
00:20:27
this section
00:20:29
that addresses fall in this memory
00:20:33
region what you mentioned after the at
00:20:36
command
00:20:37
don't worry so again when we disassemble
00:20:40
the final executable by using
00:20:42
disassembly tool you can understand more
00:20:46
in this case both VMA and LMA are sale
00:20:49
you need not to write something like
00:20:51
this you can just omit this so you can
00:20:55
just mention like this this means that
00:20:57
we am a and LM a are safe
00:21:01
let's create the next section the odd
00:21:03
data and again I'm going to merge data
00:21:08
sections of all the input files here the
00:21:12
dot data section is relocatable isn't it
00:21:14
this must be stored in flash but the
00:21:17
startup code has to copy this section
00:21:20
from flash to SRAM
00:21:22
that's why the load address is fixed
00:21:25
that is flash in the flash first this
00:21:29
section will appear and right up to that
00:21:31
this section will appear that's why you
00:21:34
have to mention load address as flash
00:21:38
whatever the VMA and the VMA in this
00:21:41
case is Ezra
00:21:44
when linker sees this so it will
00:21:46
generate load address for this section
00:21:48
which falls in flash right after this
00:21:51
section but the absolute address of this
00:21:55
section will fall in the memory region
00:21:58
SRAM which starts from this memory
00:22:02
location I will show you practically so
00:22:04
when we disassemble the code that's it
00:22:07
we created two sections this is for
00:22:10
initialized data
00:22:12
what about uninitialized data that we
00:22:15
call as VSS let's create one more
00:22:18
section BSS and again this is nothing
00:22:21
but collection of all individual BSS
00:22:24
sections of different input files and as
00:22:28
I said this will not get stored in the
00:22:30
flash that's why it has only we MA
00:22:35
so it doesn't have any l ma we ma is
00:22:39
nothing but Ezra we just created a
00:22:44
linker script which can generate 3
00:22:47
output sections for the final executable
00:22:52
and we have to keep improving this
00:22:53
linker script this is not final in the
00:22:56
next lecture we will explore one more
00:22:58
important concept of the linker script
00:23:01
that is location counter
00:23:04
now we created our linker script
00:23:07
according to this memory layout and the
00:23:10
data section which is stored in the
00:23:13
flash needs to be relocated by the
00:23:16
startup code but to relocate this
00:23:19
section you need couple of information
00:23:21
at least you should know the boundary
00:23:24
Val ro data ends where this section ends
00:23:28
so you should know this information and
00:23:31
after that you should also know the size
00:23:35
or if you know the beginning address or
00:23:40
if you know the ending address of our
00:23:42
data section and if you know the ending
00:23:46
address off dot data then you can
00:23:50
calculate the size you can use this
00:23:53
information in the C startup code to
00:23:57
relocate the section otherwise you can't
00:24:00
do it isn't it
00:24:02
now the question is how do you trace
00:24:04
such boundary information in your C
00:24:07
program the answer to that question is
00:24:10
the boundaries can be tracked inside the
00:24:14
linker script and after that that
00:24:16
boundary information can be passed to
00:24:19
the C program for that the linker gives
00:24:23
you one nice feature called location
00:24:27
counter this is a special link a symbol
00:24:31
denoted by a dot location counter is
00:24:36
denoted by a dot this symbol is called
00:24:40
location counter because linker
00:24:43
automatically updates this symbol with
00:24:47
location information you can use the
00:24:51
symbol inside the linker script to track
00:24:53
and define boundaries of various
00:24:56
sections you can also set location
00:25:00
counter to any specific value while
00:25:02
writing linker script location counter
00:25:06
should appear only inside the sections
00:25:08
command you have to remember that so you
00:25:11
cannot use that outside the sections
00:25:14
command that would throw you linker
00:25:16
error
00:25:18
the location counter is implemented by
00:25:21
the size of the output section that
00:25:24
helps you to track the boundary
00:25:27
let's make use of location counter in
00:25:29
our linker script before that we had to
00:25:34
explore one more thing that is linker
00:25:36
script symbols creating linker script
00:25:40
symbols we use location counter symbols
00:25:43
with other linker script symbols
00:25:48
let's explore about the linker script
00:25:50
symbol in the next lecture
00:25:53
in this lecture let's understand about
00:25:55
linker script symbol and later we can
00:25:58
understand how to use the location
00:26:00
counter and linker script symbols
00:26:02
together
00:26:04
what exactly the symbol a symbol is the
00:26:08
name of an address or memory location
00:26:11
symbol declaration is not equivalent to
00:26:15
a variable declaration what you do in
00:26:18
your C application
00:26:20
for example consider a tea program let's
00:26:24
say main door see and let's say you have
00:26:27
this statement what is this this is a
00:26:31
variable definition
00:26:33
here your goal is to store a value
00:26:36
hundred into some memory location
00:26:39
basically this is a global variable if
00:26:42
it is a global variable then it will go
00:26:44
into that HR memory but you don't know
00:26:47
the location if you want to modify the
00:26:50
value of this variable then you just do
00:26:53
this here you don't know the location
00:26:56
where you are going to keep this value
00:26:58
50 you just write by using the variable
00:27:03
name but at the background
00:27:06
it must be converted into an address
00:27:09
manipulation at the end of the day
00:27:12
everything is addressed so the value 50
00:27:14
must go to some addresses endures in
00:27:16
this case some memory location must be
00:27:19
modified to put the value 50 the
00:27:23
question is how this variable name is
00:27:26
replaced by the address that happens
00:27:31
because of the symbol table when you
00:27:34
compile this program may not see you
00:27:37
know that it will get converted into
00:27:39
main dot oh and in the main dot oh the
00:27:43
compiler maintains a table called symbol
00:27:47
table for the compiler this is not a
00:27:51
variable name it's a variable name for
00:27:55
you for the programmer for the compiler
00:27:58
or linker terminology we call it as a
00:28:01
symbol name it's a symbol name a symbol
00:28:05
is the name given for an address the
00:28:09
symbol table majorly maintains two
00:28:11
columns one is address and another one
00:28:15
is symbol name here you can see that
00:28:18
there are two symbols one is this one
00:28:21
that's a variable name my value and it
00:28:25
has its corresponding address when you
00:28:29
do this that means here you are trying
00:28:32
to modify an address
00:28:36
for you you are trying to modify
00:28:38
variable but at the background you are
00:28:41
trying to modify an address so the
00:28:43
address will be resolved by looking into
00:28:46
the symbol table which is maintained by
00:28:49
the compiler in the object file if you
00:28:52
consider this function definition here
00:28:56
this is a function name from one
00:29:00
basically the function definition
00:29:02
belongs to the text section restored in
00:29:05
the code memory this is also maintained
00:29:08
in the symbol table
00:29:10
here this is a symbol name from one is a
00:29:14
symbol name and this is the Associated
00:29:16
address of that function in the code
00:29:20
memory
00:29:22
like that every object file are
00:29:24
maintains the symbols and its associated
00:29:28
addresses please remember that in your C
00:29:31
program
00:29:32
you don't write symbol what you do you
00:29:35
do variable definition you do variable
00:29:38
declaration you do function definition
00:29:42
so you don't create any symbols in the C
00:29:44
program symbols are created and
00:29:47
maintained by the compiler that's why we
00:29:51
never worry about creating symbols in
00:29:54
the C program now the scenario is
00:29:57
different not worry about creating some
00:29:59
symbols because we are writing the
00:30:02
linker script and inside the linker
00:30:05
script we want to catch these boundary
00:30:08
information how do you store the
00:30:10
boundary information so would you create
00:30:12
variables no you can't because we are
00:30:15
not writing any dot C file which is
00:30:17
going to be compiled by the C compiler
00:30:19
isn't it we are writing linker script
00:30:22
which is just a text file which is going
00:30:25
to be passed by the linker that's why we
00:30:29
cannot create in variables to catch or
00:30:31
store the boundary information and other
00:30:35
things that's why we have to create some
00:30:38
symbols that's what we call as linker
00:30:41
script symbols
00:30:43
take a look into this example so here I
00:30:45
have created a couple of symbols symbols
00:30:47
is written exactly the same way how you
00:30:51
write variable definition for example
00:30:54
consider this
00:30:56
please note that this is symbol
00:30:59
definition or symbol declaration this is
00:31:02
not a variable
00:31:03
what is symbol a symbol is the name
00:31:05
given for an address
00:31:07
this is the value of the symbol when
00:31:11
linker sees this because compiler will
00:31:15
not see this why because it is in the
00:31:17
linker script linker script will be
00:31:19
passed to the build system during
00:31:21
linking stage integer linker is going to
00:31:24
see this when linker sees this entry it
00:31:28
is going to add this entry to the symbol
00:31:31
table of the final executable that's it
00:31:36
symbol name and its associated value
00:31:39
like this this is also one more symbol
00:31:45
declaration here you can see that I have
00:31:48
created one more symbol to catch the end
00:31:52
of text section here the symbol ladies
00:31:56
end of text and that is is equal to the
00:32:02
dot operator that is the location
00:32:04
counter remember what I said in the
00:32:06
location counter explanation let me open
00:32:09
that the location counter is incremented
00:32:13
by the size of the output section this
00:32:17
will happen automatically by the linker
00:32:19
at the beginning location counter is
00:32:23
equal to the VMA that is assumed by the
00:32:27
linker
00:32:29
that means dot is equal to initially
00:32:32
disorders zero cross 0 8 0 0 0 0 0 0
00:32:41
here location counter value will be
00:32:45
incremented by the size of the text
00:32:49
section that's why this symbol will now
00:32:54
hold the end of text section the address
00:32:59
of end of text section you get the
00:33:02
boundary now you can export this symbol
00:33:06
to the C program and you can access the
00:33:09
exact address where the text section
00:33:12
ends so we'll see that later similarly
00:33:15
you can create any number of for linker
00:33:18
script symbols and you can store some
00:33:20
value here and you can access that from
00:33:24
the C program we will create some more
00:33:27
linker script symbols to catch the
00:33:30
boundaries of different sections with
00:33:33
that note I would like to end this
00:33:34
lecture and in the next lecture let's
00:33:36
edit our linker script to create some
00:33:39
symbols in this lecture let's edit our
00:33:41
linker script to create some symbols
00:33:45
let's refer to this diagram to catch
00:33:47
some boundary addresses
00:33:51
first of all in this diagram so this is
00:33:53
a place where the text section ends this
00:33:57
is the beginning of data section in the
00:34:02
wrong we should know this address if we
00:34:06
know this address then from this address
00:34:09
we can start copying from flash to SRAM
00:34:13
and we should also know the start
00:34:17
address in the data memory this is the
00:34:21
source address and this is the
00:34:25
destination address we should know both
00:34:28
source and destination addresses
00:34:31
after that we should know the size of
00:34:33
this data section that is how many bytes
00:34:36
of data we want to copy from code memory
00:34:40
to data memory we at least need all
00:34:43
these three information let's create
00:34:47
some symbols to store these values let's
00:34:50
get into the linker script and let's
00:34:53
create one symbol you have to select
00:34:56
some meaningful symbol name now the
00:34:58
rules what you follow to write a
00:35:00
meaningful and legal variable name the
00:35:02
same rules you can follow to write a
00:35:04
symbol name let me create one symbol
00:35:07
name underscore etext that is end of
00:35:11
text and I equate this to the location
00:35:16
counter the dot operator remember that
00:35:19
this symbol declaration must be
00:35:22
terminated with a semicolon what did I
00:35:25
do here I stored the value of location
00:35:30
counter into a symbol name underscore e
00:35:34
text as I said in the previous video or
00:35:38
this location counter symbol will
00:35:41
contain the updated address information
00:35:44
of this text section
00:35:48
this is end of text isn't it and after
00:35:51
that so here let me create some more
00:35:53
symbols
00:35:57
as data start of data is equal to the
00:36:01
location counter you have to remember
00:36:03
this location counter always tracks VMA
00:36:08
not LM a location counter always tracks
00:36:14
VMA
00:36:15
that's why at this point the location
00:36:18
counter value is nothing but start off
00:36:21
we are May which is nothing but has from
00:36:24
address that is nothing but this one
00:36:27
that we get one more linker script
00:36:29
symbol end data is equal to location
00:36:32
counter here the location counter value
00:36:36
will be updated by this much size
00:36:41
this is a text
00:36:44
this is s data this is e data if I do
00:36:53
idiot R minus s data I would get the
00:36:56
size this is a source this is a
00:36:59
destination I can derive all other
00:37:02
information
00:37:03
let's create some linker script symbols
00:37:07
for BSS section so I will call this as
00:37:10
underscore start BSS is equal to the
00:37:14
location counter and here I can create
00:37:20
one more symbol ebsf is equal to
00:37:22
location counter we almost finished
00:37:25
writing our linker script and in the
00:37:27
next lecture let's use this linker
00:37:29
script to link our project to create
00:37:32
final executable complete up to here and
00:37:35
we'll explore about linking in the next
00:37:39
lecture

Description:

Enroll for the full course : https://www.udemy.com/course/embedded-system-programming-on-arm-cortex-m3m4/?couponCode=FASTWEBAPR20 In this lecture you'll learn , writing GNU linker script from scratch , section placement, linker script commands ,syntax and linker script symbols https://github.com/niekiran/baremetalembedded Want to learn Rust programming language? Check out our brand-new course https://courses.fastbitembedded.com/courses/rust Coupon: NEWLAUNCHOFFER Rust playlist https://www.youtube.com/playlist?list=PLERTijJOmYrBwNsm42SjcdTBU9dEyYfzh

Preparing download options

popular icon
Popular
hd icon
HD video
audio icon
Only sound
total icon
All
* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "Bare metal embedded lecture-4: Writing linker scripts and section placement" video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "Bare metal embedded lecture-4: Writing linker scripts and section placement" video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "Bare metal embedded lecture-4: Writing linker scripts and section placement" video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "Bare metal embedded lecture-4: Writing linker scripts and section placement" video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "Bare metal embedded lecture-4: Writing linker scripts and section placement"?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "Bare metal embedded lecture-4: Writing linker scripts and section placement"?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.