Protecting the bootloader when using ISP
- nicksen782
- Posts: 714
- Joined: Wed Feb 01, 2012 8:23 pm
- Location: Detroit, United States
- Contact:
Protecting the bootloader when using ISP
This will flash the bootloader:
avrdude -p m644 -c usbasp -P usb -U flash:w:Bootloader_fix.hex
But if you want to flash your game then you lose the bootloader.
avrdude -p m644 -c usbasp -P usb -U flash:w:game.hex
Is there a way to prevent bootloader overwrite? Some kind of write protect?
I started to look into this myself with http://www.engbedded.com/fusecalc/ . However, instead of experimenting with something that could break my chip (and I not knowing how to fix it) I thought I'd ask for some help.
I have a USBASP ISP programmer. I also have this error: avrdude: warning: cannot set sck period. please check for usbasp firmware update.
It takes about a minute to two minutes to program the game. I looked at http://uzebox.org/wiki/index.php?title=AVR_Programming and saw that it could take 2.5 seconds. How can I accomplish my goals?
avrdude -p m644 -c usbasp -P usb -U flash:w:Bootloader_fix.hex
But if you want to flash your game then you lose the bootloader.
avrdude -p m644 -c usbasp -P usb -U flash:w:game.hex
Is there a way to prevent bootloader overwrite? Some kind of write protect?
I started to look into this myself with http://www.engbedded.com/fusecalc/ . However, instead of experimenting with something that could break my chip (and I not knowing how to fix it) I thought I'd ask for some help.
I have a USBASP ISP programmer. I also have this error: avrdude: warning: cannot set sck period. please check for usbasp firmware update.
It takes about a minute to two minutes to program the game. I looked at http://uzebox.org/wiki/index.php?title=AVR_Programming and saw that it could take 2.5 seconds. How can I accomplish my goals?
Re: Protecting the bootloader when using ISP
The boot loader resides in the same flash as the normal program. From ISP's view, it's just not there. There is no such command as "page erase" on the ISP side either, only "chip erase".
- nicksen782
- Posts: 714
- Joined: Wed Feb 01, 2012 8:23 pm
- Location: Detroit, United States
- Contact:
Re: Protecting the bootloader when using ISP
Then perhaps a combining of the game and boot loader text into one hex?
- nicksen782
- Posts: 714
- Joined: Wed Feb 01, 2012 8:23 pm
- Location: Detroit, United States
- Contact:
Re: Protecting the bootloader when using ISP
You sure can. Here's the sequence of commands I use in my batch process to program the chips for my kits:
The important bit is the "-D" in the last command. It disables the chip erase...
Code: Select all
##Fuses
avrdude -c avrispmkii -p m644 -P usb:87:32 -B 5 -U lfuse:w:0xD7:m -U hfuse:w:0xD2:m -U efuse:w:0xFF:m
##Bootloader
avrdude -c avrispmkii -p m644 -P usb:87:32 -B 1 -U flash:w:ROMS-HEX\bootloader_0_4_4.hex -U eeprom:w:eeprom.hex
##The game
avrdude -c avrispmkii -p m644 -P usb:87:32 -D -B 1 -U flash:w:ROMS-HEX\megatris.hex
- nicksen782
- Posts: 714
- Joined: Wed Feb 01, 2012 8:23 pm
- Location: Detroit, United States
- Contact:
Re: Protecting the bootloader when using ISP
Super! Thanks Uze. I'm using the bootloader-fix.hex file that you provided me recently in another thread. Is IT now the official bootloader? Are people that develop directly on the hardware just using the bootloader/SD solution? I'm using my ISP because I can control it all from the PC.I have a batch file that give me the option of compile and emulate or compile and flash.
The SD card doesn't work after a fresh ISP flash. Solution is to remove power then replace it. Or you can remove the SD, reset the Uzebox, replace the SD then reset the Uzebox again.
I thought that maybe the CS on the SD card wasn't pulled high so I soldered a 15k resistor from the 644 side of the voltage divider to power (5V) for the CS pin. Everything worked the same, no change. I have since removed the resistor.
The SD card doesn't work after a fresh ISP flash. Solution is to remove power then replace it. Or you can remove the SD, reset the Uzebox, replace the SD then reset the Uzebox again.
I thought that maybe the CS on the SD card wasn't pulled high so I soldered a 15k resistor from the 644 side of the voltage divider to power (5V) for the CS pin. Everything worked the same, no change. I have since removed the resistor.
- nicksen782
- Posts: 714
- Joined: Wed Feb 01, 2012 8:23 pm
- Location: Detroit, United States
- Contact:
Re: Protecting the bootloader when using ISP
Seems I was too quick to call it done.
New games don't start up. The bootloader is still accessible though.
I flashed a game and removed the -D switch from avrdude. The game starts up but the bootloader is gone again.
I still have the same problem.
New games don't start up. The bootloader is still accessible though.
I flashed a game and removed the -D switch from avrdude. The game starts up but the bootloader is gone again.
I still have the same problem.
Re: Protecting the bootloader when using ISP
Some cards tolerate it and some not. I don't think we can do much on this one. I usually "un-click" the SD card before ISP flashing, otherwise I have the same problem.The SD card doesn't work after a fresh ISP flash. Solution is to remove power then replace it. Or you can remove the SD, reset the Uzebox, replace the SD then reset the Uzebox again.
You don't need the bootloader when developing straight on the hardware. Just erase the chip and program your game over and over.New games don't start up. The bootloader is still accessible though.
I flashed a game and removed the -D switch from avrdude. The game starts up but the bootloader is gone again.
I still have the same problem.
- nicksen782
- Posts: 714
- Joined: Wed Feb 01, 2012 8:23 pm
- Location: Detroit, United States
- Contact:
Re: Protecting the bootloader when using ISP
I have a really simple test for this now. Takes the guesswork out of it.Some cards tolerate it and some not. I don't think we can do much on this one. I usually "un-click" the SD card before ISP flashing, otherwise I have the same problem.
Code: Select all
// Check that the SD card is working
pf_mount(&fs); pf_mount(NULL); // Mount then unmount SD
if((res=pf_mount(&fs)) != 0){ // Try mounting
pf_mount(NULL); // Clear the workspace
Print(4 , 23, PSTR("SD test failed!"));
Print(4 , 24, PSTR("Power cycle the Uzebox."));
PrintByte(0,0, res, true);
} else {pf_mount(NULL);} // Unmount the card.
Yeah, I thought there'd be a way of keeping the bootloader AND flashing direct. I'll just have to reflash the bootloader if I want it. Not a big deal really, a double-click on a .bat file and it's done.
Re: Protecting the bootloader when using ISP
A bit off topic..
So we can use 0xD7 and 0xFE for low fuse as in http://uzebox.org/forums/viewtopic.php? ... 20&start=0
The both works.
So we can use 0xD7 and 0xFE for low fuse as in http://uzebox.org/forums/viewtopic.php? ... 20&start=0
The both works.