Bootloader section

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

A few months back I moved my project over to studio 6 and used it for a while before getting frustrated it. I was forced to do this with a classic school boy error of upgrading the processor to the xmega128a1u without really looking in to the repercussions. I simply thought i was a drop in replacement with some nice extras. It turns out you can't use it with studio 4 (AAARRRRGRGGGHHHHH!).

The main problem for me (although not limited to) was the fact I could no longer debug my bootloader section code. Even though the memory locations were set as before in studio 4 it just ignored them and in fact didn't even compile the code for either toolchain (I went back to xmega128a1 for winavr to compare). So to get round this without losing a day or 2 programming time messing around I went back to studio 4 and just set the processor to the old one and being similar it just worked, I did have to program the fuses with studio 6 though. I thought the long term solution would either be to buy IAR Workbench or pull the processors off the boards and refit with the older part.
Now yesterday I noticed I was no longer getting program or data size output, it only became important as I changed a large section of code over the weekend and wanted to compare size. I think this was because when I removed studio 4 and then re installed I installed the wrong version (build 730) and it no longer natively works with WinAvr (AAARRRRGRGGGHHHHH!).

So I moved back to studio 6 to find the code size, (probably an easier way to do this) and still not able to debug bootloader memory code but I had a bit of spare time. I found that if I get the makefile from the AS4 project and compile the code with that in AS6 I now get the bootloader section code generated and can debug it!

So in summary, my questions are:

Is there a setting somewhere in the linker options I need to set to enable the automatically generated make file to get GCC to compile the code with my sections?
Should I be doing this a different way?
Am I barking up the wrong tree on this?
Why can I not just use this device with avr studio 4?
Why can I not use my new JTAGICE 3 programmers with avr studio 4?
Why can I not use my new JTAGICE 3 programmers with AS6 on my laptop but they work fine on my desktop PC?
Should I just bite the bullet and ditch Atmel for being absolute rotters and go for a nice looking cortex M4 device?

I should also note these are not the only defined sections of my code and they work fine in the program space.

I should also note that it looks like the sections are being passed to the linker in the command line.

I should also say that I wanted to make sure that a routine was placed at the bootloader reset address so without real knowledge I created several sections for the bootloader area, .BOOTLOADERMAIN=0x10000 (contains only the reset routine) .BOOT=0x10800 for the memory programming functions and .BOOTLOADER=0x10400 for the rest of the bootloader code. It probably isn't the correct way of doing it but has worked fine for the last couple of years, with AS4.

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

Quote:

in fact didn't even compile the code for either toolchain (I went back to xmega128a1 for winavr to compare)

How could WinAVR know about the 128a1u - it predated it? If you want to use AS4 then use it alongside Atmel's 4.7.2 "toolchain".
Quote:

Is there a setting somewhere in the linker options I need to set to enable the automatically generated make file to get GCC to compile the code with my sections?

Writing bootloaders should be as simple as -Ttext=. In AS6 you can either add this as a miscellaneous option for the linker in the project settings. IOr, within the linker options there is a tab called "memory settings" where you can simply say .text= but note that Atmel work in "words" not "bytes" so if you use -Ttext then give in bytes but if you use memory settings give it in words (that is half the value).
Quote:

Why can I not just use this device with avr studio 4?

There are two parts to using AS4 (for C). One is the C compiler and one is the IDE. As I say you can upgrade the C compiler to a modern one that knows all about the latest chips. However the IDE finished development at 4.19. At that time it did not know about JTAGICE3 and it did not knwo about some models of AVR that have been launched in the last 2-3 years. There's not a lot you can do about that.
Quote:

Why can I not use my new JTAGICE 3 programmers with avr studio 4?

because it first appeared when AS5 was first released and Atmel had already made a conscious decision to concentrate on the "new" IDE in favour of the old AS4. So it came too late.
Quote:

Why can I not use my new JTAGICE 3 programmers with AS6 on my laptop but they work fine on my desktop PC?

That unfortunately seems to be Atmel's fault. There are many threads here about issues of AS6 that break the JTAG debuggers and ways to work around that (going back in firmware versions and the like). For whatever reason Atmel won't seem to acknowledge that this issue exists. Presumably on the machines where they do the automated testing of the programmers and debuggers the latest AS6 does work with JTAGICE3 and JTAGICEmkII so they deem it "no problem here". Yet many many threads on this board show that there clearly is a problem. The hope is that internally Atmel do acknowledge this and the next release of AS6 will fix everything. In the meantime look for the threads about reverting firmware versions.
Quote:

