Uzebox SD Gameloader V0.4.5

Topics related to the API, programming discussions & questions, coding tips, bugs, etc. should go here.
CunningFellow
Posts: 1174
Joined: Mon Feb 11, 2013 8:08 am
Location: Brisbane, Australia

Re: Uzebox SD Gameloader V0.4.5

Post by CunningFellow » Wed Apr 19, 2017 4:09 am

D3thAdd3r wrote:I think the most useful possible feature that could be added to the bootloader, would be the ability to flash itself from a file on the SD card.
I would think SD-HC would be most useful. You can make user-code that can trick the CPU into flashing a new bootloader so no need to waste the precious 4K on that :)

charliegreen
Posts: 19
Joined: Wed Jan 14, 2015 7:28 pm
Location: California, USA

Re: Uzebox SD Gameloader V0.4.5

Post by charliegreen » Sat Aug 26, 2017 8:09 pm

Hey!

So, I just got back to my Fuzebox after a really long time! I'm having some problems flashing the gameloader, though. I'm using an ISP programmer. I'm sure this must be a solved problem by now, but I haven't found anything here that works for me. I'm on linux and so can't use AVR Studio, and am using avrdude instead. I know that the chip itself works because I backed up ladyada's bootloader and fuse configuration beforehand, and when I restore that, it boots just fine.

I tried this, but plugged everything in and the chip didn't boot. I figured it might be an issue with the fuses, so tried to copy uze exactly (going off this post):

Code: Select all

$ avrdude -c usbtiny -p m644 -U hfuse:w:0xda:m # unset EESAVE so chip erase wipes EEPROM (just in case..?)
$ avrdude -c usbtiny -p m644 -e
$ avrdude -c usbtiny -p m644 -U efuse:w:0xff:m -U hfuse:w:0xd2:m -U lfuse:w:0xfe:m
$ avrdude -c usbtiny -p m644 -U flash:w:Bootloader.hex
With this, too, the chip was completely unresponsive: no audio, no video, no LED, nothing. I figured this might be an issue with lock bits, but they're 0xFF as they should be. I took a full dump of the flash and compared everything, and the gameloader was loaded properly and didn't overflow into low memory or anything like that.

