Protecting the bootloader when using ISP

Topics regarding the Uzebox hardware/AVCore/BaseBoard (i.e: PCB, resistors, connectors, part list, schematics, hardware issues, etc.) should go here.
Post Reply
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Protecting the bootloader when using ISP

Post by nicksen782 »

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?
User avatar
Janka
Posts: 214
Joined: Fri Sep 21, 2012 10:46 pm
Location: inside Out

Re: Protecting the bootloader when using ISP

Post by Janka »

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". :(
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Protecting the bootloader when using ISP

Post by nicksen782 »

Then perhaps a combining of the game and boot loader text into one hex?
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Protecting the bootloader when using ISP

Post by nicksen782 »

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

Re: Protecting the bootloader when using ISP

Post by uze6666 »

You sure can. Here's the sequence of commands I use in my batch process to program the chips for my kits:

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
The important bit is the "-D" in the last command. It disables the chip erase... :)
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Protecting the bootloader when using ISP

Post by nicksen782 »

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.
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Protecting the bootloader when using ISP

Post by nicksen782 »

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.
User avatar
uze6666
Site Admin
Posts: 4823
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Protecting the bootloader when using ISP

Post by uze6666 »

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.
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.
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.
You don't need the bootloader when developing straight on the hardware. Just erase the chip and program your game over and over.
User avatar
nicksen782
Posts: 714
Joined: Wed Feb 01, 2012 8:23 pm
Location: Detroit, United States
Contact:

Re: Protecting the bootloader when using ISP

Post by nicksen782 »

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.
I have a really simple test for this now. Takes the guesswork out of it.

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.
When I build my Uzebox enclosure I'll be modding the hardware a bit to have a power switch to do this easy. Right now I just unplug the ISP programmer and/or AC adapter.

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.
greg
Posts: 5
Joined: Fri Nov 02, 2012 3:01 am
Location: Port-au-Prince, Haïti

Re: Protecting the bootloader when using ISP

Post by greg »

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.
Post Reply