[Tinyos-beta-commits] CVS: tinyos-1.x/beta/Deluge/TestDeluge/GoldenImage GoldenImageWriter.nc, NONE, 1.1 GoldenImageWriterM.nc, NONE, 1.1 Makefile, NONE, 1.1

Jonathan Hui jwhui at users.sourceforge.net
Sun Nov 21 21:31:00 PST 2004


Update of /cvsroot/tinyos/tinyos-1.x/beta/Deluge/TestDeluge/GoldenImage
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13752/TestDeluge/GoldenImage

Added Files:
	GoldenImageWriter.nc GoldenImageWriterM.nc Makefile 
Log Message:
- Initial checkin of Deluge v2.0.

- New features:
  - Support for hardware write protect of external flash chip.
  - Ping results include information obtained from Ident.h.
  - CRCs are no longer inlined with program data, thus allowing for
    DMA transfers from external flash to program flash.
  - Version number information included in Deluge packets to prevent
    nodes with different versions of Deluge from conflicts.
  - Support for TinyOS 2.x hardware independent storage abstraction.
  - Metadata data-structures include CRCs generated by the host PC
    to help guard against corruption.
  - TOSBoot bootloader now written in nesC.
  - Reduced RAM and ROM requirements.
  - Other minor enhancements that I can't think of right now.

- Major user differences:
  - Golden image is now slot 0. While it cannot be written to, the user
    can retrieve Ident.h information about the golden image.
  - When specifying an image for download, the user specifies the 
    build/<platform> directory rather than just the ihex file. The issue
    is that it is very difficult to pull out the Ident.h information
    without compile-time output.

