Jumping

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

we have a code consist on 2 section

one section is bootloader

other section is main code

if we want jumping ti main code in the bootloader code how we can?

is it possible to write jmp "0000"  ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can't jump to code from the bootloader.  The bootloader puts the bytes that it receives from the UART into flash ROM.  These bytes are in a specific format so that the bootloader knows when it has received all  the code that it needs to load into the Flash ROM.   Then the bootloader itself jumps to address 0x0000 in the flash.  At this address is another jump instruction where the code actually begins.

 

If the bootloader does not receive any bytes from the UART within a time-out period, then it will jump to address 0x0000.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:

You can't jump to code from the bootloader.  The bootloader puts the bytes that it receives from the UART into flash ROM.  These bytes are in a specific format so that the bootloader knows when it has received all  the code that it needs to load into the Flash ROM.   Then the bootloader itself jumps to address 0x0000 in the flash.  At this address is another jump instruction where the code actually begins.

 

If the bootloader does not receive any bytes from the UART within a time-out period, then it will jump to address 0x0000.

No I have write my Bootloader

It is not Serial communication Bootloader

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

An example is here:

 

https://www.pocketmagic.net/simp...

 

 

Yes, you can just:

asm("jmp 0");

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

 

An example is here:

 

https://www.pocketmagic.net/simp...

 

 

Yes, you can just:

asm("jmp 0");

 

thank you

It means that we use #asm  jmp "0"  #endasm   in the end of the Bootloader?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hasanzadeh99 wrote:
It means that we use #asm  jmp "0"  #endasm   in the end of the Bootloader?

 

I'm not sure what you mean. - where did you get the #asm #endasm from???

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have to say which language you are talking about. If Asm then the usual way from the bootloader to the app is simply "JMP 0". If C then you can probably do some kind of asm("JMP 0") but you can do it in plain C code..

void (*fptr)(void);
fptr reset = (fptr)0;

reset();

It's true that what this actually generates is "CALL 0" not "JMP 0" but as the very first thing C will do is reset SP this does not matter.

 

You can see where I do this in my own bootloader at:

 

https://github.com/wrightflyer/s...

 

You can't jump to code from the bootloader.

And there speaks someone who's clearly never written a bootloader and is giving misguided advice about something they don't understand. Ho hum.

Last Edited: Sat. Jun 15, 2019 - 12:58 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There are situations where the "pure" C/C++ code does not work. Namely on big devices when you want to jump from EIND=1 to 0x0 (which is EIND=0) and the compiler uses EICALL/EIJMP like GCC does.
.
You can then follow GCC documentation on EIND peculiarities or
.
__asm ("%~jmp 0");
__builtin_unreachable();

avrfreaks does not support Opera. Profile inactive.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

d

 

 

 

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

Last Edited: Mon. Jun 24, 2019 - 08:47 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes but if you do the WDR thing in a bootloader the BOOTRST is still back into the bootloader. It then has to check WDRF and, if set, it does this same JMP 0 thing as being talked about here.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

void (*fptr)(void);
fptr reset = (fptr)0;

reset();

 

OK , actually this code works

but would you explain about following section ?

what does means this?

is it function definition?

How?

void (*fptr)(void);
fptr reset = (fptr)0;

reset();

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I believe clawson meant to do this:

typedef void ( *fptr )( void );
fptr reset = (fptr)0;

reset();

The first line declares a function pointer type that can point to functions that return nothing and take no arguments.

 

The second line creates a pointer to such a function whose code resides at flash address 0 (the reset vector).

 

The final line calls the function pointer resulting in the execution of the code located at flash address 0.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You are quite right, the first line was supposed to be a typedef. This is what happens when this site makes it close to impossible to type code on a mobile phone :-(