-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question on Dual Templates #42
Comments
I meant to offer an urloader sketch that would patch template bootloaders on the fly with the desired ports/pins but faced difficulties porting that from a bespoke IDE to plain vanilla avr-gcc; over time, this fell off my todo list. Apologies for raising expectations.
The source code is currently the only additional source I can offer Lines 610 to 620 in 5e9d508
In your case this translates to the following replacement table for opcodes in the template hex file assuming the CS pin is PC0 (I guess your reference to A0 is the Arduino numbering of pins, but the datasheet pin name would be PC0)
For the ATmega328P the address of PORT C is 8 and that of DDR C is 7:
Once these replacements are done in the template bootloader, it will be ready for use.
Yes, you could do that, too. Newer toolchain versions should work but they are untested: some of the tricks to keep urboot small rely on properties of those specific toolchains. Best to use the provided docker file to compile on Windows, eg,
You will need to add dual boot options... |
Right, I'm still a beginner (with MCUs) and follow what is printed on the boards.
So I have to search for the “move rx,rx” opcodes across the entire hex file and also need to adjust the checksums, right? |
Not if you use the
The format |
Great, that makes life easier. Thanks! |
pro tip: you can use the disasm terminal command in connection with |
Hmm, it's looking more and more like AVRDUDE is a much more powerful tool than I originally thought. |
Before patching a template bootloader, I tried to verify my OTA-enabled sketch on a test board with urboot_m328p_1s_autobaud_uart0_rxd0_txd1_led+d5_csb0_dual_pr_ee_ce.hex installed (and CS on PB0). Next, I patched this single byte at 0x0066 in the SPI flash from FC to D4 just before resetting the board and - viola - the OTA uploaded sketch runs fine. |
I take it this bootloader comes directly or indirectly from this repo directory.
However, in this case the MCU has hardware-protected bootloading and the 512 byte size of the bootloader is exactly one of the sizes that the MCU offers. So this situation does not require vector bootloading, and it is better to select the hw-supported bootloader The uploaded code always needs to be presented in terms of full pages (128 bytes for the |
And in case my previous answer wasn't clear: hw-supported bootloaders don't need patching of the sketch. |
It was, thank you very much. Nice to see that my observations have a natural explanation. Managing fuses seems feasible as far as I can see (I think I need to switch the BOOTRST one, right?). I will check it out. |
Very: the bytes in that place code where the application starts and that depends on the sketch and the compiler. Really, it is best to use a hw-supported bootloader here. With a reasonably recent AVRDUDE it is easy to set the fuses correctly using a physical programmer whilst you flash your bootloader, eg, as in
Note that the boot section size 256w is given in words, ie, means 512 bytes. If you feel like it you can sprinkle in a |
Ok, I did it. And it looks good. |
If it's the case that the MiniCore IDE issues the wrong fuse settings for hw-supported bootloaders I'd encourage to raise an issue over that. I am sure Hans will be happy to engage with that.
Good luck. If you'd like, please share your experience with that and let me know how the documentation for urboot could be improved with that respect. |
Highly recommended to at least check the fuse settings. It's important that the bootloader size is correctly set. When the bootloader size setting in the fuses is too big, you might not notice trouble initially (b/c the MCU sails over the initial 0xff section of the too big bootloader section until it rexches urboot in the top 512 bytes) but as soon as the sketches get bigger reset will jump to the top end of your sketches with unknown results. |
The MiniCore/Arduino IDE issues the fuse settings for vector bootloaders because it installs a vector bootloader for (8 MHz) 328p MCUs (.../urboot/atmega328p/watchdog_1_s/autobaud/uart0_rxd0_txd1/led+b5/urboot_atmega328p_pr_ee_ce.hex). From this installation I also copied the fuse settings for the bootloader size which I think is ok.
Yes, I will do so. |
Done. I wasted some time looking for an AVR disassemler to verify the replacement opcodes, but even without it everything worked out fine. |
Regarding the documentation for urboot I'd suggest to include your post from Dec 13, this helped me a lot. Without suitable tools, you have to put together the opcodes yourself. They are always 2-byte codes, with the first byte in the binary program in second place. sbi: 0x9A + 5 bits for one of the port registers + 3 bits for the bit; Since hex files are plain text files, a text editor is a good choice for finding and replacing the opcodes. assembler opcode hex --> Replaced by: The 'hex' column indicates how the opcodes appear in a text editor. After replacement I saved the bootloader as urboot_m328p_1s_autobaud_uart0_rxd0_txd1_no-led_csc0_patched_dual_ee_ce_hw.hex Each line of a hex file ends with a checksum byte, which is now invalid for all the patched lines. Since the people I'm addressing often don't have much experience with micro controllers, this is a bit more detailed as might be appropriate for the urboot site, I think. But maybe you can still use some of it. |
@elogh Thanks for your suggestions to update the documentation. I have now pushed two commits doing so
Please could you review these two commits, in particular the latter? Once you are happy, we can close the issue. |
I think now it is clearly documented how to modify a template and quite easy to do. Thanks again for your valuable help and your excellent software! |
Hi Stefan,
I'm going to set up a Pro Mini board with dual boot from SPI flash that has its CS pin on A0.
Reading your documentation I found that I either have to build an appropriate version of urboot myself or will need to use the urloader sketch to install a templated prebuilt urboot.hex.
Unfortunately I couldn't find any additional information about an urloader sketch.
I've also been looking on the minicore site, but couldn't find information on how to select (and install) a templated bootloader although there is a page (cores/minicore/atmega328p/watchdog_1_s/autobaud/uart0_rxd0_txd1/template_dual) offering a suitable version. (At least I think so, because there is no "dual" in the path/file name.)
So could you please guide me to additional documentation on how to use a templated bootloader?
Regarding the option to build my own version of urboot: I read that I should use an older tool chain, but I'm on Windows only and don't have it at hand.
So, can I use the tool chain installed with the Arduino IDE (2.3) to build urboot? (It wouldn't be a problem for me that some more bytes are consumed then.)
Thanks,
Erwin
The text was updated successfully, but these errors were encountered: