Discussion:
Help with embedded code linking
Grzesiek Gajoch
2014-07-21 09:37:28 UTC
Permalink
Hi all,
My "problem" is as follows:
I have relatively big code for STM32 microcontroller (~300KB binary file).
Every time I want to test new software version I have to recompile all
of it and then reflash whole memory (which takes time).

I have a question:
is it possible to compile "library" part of code (it does not change
but takes a lot of memory) and burn it in static place in memory,
when compiling "user" code (it uses functions from library) tell the
linker somehow to map jumps to part of memory where the lib is (i.e.
take the adresses from memory map of staticly burned lib) - the goal
is to place it in "user" place in memory (and only reflash this part).

Thanks for replay and help!
Best regards,

Grzegorz Gajoch
Jonathan Wakely
2014-07-21 09:41:38 UTC
Permalink
Post by Grzesiek Gajoch
Hi all,
I have relatively big code for STM32 microcontroller (~300KB binary file).
Every time I want to test new software version I have to recompile all
of it and then reflash whole memory (which takes time).
is it possible to compile "library" part of code (it does not change
but takes a lot of memory) and burn it in static place in memory,
when compiling "user" code (it uses functions from library) tell the
linker somehow to map jumps to part of memory where the lib is (i.e.
take the adresses from memory map of staticly burned lib) - the goal
is to place it in "user" place in memory (and only reflash this part).
Flashing your microcontroller is nothing to do with GCC.

You can certainly compile part of the code into a static library and
link to it, which would be quicker than recompiling the whole thing
every time. That wouldn't help reduce the time to flash the device,
but that's nothing to do with GCC and I don't know how to help with
that.
Niklas Gürtler
2014-07-21 09:53:46 UTC
Permalink
That is possible by placing the library in one part of the flash via a
linker script, and the remainder of the code in another part.
Alternatively you could buy a faster programming device such as Segger
J-Link which can flash even big microcontrollers in <1s ...
Post by Grzesiek Gajoch
Hi all,
I have relatively big code for STM32 microcontroller (~300KB binary file).
Every time I want to test new software version I have to recompile all
of it and then reflash whole memory (which takes time).
is it possible to compile "library" part of code (it does not change
but takes a lot of memory) and burn it in static place in memory,
when compiling "user" code (it uses functions from library) tell the
linker somehow to map jumps to part of memory where the lib is (i.e.
take the adresses from memory map of staticly burned lib) - the goal
is to place it in "user" place in memory (and only reflash this part).
Thanks for replay and help!
Best regards,
Grzegorz Gajoch
Grzesiek Gajoch
2014-07-21 10:17:43 UTC
Permalink
Thanks for reply,
faster programmer is not a option - programming is done via WiFi (it
has to be done that way).
Yes, that's what I want to do - but the question is how to tell the
linker about libraries (which are already somewhere in memory)?
Pozdrawiam,

Grzegorz Gajoch
Post by Niklas Gürtler
That is possible by placing the library in one part of the flash via a
linker script, and the remainder of the code in another part.
Alternatively you could buy a faster programming device such as Segger
J-Link which can flash even big microcontrollers in <1s ...
Post by Grzesiek Gajoch
Hi all,
I have relatively big code for STM32 microcontroller (~300KB binary file).
Every time I want to test new software version I have to recompile all
of it and then reflash whole memory (which takes time).
is it possible to compile "library" part of code (it does not change
but takes a lot of memory) and burn it in static place in memory,
when compiling "user" code (it uses functions from library) tell the
linker somehow to map jumps to part of memory where the lib is (i.e.
take the adresses from memory map of staticly burned lib) - the goal
is to place it in "user" place in memory (and only reflash this part).
Thanks for replay and help!
Best regards,
Grzegorz Gajoch
Niklas Gürtler
2014-07-21 11:30:21 UTC
Permalink
You need to define the linker symbols for the functions. You could do
that in the linker script, but there are probably better ways. Maybe ask
the binutils mailing list about how to define a lot of symbols.
Post by Grzesiek Gajoch
Thanks for reply,
faster programmer is not a option - programming is done via WiFi (it
has to be done that way).
Yes, that's what I want to do - but the question is how to tell the
linker about libraries (which are already somewhere in memory)?
Pozdrawiam,
Grzegorz Gajoch
Post by Niklas Gürtler
That is possible by placing the library in one part of the flash via a
linker script, and the remainder of the code in another part.
Alternatively you could buy a faster programming device such as Segger
J-Link which can flash even big microcontrollers in <1s ...
Post by Grzesiek Gajoch
all,
I have relatively big code for STM32 microcontroller (~300KB binary file).
Every time I want to test new software version I have to recompile all
of it and then reflash whole memory (which takes time).
is it possible to compile "library" part of code (it does not change
but takes a lot of memory) and burn it in static place in memory,
when compiling "user" code (it uses functions from library) tell the
linker somehow to map jumps to part of memory where the lib is (i.e.
take the adresses from memory map of staticly burned lib) - the goal
is to place it in "user" place in memory (and only reflash this part).
Thanks for replay and help!
Best regards,
Grzegorz Gajoch
David Brown
2014-07-21 12:46:15 UTC
Permalink
(This is not really a gcc question - more of a general or embedded C
question. You might like to discuss it on then comp.lang.c or
comp.arch.embedded newsgroups.)


While this sort of thing /can/ be done using linker and library magic,
it is often better to use an indirection table - it helps keep the parts
independent.

Make one "base" program containing all the common code. Then you can
have multiple "application" programs that can be updated. It is up to
you whether the "base" program has the "main()" function and calls the
application code as needed, or whether the "application" programs are
the main programs and call functions in the "base" code as needed
(either way can work).

A program that is exporting a set of functions will then have a struct
typedef with a list of pointers, such as:

typedef struct {
int versionInfo;
void (*fooP)(void);
int (*barP)(int a, int b);
} exportTable_t;


The exporting code will define the table:

const exportTable_t exportTable = {
0x00000001,
&foo,
&bar
}

And the importing code will use the table:

extern const exportTable_t exportTable;
#define foo exportTable.fooP
#define bar exportTable.barP


Then the importing program can use the external functions as "x = bar(y,
z);".

Of course, the importing and exporting code need to agree on where the
table is placed - that can be a fixed location, or an initialisation
parameter sent from one to the other (the definitions above have to be
adjusted to suit the method). But the fixed format and single location
means it is much easier to mix and match the base code and the
application code.
Post by Grzesiek Gajoch
Thanks for reply,
faster programmer is not a option - programming is done via WiFi (it
has to be done that way).
Yes, that's what I want to do - but the question is how to tell the
linker about libraries (which are already somewhere in memory)?
Pozdrawiam,
Grzegorz Gajoch
Post by Niklas Gürtler
That is possible by placing the library in one part of the flash via a
linker script, and the remainder of the code in another part.
Alternatively you could buy a faster programming device such as Segger
J-Link which can flash even big microcontrollers in <1s ...
Post by Grzesiek Gajoch
Hi all,
I have relatively big code for STM32 microcontroller (~300KB binary file).
Every time I want to test new software version I have to recompile all
of it and then reflash whole memory (which takes time).
is it possible to compile "library" part of code (it does not change
but takes a lot of memory) and burn it in static place in memory,
when compiling "user" code (it uses functions from library) tell the
linker somehow to map jumps to part of memory where the lib is (i.e.
take the adresses from memory map of staticly burned lib) - the goal
is to place it in "user" place in memory (and only reflash this part).
Thanks for replay and help!
Best regards,
Grzegorz Gajoch
Loading...