Should I just bite the bullet and ditch Atmel for being absolute rotters and go for a nice looking cortex M4 device?

Atmel make M4 chips ;-). As the debugging side of things is completely different to that for AVR8 you may have issues but they are unlikely to be the same ones!

(M4 is not really an equivalent for Xmega - that would be more like M0/M0+/M3 than M4 which are the ones with all the extra maths support for really compute intense programming).

Quote:

I should also note that it looks like the sections are being passed to the linker in the command line.

What do the .map and even avr-nm say after the build?
Quote:

I should also say that I wanted to make sure that a routine was placed at the bootloader reset address so without real knowledge I created several sections for the bootloader area,

I'd fix that. As I say a bootloader is nothing more than -Ttext=non-zero. If you don't do it that way the reset jump, vector table and CRT contents are not going to be properly located. (that is the contents of .vectors and .initN).
Quote:

It probably isn't the correct way of doing it but has worked fine for the last couple of years, with AS4.

It may well have worked by some fluke but this wrong method has now been "found out" by a change of tool. _do_copy_data and _do_clear_bss are now done differently in 4.7.2 compared to the 4.3.3 in WinAVR - could be that. (though a good bootloader will be handling those things itself so it can be built with -nostartfiles).

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

Thanks as always for a detailed response, I like it because it gives me food for thought and hopefully I will learn by it.

Quote:

How could WinAVR know about the 128a1u - it predated it? If you want to use AS4 then use it alongside Atmel's 4.7.2 "toolchain".

I recompiled using the old processor defined as I did not use any of the newer features it worked without change.

Quote:

Writing bootloaders should be as simple as -Ttext=. In AS6 you can either add this as a miscellaneous option for the linker in the project settings. IOr, within the linker options there is a tab called "memory settings" where you can simply say .text= but note that Atmel work in "words" not "bytes" so if you use -Ttext then give in bytes but if you use memory settings give it in words (that is half the value).

Yes but I want to use the bootloader section to do things like bootloading and crc checks on the application area before starting the application area code and I like it being part of the project. Is this possible? Should I really have created 2 projects for this? I have not used interrupts in this bit which is why it works I guess.

Quote:

What do the .map and even avr-nm say after the build?

There is no mention of the missing sections at all in the map file or the lss but I'm not sure what avr-nm is.

Quote:

(M4 is not really an equivalent for Xmega - that would be more like M0/M0+/M3 than M4 which are the ones with all the extra maths support for really compute intense programming)

I know, it would be amazing to have these features I could do a lot with it. Have been tempted for the last year or so to develop a board around it. Never get the time right now but it could be on the cards. I have an STM dev board with a M4 that I have developed on.

Quote:

It may well have worked by some fluke but this wrong method has now been "found out" by a change of tool. _do_copy_data and _do_clear_bss are now done differently in 4.7.2 compared to the 4.3.3 in WinAVR - could be that. (though a good bootloader will be handling those things itself so it can be built with -nostartfiles)

Why does the use of the AS4 makefile work with the new toolchain?
Why does compiling with WinAvr in AS6 result in the same 'problem'?

I think the other AS4 vs AS6 issues are covered. It was probably more of a rant on my part than anything constructive. I would like to see data breakpoints in AS6 though.

Thanks.

John.

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

Quote:

Yes but I want to use the bootloader section to do things like bootloading and crc checks on the application area before starting the application area code and I like it being part of the project. Is this possible?

I do that in my own bootloader (you may find the CRC stuff useful as it matches the algo in srec_cat):

http://spaces.atmel.com/gf/proje...

main code here:

http://spaces.atmel.com/gf/proje...

I don't see what having CRC stuff in the B/L has to do with how you position .text? Are you talking about sharing some of the bootloader functions to the app section? I'd do that with a common dispatch table at a fixed address then build each app separately. As my bootloader solution shows it's easy to have both app and B/L as two projects in one AS6 solution (one of the nice features of AS6).

Quote:

Should I really have created 2 projects for this?

So - yes.
Quote:

but I'm not sure what avr-nm is.

