Difference between revisions of "Bootloader"

From Gamebuino Wiki
Jump to: navigation, search
(Questions ?)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
 
<div style="width:45%;min-width:20em;float:left;margin-right:5%">
 
<div style="width:45%;min-width:20em;float:left;margin-right:5%">
=== Get a free Gamebuino ===
 
For now, Gamebuino uses the Arduino UNO bootloader. It works great, but you need a computer every time you want to load a new game. With hybrid USB/SD card bootloader, you could switch between games just by restarting your Gamebuino !
 
  
That's why I need YOU, a bad-ass developer, to make it work. A guy already did that, but I didn't manage to compile the source yet. If you manage to compile it and make it work as described below, you'll '''GET A FREE GAMEBUINO BEFORE EVERYBODY !'''
+
=== Overview ===
 +
The Gamebuino uses the modified version of the Arduino's UNO bootloader (Optiboot). The changes allow the firmware to load and run the game selection sketch from SD card when the Gamebuild is reset with the C button held down; it also allows that software to load and launch other games on the SD card programatically. Other than these extra features the bootloader should run normally, meaning it is compatible with the Official software and will support IDE uploads and program verification.
  
 
=== Sources ===
 
=== Sources ===
* [http://arduino.cc/en/Hacking/Bootloader?from=Main.Bootloader Arduino bootloader]: for the ones who don't know what a bootloader is
+
* [https://code.google.com/p/optiboot/]: The firmware used by the official Arduino IDE for flashing Uno boards.
* [https://github.com/thseiler/embedded/tree/master/avr/2boots 2boots], a SD-enabled bootloader source code
+
* [https://github.com/thseiler/embedded/tree/master/avr/2boots 2boots], an SD-enabled bootloader source code, the Gamebuino bootloader uses it's FAT16 and flashing code.
* [http://harizanov.com/2013/01/2boots-bootloader-on-the-uiot-serial-mmc-bootloader-in-2kb/ 2boots variant], a tweaked version that is ''supposed'' to be compilable
 
  
=== Principle ===
+
=== Launching Loader ===
My goal is first to compile and get it to work, obviously. Then, it has to be slightly modified to be easily usable on a Gamebuino. Here is how I picture it:
+
If the the C button is held down while the unit is powered-up then the bootloader will search for a compiled sketch on the SD card called "LOADER.HEX". Note that the SD must be formatted with FAT16 and the filename must be upper case characters.If no SD card is present, or if the LOADER.HEX file can't be found or loaded then the bootloader will execute whatever program is already flashed into memory.
* The SD card contains a program named "LOADER" which is loaded when the Gamebuino is turned on while pressing "C". This program allow you to navigate in the SD card and select a game. Then, it writes the game file's name in the EEPROM
 
* Turn the Gamebuino off then back on
 
* The boot-loader loads the game selected by reading its name in the EEPROM
 
  
All the EEPROM part is already included in 2boots, you just have to compile it and add the C button feature.
+
=== Flashing the Gamebuino Bootloader ===
 +
Under normal operation the Gamebuino is programmed via the USB virtual COM port with the device selected as "Arduino UNO". However, if you wish to program it or upload the bootloader using an external hardware programmer  (e.g. another Arduino) then you must edit the boards.txt file in the Arduino package (typically loacted at C:\arduino-1.0.5\hardware\arduino\boards.txt) and add the following section:
  
=== Pin mapping ===
+
<nowiki> gamebuino.name=Gamebuino
* Button C : A3 (PC3)
+
gamebuino.upload.protocol=arduino
* SD enable : 10 (PB2)
+
gamebuino.upload.maximum_size=32256
* See the schematics in [[Hardware]] for more details
+
gamebuino.upload.speed=115200
 +
gamebuino.bootloader.low_fuses=0xff
 +
gamebuino.bootloader.high_fuses=0xd8
 +
gamebuino.bootloader.extended_fuses=0x05
 +
gamebuino.bootloader.path=gamebuino_boot
 +
gamebuino.bootloader.file=gamebuino_boot.hex
 +
gamebuino.bootloader.unlock_bits=0x3F
 +
gamebuino.bootloader.lock_bits=0x0F
 +
gamebuino.build.mcu=atmega328p
 +
gamebuino.build.f_cpu=16000000L
 +
gamebuino.build.core=arduino
 +
gamebuino.build.variant=standard</nowiki>
 +
 
 +
Restart the Arduino IDE and you will see a new device type called "Gamebuino". (This change is required for external programming because the Gamebuino bootloader is larger than the original Optiboot bootloader and the fuse bits need to be modified to accommodate this).
 +
 
 +
=== Launching Games via Software ===
 +
The boot loader can be invoked at any time to load and launch a game from the SD card. To do this simply add the following code to any sketch:
 +
 
 +
<nowiki>    #define load_game (*((void(*)(char*))0x7ffc))</nowiki>
 +
 
 +
A game can then be loaded and launched by calling this function, passing in an upper-case-only file name with the .HEX extension:
 +
 
 +
<nowiki>    load_game("BLINK");</nowiki>
 +
 
 +
This causes a long-jump into the boot loader code causing it to load and launch BLINK.HEX from the SD card.
  
 
=== Questions, suggestions, solutions ? ===
 
=== Questions, suggestions, solutions ? ===
Line 29: Line 49:
 
Good luck !
 
Good luck !
  
=== Conditions ===
+
=== Download ===
If you are the first to post on the forum a working source of the bootloader (as described above), how to compile it, and the binaries, I'll send you a free Gamebuino !
+
 
</div>
+
The current alpha version of the boot loader can be downloaded from the files section.
<div style="width:45%;min-width:20em;float:left;margin-right:5%">
 
[[File:We_Need_You.jpeg]]
 
</div>
 

Revision as of 2014-03-18T00:23:02

Overview

The Gamebuino uses the modified version of the Arduino's UNO bootloader (Optiboot). The changes allow the firmware to load and run the game selection sketch from SD card when the Gamebuild is reset with the C button held down; it also allows that software to load and launch other games on the SD card programatically. Other than these extra features the bootloader should run normally, meaning it is compatible with the Official software and will support IDE uploads and program verification.

Sources

  • [1]: The firmware used by the official Arduino IDE for flashing Uno boards.
  • 2boots, an SD-enabled bootloader source code, the Gamebuino bootloader uses it's FAT16 and flashing code.

Launching Loader

If the the C button is held down while the unit is powered-up then the bootloader will search for a compiled sketch on the SD card called "LOADER.HEX". Note that the SD must be formatted with FAT16 and the filename must be upper case characters.If no SD card is present, or if the LOADER.HEX file can't be found or loaded then the bootloader will execute whatever program is already flashed into memory.

Flashing the Gamebuino Bootloader

Under normal operation the Gamebuino is programmed via the USB virtual COM port with the device selected as "Arduino UNO". However, if you wish to program it or upload the bootloader using an external hardware programmer (e.g. another Arduino) then you must edit the boards.txt file in the Arduino package (typically loacted at C:\arduino-1.0.5\hardware\arduino\boards.txt) and add the following section:

	gamebuino.name=Gamebuino
	gamebuino.upload.protocol=arduino
	gamebuino.upload.maximum_size=32256
	gamebuino.upload.speed=115200
	gamebuino.bootloader.low_fuses=0xff
	gamebuino.bootloader.high_fuses=0xd8
	gamebuino.bootloader.extended_fuses=0x05
	gamebuino.bootloader.path=gamebuino_boot
	gamebuino.bootloader.file=gamebuino_boot.hex
	gamebuino.bootloader.unlock_bits=0x3F
	gamebuino.bootloader.lock_bits=0x0F
	gamebuino.build.mcu=atmega328p
	gamebuino.build.f_cpu=16000000L
	gamebuino.build.core=arduino
	gamebuino.build.variant=standard

Restart the Arduino IDE and you will see a new device type called "Gamebuino". (This change is required for external programming because the Gamebuino bootloader is larger than the original Optiboot bootloader and the fuse bits need to be modified to accommodate this).

Launching Games via Software

The boot loader can be invoked at any time to load and launch a game from the SD card. To do this simply add the following code to any sketch:

    #define load_game (*((void(*)(char*))0x7ffc))

A game can then be loaded and launched by calling this function, passing in an upper-case-only file name with the .HEX extension:

    load_game("BLINK");

This causes a long-jump into the boot loader code causing it to load and launch BLINK.HEX from the SD card.

Questions, suggestions, solutions ?

If you have any questions, ask them the in this thread.

Good luck !

Download

The current alpha version of the boot loader can be downloaded from the files section.