I did notice one thing, though: the gameloader was loaded from 0xF000 to 0xFF5A (which is to be expected, looking at the hex file). I find this a little bit odd, though, since (at least, looking at this nifty fuse calculator, and the values in uze's original post) I'd expect with BOOTSZ=01 and BOOTRST=1 that the bootloader should be loaded starting at 0x7800? Am I misunderstanding how these fuses work? This reminds me of confusions with physical/virtual addresses when dealing with virtual memory in OS development, but I figure such a small chip can't have virtual memory, right? In any case, I thought I'd give it a shot, in the off-chance I was missing something important (presumably some AVR Studio setting that shifts addresses or something), and wrote a new bootloader hex file starting at 0x7800 instead of 0xF000, but when I loaded that, the Fuzebox was still completely unresponsive (which isn't too surprising, but w/e).

I suppose another possibility is that the FAT16 SD card I've had inserted for all these tests is corrupted in some strange way that's crashing the gameloader, but it looks pretty much fine to me. I may repeat the tests I've done, but without the card in, if it turns out I'm not missing something really basic/obvious.

Does anyone know what I'm missing? I'll attach the gameloader I'm flashing (Bootloader.hex) and the one that starts at 0x7800 (boot7800.hex) in case you're interested.

Thanks!
Attachments
Bootloader.hex
(10.83 KiB) Downloaded 131 times
boot7800.hex
(10.59 KiB) Downloaded 119 times

User avatar
Jubatian
Posts: 1355
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Uzebox SD Gameloader V0.4.5

Post by Jubatian » Sun Aug 27, 2017 7:05 am

I fired up my programmer, but then I got an idea, the CUzeBox emulator supports running the bootloader (even programming games).

However I found that CUzeBox can not start either of these bootloader images. I attached an image which it can start. 0x7800 is probably a word address which you may have seen somewhere, since the AVR has 16 bit opcodes, sometimes word addresses are used. However it is certainly wrong in the boot7800.hex file since the hex have byte addresses, in that using the 0x7800 - 0x7FFF range will put the bootloader in the middle of the ROM which isn't what you want.

The other hex you have might be a bootloader which is somehow damaged (it has the right addresses, but it doesn't start in CUzeBox, so I didn't even upload it in the end). The bootloader for some reason is very picky for the GCC version used, possibly it is broken in some manner (does something undefined by C language standard which some versions of GCC compile into non-working code or has some severe race condition which breaks some builds depending on how many cycles a routine ended up taking, I don't know).

Use the bootloader hex provided by Uze in the first post, which is known to work (and if you still want to build one yourself, test it first with CUzeBox, if it starts it, then you have chance with the real hardware :) ).

Alternatively you could test your hardware by uploading .hex game files if you are unsure about the fuses, and want to see whether your hardware works at all. For example use Megatris which should compile and run fine.

charliegreen
Posts: 19
Joined: Wed Jan 14, 2015 7:28 pm
Location: California, USA

Re: Uzebox SD Gameloader V0.4.5

Post by charliegreen » Mon Aug 28, 2017 5:43 pm

Oh my goodness, you're totally right, the word/byte addressing makes a lot of sense, I downloaded Bootloader_0_4_5.hex, it works great, and I feel ridiculous and should have posted here way sooner :oops:

Thank you so much!!

One thing, though: is the soft reset button supposed to be able to reset the console to the gameloader screen? It isn't for me, and I'd assume you'd want to do that if possible, so you don't have to unplug the box or leave the case open to get at the reset button. Maybe I'm misunderstanding what the soft reset button is supposed to do. It could also be bad wiring on my part (right after digging my Fuzebox up from the depths of my past, I saw my old solder joints and was appalled, I would not be surprised if something didn't work right). Thanks again!

User avatar
Jubatian
Posts: 1355
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Uzebox SD Gameloader V0.4.5

Post by Jubatian » Mon Aug 28, 2017 8:20 pm

charliegreen wrote:
Mon Aug 28, 2017 5:43 pm
One thing, though: is the soft reset button supposed to be able to reset the console to the gameloader screen? It isn't for me, and I'd assume you'd want to do that if possible, so you don't have to unplug the box or leave the case open to get at the reset button. Maybe I'm misunderstanding what the soft reset button is supposed to do. It could also be bad wiring on my part (right after digging my Fuzebox up from the depths of my past, I saw my old solder joints and was appalled, I would not be surprised if something didn't work right). Thanks again!
You mean the button on PD2 (rather called "Power on switch")?

http://uzebox.org/wiki/ATmega644_Pin_Allocation

This button does just what you program it to do, there isn't anything for it in the kernel, so normally it will do nothing (so it isn't a problem if you don't see anything happening). Otherwise usually there is a button on the Reset pin of the AtMega644 so you can reset it. Eh, wait, now I see what is the problem: http://www.ladyada.net/make/fuzebox/solder.html , the Reset button exists on Fuzebox, but it is buried within the box. Maybe you could wire S1 to reset the box since S1 isn't used anyway (and will not be used later either, to have anything consistent on it, all games would have to be reprogrammed, the only thing I could imagine for that button is that the bootloader might later invent some good usage, or possibly some games might add some feature on it - such as to operate the box on some very rudimentary level without a controller).

EDIT: I found however a soft-reset which is compiled in probably all the games:

https://github.com/Uzebox/uzebox/blob/m ... ore.c#L309

Pressing down Start + Select + B + Y will trigger a soft-reset, so with most games you likely can reset the console without the button.

charliegreen
Posts: 19
Joined: Wed Jan 14, 2015 7:28 pm
Location: California, USA

Re: Uzebox SD Gameloader V0.4.5

Post by charliegreen » Wed Aug 30, 2017 10:02 pm

Thank you, that's exactly what I was looking for! :) And good to know about that button!