- Known issues:
  - Does not support more than 1 downloadable image (actually, it might, 
    but I haven't tested it yet).

- To setup the Deluge tools, create the directory net/tinyos/deluge
and copy all files in 'delugetools' into it.

- Operation is very similar to Deluge v1.0.
  Ping:
    $ java net.tinyos.deluge.Deluge -p
  Download:
    $ java net.tinyos.deluge.Deluge -i -if <builddir> -in <imagenum>
  Reboot:
    $ java net.tinyos.deluge.Deluge -r -in <imagenum>



--- NEW FILE: GoldenImageWriter.nc ---
// $Id: GoldenImageWriter.nc,v 1.1 2004/11/22 05:30:58 jwhui Exp $

/*									tab:4
 * "Copyright (c) 2000-2004 The Regents of the University  of California.  
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose, without fee, and without written agreement is
 * hereby granted, provided that the above copyright notice, the following
 * two paragraphs and the author appear in all copies of this software.
 * 
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 */

/*
 * @author Jonathan Hui <jwhui at cs.berkeley.edu>
 */

includes Deluge;
includes GoldenImage;
includes TOSBoot;

configuration GoldenImageWriter {
}

implementation {

  components
    Main,
    DelugeC,
    DelugeMetadataC as Metadata,
    DelugeStorageC as Storage,
    FlashWPC,
    GoldenImageWriterM,
    InternalFlashC as IFlash,
    LedsC,
    NetProgC;

  Main.StdControl -> DelugeC;
  Main.StdControl -> GoldenImageWriterM;

  GoldenImageWriterM.DataWrite -> Storage.DataWrite[unique("DelugeDataWrite")];
  GoldenImageWriterM.FlashWP -> FlashWPC;
  GoldenImageWriterM.Metadata -> Metadata.Metadata[unique("DelugeMetadata")];
  GoldenImageWriterM.MetadataControl -> Metadata;
  GoldenImageWriterM.IFlash -> IFlash;
  GoldenImageWriterM.Leds -> LedsC;
  GoldenImageWriterM.NetProg -> NetProgC;
  GoldenImageWriterM.Storage -> Storage;

}

--- NEW FILE: GoldenImageWriterM.nc ---
// $Id: GoldenImageWriterM.nc,v 1.1 2004/11/22 05:30:58 jwhui Exp $

/*									tab:4
 * "Copyright (c) 2000-2004 The Regents of the University  of California.  
 * All rights reserved.
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose, without fee, and without written agreement is
 * hereby granted, provided that the above copyright notice, the following
 * two paragraphs and the author appear in all copies of this software.
 * 
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
 */

/*
 * @author Jonathan Hui <jwhui at cs.berkeley.edu>
 */

module GoldenImageWriterM {
  provides {
    interface StdControl;
  }
  uses {
    interface DelugeDataWrite as DataWrite;
    interface DelugeMetadata as Metadata;
    interface DelugeStorage as Storage;
    interface FlashWP;
    interface InternalFlash as IFlash;
    interface Leds;
    interface NetProg;
    interface SplitControl as MetadataControl;
  }
}

implementation {

  enum {
    BUF_SIZE = 128,
  };

  uint8_t  buf[BUF_SIZE];
  uint16_t curBuf;
  bool     allDone;

  DelugeImgDesc imgDesc;

  void fillBuf() {

    uint32_t target = 0, base, length;
    uint8_t  curBufPtr = 0;
    uint8_t  i;

    uint32_t offset = (uint32_t)(curBuf-1) * (uint32_t)BUF_SIZE;

    if (curBuf == 0) {
      for ( i = 0; i < BUF_SIZE; i++ )
	buf[i] = 0;

      memcpy(&buf[target], G_Ident.program_name, 9);
      target += 9;
      memcpy(&buf[target], &G_Ident.unix_time, sizeof(G_Ident.unix_time));
      target += sizeof(G_Ident.unix_time);
      memcpy(&buf[target], &G_Ident.user_hash, sizeof(G_Ident.user_hash));
      target += sizeof(G_Ident.user_hash);
      return;
    }

    for ( i = 0; i < GI_NUM_SECTIONS && curBufPtr < BUF_SIZE; i++ ) {
      base = startAddrs[i];
      length = endAddrs[i] - startAddrs[i];
      
      // base address
      for( ; offset < target + 4 && curBufPtr < BUF_SIZE; offset++ )
	buf[curBufPtr++] = (base >> ((offset-target)*8)) & 0xff;
      // length address
      for( target += 4; offset < target + 4 && curBufPtr < BUF_SIZE; offset++ )
	buf[curBufPtr++] = (length >> ((offset-target)*8)) & 0xff;
      // code data
      for( target += 4; offset < target + length && curBufPtr < BUF_SIZE; offset++ )
	buf[curBufPtr++] = GI_GET_BYTE(base + (offset-target));

      target += length;
    }

    if (i >= GI_NUM_SECTIONS) {
      for ( ; offset < target + 8 && curBufPtr < BUF_SIZE; offset++ )
	buf[curBufPtr++] = 0;
      if (offset >= target + 8)
	allDone = TRUE;
    }

  }

  task void writeData() {
    uint32_t offset = (uint32_t)curBuf * (uint32_t)BUF_SIZE + DELUGE_CRC_BLOCK_SIZE;
    if (call DataWrite.write(DELUGE_FACTORY_IMAGE_NUM, offset, buf, BUF_SIZE) == FAIL)
      post writeData();
  }

  command result_t StdControl.init() { return SUCCESS; }
  command result_t StdControl.start() { return SUCCESS; }
  command result_t StdControl.stop() { return SUCCESS; }

  event result_t MetadataControl.initDone() {
    return SUCCESS;
  }

  task void eraseData() {
    if (call Metadata.setupNewImage(&imgDesc) == FAIL)
      post eraseData();
  }

  task void clrWP() {
    if (call FlashWP.clrWP() == FAIL)
      post clrWP();
  }

  task void setWP() {
    if (call FlashWP.setWP() == FAIL)
      post setWP();
  }
  
  event result_t MetadataControl.startDone() { 

    uint8_t isGoldenImgLoaded;

    call IFlash.read((uint8_t*)TOSBOOT_FLAGS_ADDR, &isGoldenImgLoaded, 
		     sizeof(isGoldenImgLoaded));

    // don't clone to flash if golden image has been loaded
    if (!(isGoldenImgLoaded & TOSBOOT_GOLDEN_IMG_LOADED))
      return SUCCESS;
    
    // haven't cloned to flash before
    if (call FlashWP.clrWP() == FAIL)
      post clrWP();

    return SUCCESS; 

  }

  event result_t MetadataControl.stopDone() { 
    return SUCCESS; 
  }

  event result_t FlashWP.clrWPDone(result_t result) {
    allDone = FALSE;
    curBuf = 0;
    
    imgDesc.vNum = 0;
    imgDesc.imgNum = DELUGE_FACTORY_IMAGE_NUM;
    imgDesc.numPgs = 1;
    imgDesc.crc = 0;
    imgDesc.numPgsComplete = 1;
    if (call Metadata.setupNewImage(&imgDesc) == FAIL)
      post eraseData();
    return SUCCESS;
  }

  void completeWrite() {
    uint32_t addr;
    uint8_t  tmp8;

    // mark that golden image has been written
    call IFlash.read((uint8_t*)TOSBOOT_FLAGS_ADDR, &tmp8, sizeof(tmp8));
    tmp8 &= ~TOSBOOT_GOLDEN_IMG_LOADED;
    call IFlash.write((uint8_t*)TOSBOOT_FLAGS_ADDR, &tmp8, sizeof(tmp8));

    // have bootloader reprogram chip to verify that everything is working
    tmp8 = TOSBOOT_GESTURE_MAX_COUNT;
    call IFlash.write((uint8_t*)TOSBOOT_GESTURE_COUNT_ADDR, &tmp8, sizeof(tmp8));
    addr = call Storage.imgNum2Addr(DELUGE_FACTORY_IMAGE_NUM) + DELUGE_IDENT_SIZE;
    call IFlash.write((uint8_t*)TOSBOOT_NEW_IMG_START_ADDR, &addr, sizeof(addr));

    call NetProg.reboot();
  }

  event result_t FlashWP.setWPDone(result_t result) {
    completeWrite();
    return SUCCESS;
  }

  event result_t DataWrite.writeDone(result_t result) {

    if (result == FAIL) {
      // something went wrong, try again
      post writeData();
      return SUCCESS;
    }

    curBuf++;
    
    // if all done, sync image data
    if (allDone) {
      if (call FlashWP.setWP() == FAIL)
	post setWP();
      return SUCCESS;
    }

    call Leds.set(curBuf);

    fillBuf();
    post writeData();

    return SUCCESS;

  }

  event result_t DataWrite.eraseDone(result_t result) { return SUCCESS; }

  event result_t Metadata.setupNewImageDone(result_t result) {
    // start cloning
    call Metadata.receivedPage(DELUGE_FACTORY_IMAGE_NUM, 0);
    fillBuf();
    post writeData();
    return SUCCESS;
  }

}

--- NEW FILE: Makefile ---
COMPONENT=GoldenImageWriter
PFLAGS += -DDELUGE_GOLDEN_IMAGE -DDELUGE_LEDS
CFLAGS += -DTOSH_MAX_TASKS_LOG2=7
include $(TOSDIR)/../apps/Makerules


More information about the Tinyos-beta-commits mailing list