  unsigned char buffer[BLOCKSIZE];
    unsigned int data;
    long tempaddress;
	
    // EEPROM memory type.
    if(mem=='E')
    {
        /* Fill buffer first, as EEPROM is too slow to copy with UART speed */
  //      for(tempaddress=0;tempaddress<size;tempaddress++)
  //          buffer[tempaddress] = recchar();

        /* Then program the EEPROM */
        WAIT_FOR_SPM();
    	for( tempaddress=0; tempaddress < size; tempaddress++)
    	{
	        EEARL = *address; // Setup EEPROM address
            EEARH = ((*address) >> 8);
            EEDR = buffer[tempaddress]; // Get byte.
            EECR |= (1<<EEMWE); // Write byte.
            EECR |= (1<<EEWE);
            while (EECR & (1<<EEWE)); // Wait for write operation to finish.

  			(*address)++; // Select next EEPROM byte
        }
        return '\r'; // Report programming OK
        
    } else if(mem=='F')  {     // Flash memory.
    
        (*address) <<= 1; // Convert address to bytes temporarily.
        tempaddress = (*address);  // Store address in page.
	
        do {
            data = 0x55 ;//getword();
            FILL_TEMP_WORD(*address, data);
            (*address)+=2; // Select next word in memory.
            size -= 2; // Reduce number of bytes to write by two.
        } while(size); // Loop until all bytes written.

	    PAGE_WRITE(tempaddress);
	    WAIT_FOR_SPM();
	    ENABLE_RWW_SECTION();
	    
        (*address) >>= 1; // Convert address back to Flash words again.
        return '\r'; // Report programming OK
        
    } else {
        return '?';
    }
    
    
    
    
    
    
    
    
    -----------------------
    
    
            uint16_t i;
        uint8_t sreg;
        uint32_t page;
        
        page = 0;

        // Disable interrupts.

        sreg = SREG;
        cli();
    
        eeprom_busy_wait ();

        boot_page_erase (page);
        boot_spm_busy_wait ();      // Wait until the memory is erased.

        for (i=0; i<SPM_PAGESIZE; i+=2) {
            boot_page_fill (page + i, 0x5555);
        }

        boot_page_write (page);     // Store buffer in flash page.
        boot_spm_busy_wait();       // Wait until the memory is written.

        // Reenable RWW-section again. We need this if we want to jump back
        // to the application after bootloading.

        boot_rww_enable ();

        // Re-enable interrupts (if they were ever enabled).

        SREG = sreg;
        return '\r';
