[En-Nut-Discussion] bootloader patches submitted for approval

Dave ethernut at wormfood.org
Wed May 25 14:30:29 CEST 2005


Hi everyone.

I just started using the bootloader on my project, and it is a fantastic
feature. Using the bootloader I can load my entire 60k program, in about
5 to 6 seconds, and 124k program loaded in about 10 seconds. I fixed a
few odds and ends with the bootloader, and thought others might like to
have these fixes too. The patch file is in a standard unix patch format,
I hope that don't cause problems for windows users. If it does, I'm sure
you can figure it out, or ask me, and I'll make the patched files
available on my web site, or attach them to another email.



Problem: Bootloader always uses a MAC address of 00:06:98:00:00:00

I notice that is on the list of things to fix. This could be a potental
problem for me, since I have 8 to 10 ethernut boards on one network. If
I add a new board with a different hardware configuration, I can't tell
the dhcp config to load a different boot file for that specific ethernut
board.

Solution: Load MAC address from EEPROM.

I modified NicInit(), in ether.c with the code that reads the MAC from
the EEPROM, because it would not work, when I put the same code in
main() just before NicInit() was called. I am rather curious to know why
this does not work as expected, perhaps it is another compiler bug.



Problem: The space between 1E000 and 1EFFF is never programmed by the
bootlader.

The FlashROM is divided up into 512 pages that can be programmed one at
a time. The FlashPage() function stops after 480 blocks, but it should
stop after 496 blocks.

Solution: Increase the loop counter to program an additional 16 blocks.

I modified tftp.c to program all memory, except where the bootloader
lives.



Problem: won't compile bootloader, because it can't find ../NutConf.mk

Solution: Change 'NutConf.mk' in Makefile to 'UserConf.mk'



Problem: bootloader will not compile with newer versions of avr-gcc.

Solution: Change all references to outb(), outp(), sbi() and cbi().



Here is my patch file, in addition to it being attached to my email. If
anyone has any problems or questions with it, please let me know. Under
Linux (and probably osx), type 'patch </path/to/eboot.patch', from
within the eboot directory, to apply the patch.

-Dave

diff -ru old/Makefile new/Makefile
--- old/Makefile        2005-05-19 00:53:34.000000000 -0400
+++ new/Makefile        2005-05-06 19:08:07.000000000 -0400
@@ -45,7 +45,7 @@
 top_srcdir = ..
 top_appdir = ..

-include $(top_srcdir)/NutConf.mk
+include $(top_srcdir)/UserConf.mk
 include Makedefs

 SRCS =  $(PROJ).c tftp.c dhcp.c udp.c ip.c arp.c ether.c util.c
diff -ru old/ether.c new/ether.c
--- old/ether.c 2005-05-19 00:53:34.000000000 -0400
+++ new/ether.c 2005-05-25 04:33:06.259526632 -0400
@@ -82,6 +82,19 @@
 #define NIC_FIRST_RX_PAGE   (NIC_FIRST_TX_PAGE + NIC_TX_PAGES *
NIC_TX_BUFFERS)
 #define TX_PAGES            12

+unsigned char EEPROM_read(unsigned int uiAddress)
+{
+       /* Wait for completion of previous write */
+       while(EECR & (1<<EEWE))
+               ;
+       /* Set up address register */
+       EEAR = uiAddress;
+       /* Start eeprom read by writing EERE */
+       EECR |= (1<<EERE);
+       /* Return data from data register */
+       return EEDR;
+}
+
 /*!
  * Realtek packet header.
  */
@@ -99,8 +112,8 @@
      * Prepare the EEPROM emulation port bits. Configure the EEDO
      * and the EEMU lines as outputs and set both lines to high.
      */
-    outb(PORTC, 0xC0);
-    outb(DDRC, 0xC0);
+    PORTC = 0xC0;
+    DDRC = 0xC0;
     Delay(20);

     /*
@@ -112,7 +125,7 @@
     /*
      * No external memory access beyond this point.
      */
-    cbi(MCUCR, SRE);
+    MCUCR &= ~_BV(SRE);

     /*
      * Loop until the chip stops toggling our EESK input.
@@ -130,11 +143,11 @@
     /*
      * Enable memory interface.
      */
-    sbi(MCUCR, SRE);
+    MCUCR |= _BV(SRE);

     /* Reset port outputs to default. */
-    outb(PORTC, 0x00);
-    outb(DDRC, 0x00);
+    PORTC = 0x00;
+    DDRC = 0x00;

     /* Wait until controller ready. */
     while(NIC_CR != (NIC_CR_STP | NIC_CR_RD2));
@@ -151,11 +164,15 @@
 {
     u_char c;

+    mac[3]=EEPROM_read(0x4D);
+    mac[4]=EEPROM_read(0x4E);
+    mac[5]=EEPROM_read(0x4F);
+
     /*
      * Enable external data and address
      * bus.
      */
-    outp(BV(SRE) | BV(SRW), MCUCR);
+    MCUCR = (_BV(SRE) | _BV(SRW));

     c = NIC_RESET;
     Delay(5);
diff -ru old/tftp.c new/tftp.c
--- old/tftp.c  2005-05-19 00:53:34.000000000 -0400
+++ new/tftp.c  2005-05-14 14:35:28.000000000 -0400
@@ -67,7 +67,7 @@
         len = 256;

     if (page >= 256) {
-        if (page >= 480)
+        if (page >= 496)
             return;
         RAMPZ = 1;
     } else


More information about the En-Nut-Discussion mailing list