User avatar
uze6666
Site Admin
Posts: 4449
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Uzebox SD Gameloader V0.4.5

Post by uze6666 » Thu Sep 28, 2017 12:16 am

Indeed the soft reset was there from the very start. Maybe one or two very very early games doesn't support it.

I've updated the Wiki FAQ to reflect the soft reset part. It was there, but terribly documented! I will also add it to the kit assembly guide.
http://uzebox.org/wiki/FAQ#Is_there_any ... eloader.3F

rfisher
Posts: 11
Joined: Tue Jan 15, 2019 8:38 pm

Re: Uzebox SD Gameloader V0.4.5

Post by rfisher » Sun Feb 03, 2019 2:36 pm

EDIT: AVRDUDE commandline solved my problem

On a breadboard with a usbtinyisp programmer and avrdude I'm getting the following verification error. Any ideas of what I'm doing wrong?

Image

I then found that the low fuse needs to be FE and I still get a error.

Image

I also created a simple led blinking program with the fuses L:0xD7 H:0x99 E:0xff and programed it which works.

Code: Select all

.equ gled = 5

ldi r16, (1 << gled) 
out DDRD, r16

start:
    sbi PORTD,gled

; http://www.bretmulvey.com/avrdelay.html
	ldi  r18, 51
    ldi  r19, 187
    ldi  r20, 224
L1: dec  r20
    brne L1
    dec  r19
    brne L1
    dec  r18
    brne L1
    rjmp PC+1

	cbi PORTD,gled

	ldi  r18, 51
    ldi  r19, 187
    ldi  r20, 224
L2: dec  r20
    brne L2
    dec  r19
    brne L2
    dec  r18
    brne L2
    rjmp PC+1
    rjmp start

User avatar
nicksen782
Posts: 667
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Uzebox SD Gameloader V0.4.5

Post by nicksen782 » Sun Feb 03, 2019 8:31 pm

Here is how I did it with AVR Dude at the command line:

Code: Select all

sudo avrdude -V -p m644 -P usb -c usbtiny -B 1 -U flash:w:Bootloader5_10.hex
sudo avrdude -V -p m644 -P usb -c usbtiny -B 1 -U efuse:w:0xff:m -U hfuse:w:0xd2:m -U lfuse:w:0xfe:m
http://uzebox.org/wiki/Uzebox_Tutorials ... otloaderFS

The top line will flash the bootloader (or any other hex you specifiy.) The second line sets the fuses. These are the fuses that I have set and they work for me.

If the fuses are supposed to be something else please let me know.

http://uzebox.org/forums/viewtopic.php? ... use#p12945 . The lfuse specified there does not match mine so maybe mine needs updating too.

Code: Select all

avrdude -c usbtiny -p m644p -U lfuse:w:0xd7:m -U hfuse:w:0xd2:m -U efuse:w:0xff:m
... I wonder if my fuses are wrong and that is why the ESP8266 is crashing when accessed by my Uzebox...

Who has an authoritative answer on this?

User avatar
Jubatian
Posts: 1355
Joined: Thu Oct 01, 2015 9:44 pm
Location: Hungary
Contact:

Re: Uzebox SD Gameloader V0.4.5

Post by Jubatian » Tue Feb 05, 2019 8:42 pm

Do you happen to have another ATmega644 IC at hand? A few of them doesn't like running at 28.6MHz, and you might be just unlucky to encounter one of those. Another bet could be checking the related solder points and possibly wires to make sure communication is OK between the programmer and the chip. What I see feels like something possibly nondeterministic, like if the line had some noise, making you unable to successfully program anything of significant size (once you had an error at 0xF200, the other time at 0xF400, so once you got 512 bytes of the bootloader apparently successfully in, the other time, 1024 bytes).

(Desperate I would possibly even try to split up the bootloader HEX into let's say 256 byte chunks, and program those one by one until succeeding, at least hoping that then as an Uzebox it would be functional. Wouldn't fix the problem of the programmer of course, but at least the Uzebox would have a bootloader then)

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests