else blockFlashRead( tempSize );
This function — depending on whether cmd is ‘B’ or
‘g’ — calls functions to load or read the Flash. The load
function is pretty much the same as the Flash load
function we discussed last month for the
SmileyFlash Writer. The blockFlashRead() function uses the
avrlibc pgm_read_byte_near(address) function similar to
what we saw in Workshop 25.
void blockFlashRead(uint16_t size)
data = pgm_read_byte_near(address++);
// send byte
// reduce number of bytes to read
// by one
} while (size);
// loop through size
Keeping the Bootloader as
Small as Possible
When we compile EduBootAVR with
AVRStudio/WinAVR with our usual settings, we get a code
size of 1,086 bytes. Oh, darn, the boot section boundary
is at 1,024, so it is 62 bytes too large. Can we get the
code smaller? Could we rewrite the program hoping to
find something that will save us 62 piddly bytes? Well, we
might, but there are other ways to save some space with a
Eliminate Some of the Start Code
When we use AVRStudio with WinAVR to compile
files, we get a gift of having necessary startup code added
for us. This includes the interrupt jump table. But what if
you aren’t using the interrupts? Well, you can eliminate it.
Since we aren’t using interrupts in the bootloader, let’s
dump the jump table! We do this by opening the Project
Configuration Options window Custom Options pane, as
shown in Figure 2. We write ‘-nostartfiles’ in the ‘Add’ test
box, then click ‘Add’ so that ‘-nostartfiles’ appears as
shown in the figure. This also removes some startup code
that we do need, so we have to add it back by putting the
following code snippet right before the main() function:
■ FIGURE 4. Connect Dialog.
SMILEY’S WORKSHOP ☺
■ FIGURE 3. Project Options General.
// From Peter Fluery AVRFreaks Aug 10 2005 -
// to remove interrupt Vector table
// put -nostartfiles in LDFlags, add the
// following function saves wasted space
void __jumpMain (void) __attribute__ ((naked))
__attribute__ ((section (“.init9”)));
asm volatile ( “.set __stack, %0” :: “i”
asm volatile ( “clr __zero_reg__” );
// r1 set to 0
asm volatile ( “rjmp main”);
// jump to main()
Now when we compile the code, we get 958 bytes
which will fit in the desired boot section. We could stop
here, but there is also another way to save some space.
Use a Different Optimization Level
We can keep the code unchanged and instead of
using the default optimization of –Os, we can use –O1.
You change this as shown in Figure 3. Just select –O1
from the Optimizations drop box. When you compile
using this optimization, you get 986 bytes which would
also get you inside the limits.
If you use both, you get 854 bytes, providing you with
■ FIGURE 5. Select AVR Programmer.
October 2010 63