Go Down

Topic: What is the purpose of erasing in banzai() in ArduinoCore-samd (Read 1 time) previous topic - next topic

keesbakker

Hi,

In ArduinoCore-samd there is Reset.cpp with the function banzai. It is called (indirectly) from the the ticks handler. And this is initiated from CDC.cpp function CDC_Setup.

What is the reasoning to "Erase application" before doing a reset?

Let me already give my opinion about it :-)
I find this code unnecessary, because it should be the task of the bootloader to erase (and load a new program)
Even if you want to be able to force the bootloader to stay in "bootloader mode", it should be possible to use the "double tap" trick that the bootloader itself uses, namely set the magic word (0x07738135) at address 0x20007FFC.

I even find it unwanted and maybe a bit dangerous. Suppose there is a run-away pointer that changes the variable static int ticks in Reset.cpp, as soon as ticks is back to zero your program will be erased.

BTW. This banzai code was introduced in this commit

commit dd50d5c446e6d1fb9cbfd93b5d579604038a3125
Author: Cristian Maglie <c.maglie@arduino.cc>
Date:   Fri Aug 15 12:10:50 2014 +0200

     Implemented 1200bps-touch to restart bootloader when connected from native port

ballscrewbob

#1
Dec 31, 2016, 06:37 pm Last Edit: Dec 31, 2016, 06:44 pm by Ballscrewbob Reason: add link and experience
I came across that a long time ago.

Its actually in the spec sheet for the processor commands itself !
It not an addition per-se.

I did ask the reason for a "self destruct" option.

EDIT found the post that mentions it from some time ago HERE

MO manual here
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

keesbakker

Thanks for the pointer, but besides the mention of the self-destruct there is no answer as to why this self-destruct is a good idea.

Also I don't really understand what you mean with:
Quote
Its actually in the spec sheet for the processor commands itself !
It not an addition per-se.
(I'm not looking for an explanation how the erasure and the resets words, but why the erasure is needed.)

ballscrewbob

You said it was introduced in a commit.

Just pointed out it was always there.
As for the reason I think you might get a better explanation by following the trail back to the source thats all.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

keesbakker

Quote
You said it was introduced in a commit.

Just pointed out it was always there.
No, it was introduced in that commit.

Quote
As for the reason I think you might get a better explanation by following the trail back to the source thats all.
Yeah, that might be better. I'll raise an issue at github.

ericbaril72

I might use it to force the CPU to stay in bootloader mode.
I do not have the ability of double-tapping in-the-field.

So , I DO like this function.

I don't know of a lots of programmers implementing useless stuff ...
I do know however that COMMITS rarely explain every design decisions.

It might be wiser to add proper comments in the banzai() and post a pull-request then declaring this as an Issue.


Go Up