Binutils for AVR contatins a number of tools (avr-objdump, avr-objcopy, avr-readelf, avr-ar), avr-nm is just one of these. When you run it on an .o or .elf file it will tell you what function and data objects it contains, where they are and how big they are. For example:

E:\sdboot-trunk\Debug>avr-nm pfboot.elf | grep " T " | sort
00007000 T start
00007008 T __ctors_end
00007008 T __ctors_start
00007008 T __dtors_end
00007008 T __dtors_start
00007008 T __trampolines_end
00007008 T __trampolines_start
00007008 T main
0000724e T init_spi
00007258 T dly_100us
00007268 T select
0000726e T deselect
00007270 T rcv_spi
00007272 T xmit_spi
0000728c T flash_erase
000072a8 T flash_write
000072e4 T disk_read
0000736a T disk_initialize
000074b8 T disk_readp
0000756a T __muluhisi3
0000757e T __umulhisi3
00007596 T __eerd_word_m32
000075a0 T __eeupd_word_m32
000075a8 T __eerd_block_m32
000075ac T __eerd_blraw_m32
000075c8 T __eeupd_byte_m32
000075ca T __eeupd_r18_m32
000075ea T _etext

This is my own bootloader that was built to locate at 0x7000.

Quote:
Why does compiling with WinAvr in AS6 result in the same 'problem'?

Clearly the command line invocation of the compiler and linker must be different in some way. The commands issued are output so you should be able to compare.

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

Quote:

I don't see what having CRC stuff in the B/L has to do with how you position .text? Are you talking about sharing some of the bootloader functions to the app section?

I have placed the flash program memory writing functions up there and use them from the application area as well as the bootloader to load a chunk of the flash with some stuff (not native executable code) during the application execution so I suppose this is the real reason to have both bootloader and application in the same project. I do not know about dispatch tables so maybe a time to do some learning!

Quote:

As my bootloader solution shows it's easy to have both app and B/L as two projects in one AS6 solution (one of the nice features of AS6).

I had thought of this, can you debug both at the same time or do you need to switch between them? Is each project aware of the other? I should do some testing when I get a quiet time.

Besides all of this stuff another thought occurred to me, why is the code not being generated and placed in the bootsection? Right or wrong, I have defined the sections and referred to them in my functions using the __attribute__((section (".wherever"))). The other sections in the application area seem to be OK and placed where I expect them.

Although, you may have answered that:

Quote:

Clearly the command line invocation of the compiler and linker must be different in some way.

I think I need to look at what is going on in a bit more depth.

Thanks.

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

OK after closer inspection, what about this as an explanation:

The makefile from AS4 refers to avr-gcc without a path so it would take the one in the system path... the winAVR one.

The new toolchain compiler realises the code in the boot section is never called, because it is only entered when the processor resets and optomises it out where as the winAVR one doesn't even though they have the same -Os switch set.

Is there a way to ensure the routines in the bootloader section to not be optomised out?

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

Ah what you are likely encountering is that by default an AS6 project has -ffunction-sections enabled for the compiler and -gc-sections enabled for the linker. The first says "as you compile each function put it in its own separately named memory section". So foo() goes into .text.foo and so on. The -gc-sections option to the linker says "garbage collect any unreferenced sections". So if anything in the code calls foo() then the .text.foo reference count is incremented beyond 0 and when it comes to link that section will not be garbage collected (dumped) because there was a reference. If nothing apparently calls foo() so .text.foo reference count remains 0 then the linker says "no point including this as nothing uses it" and it gets dumped from the output image.

There's no harm in leaving -ffunction-sections (and -fdata-sections) turned on but to stop this behaviour make sure -gc-sections is turned off. Then AS6 should behave like AS4+WinAVR.

You can tell when -gc-sections is active as the .map file will have a section near the start to say what was discarded.

But do split this into two projects and just -Ttext= the B/L one.

(I'm guessing you haven't read the Bootloader FAQ in the Tutorial Section - probably worth a look).

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

Yes, just found it and about to post as it looks like it worked! I spotted the options in the compiler section but wasn't until the one in the linker section was turned off did it work.
I will make note to study the bootloader stuff once I get time and will most likely split out the projects, especially as AS6 has the ability to have more than one in a solution it kinda makes sense.

Thanks again.

John.