Questions about bootloader code (cloader.py)

Firmware/software/electronics/mechanics
Post Reply
derf
Expert
Posts: 163
Joined: Fri May 31, 2013 12:17 am
Location: Germany

Questions about bootloader code (cloader.py)

Post by derf »

Hey Bitcraze Team,

While trying to understand the code of the bootloader, the following questions came up:
  • update_mapping method in cloader.py
    I found the description of the GET_MAPPING command in the wiki, but it seems like the mapping (self.mapping) is never used anywhere. Did I miss something or is the feature not yet used?
  • check_link_and_get_info method in cloader.py
    Why is the radio link set to a random address?
Regards,

Fred
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Questions about bootloader code (cloader.py)

Post by arnaud »

Hi Fred,

The mapping is implemented to test the bootloader firmware but is not used yet. It is required to know the mapping if you want to write something from anywhere in the middle of the flash but we are not doing that yet, we always flash from the beginning of a physical page.

The random address is meant to protect the bootloading process: soon in the connection process both the PC and the copter switch to a random address so it is possible to update another copter at the same time without interference. Originally this was implemented for early production where we got corrupted flashing when two copter where flashed at the same time. (I wish to use the address during normal connection as well for the same reason, hopefully I will get time for it).

Thanks for the github links, now I know how to show blocks of code! :-D
BR,
/Arnaud
derf
Expert
Posts: 163
Joined: Fri May 31, 2013 12:17 am
Location: Germany

Re: Questions about bootloader code (cloader.py)

Post by derf »

Hi Arnaud,

Thanks for your reply.
I noticed that the wiki states for GET_MAPPING:
For example the STM32F405 has a mapping of [4, 16, 1, 64, 7, 128]
When I send the GET_MAPPING packet like described here, I actually get a reply that contains [4, 16, 1, 64, 7, -128].
So I don't understand why Lines 334-339 are necessary.
(As long as it's unfinished code that's not used, I guess it's not so bad. I'm just curious if it can be improved. ;) )

About the random address:
I can't seem to find the piece of code that resets the address to the original value.
How does it work?

Best Regards,

Fred
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Questions about bootloader code (cloader.py)

Post by arnaud »

The mapping is "compressed" when communicated, the code you are linking is decomposing it in a list of bootloader page that are at the start of physical page. Then the flashing algorithm will be directly able to use this list of page to see where physical page starts.

Code: Select all

>>> m =  [4, 16, 1, 64, 7, 128]
>>> mapping = []
>>> page = 0
>>> for i in range(int(len(m) / 2)):
...     for j in range(m[2 * i]):
...         mapping.append(page)
...         page += m[(2 * i) + 1]
... 
>>> mapping
[0, 16, 32, 48, 64, 128, 256, 384, 512, 640, 768, 896]
The code could maybe just be a bit more "pythonic" :).

As for the random address it is reset when the copter resets, it is not saved anywhere in the copter and is used only until the next reset. At the end of the flashing sequence the copter is reset and comes back to the default address.
derf
Expert
Posts: 163
Joined: Fri May 31, 2013 12:17 am
Location: Germany

Re: Questions about bootloader code (cloader.py)

Post by derf »

Thanks Arnaud, for the explanation. :)
Post Reply