[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/net/blip/nwprog BootImage.nc, NONE, 1.1 Deluge.h, NONE, 1.1 DelugePatch.nc, NONE, 1.1 DelugePatchC.nc, NONE, 1.1 DelugePatchClientC.nc, NONE, 1.1 DelugePatchP.nc, NONE, 1.1 DelugeReadIdent.nc, NONE, 1.1 DelugeReadIdentC.nc, NONE, 1.1 DelugeReadIdentClientC.nc, NONE, 1.1 DelugeReadIdentP.nc, NONE, 1.1 DelugeVerify.nc, NONE, 1.1 DelugeVerifyC.nc, NONE, 1.1 DelugeVerifyClientC.nc, NONE, 1.1 DelugeVerifyP.nc, NONE, 1.1 NWProgC.nc, NONE, 1.1 NWProgP.nc, NONE, 1.1
sdhsdh
sdhsdh at users.sourceforge.net
Mon Jan 19 16:28:18 PST 2009
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/net/blip/interfaces ICMP.nc, NONE, 1.1 ICMPPing.nc, NONE, 1.1 IP.nc, NONE, 1.1 IPAddress.nc, NONE, 1.1 IPRouting.nc, NONE, 1.1 Statistics.nc, NONE, 1.1 Tcp.nc, NONE, 1.1 UDP.nc, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/net/blip/serial SerialDevConf.h, NONE, 1.1 SerialDevConfC.nc, NONE, 1.1 SerialPacketInfoDevConfP.nc, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/net/blip/nwprog
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv6583/tos/lib/net/blip/nwprog
Added Files:
BootImage.nc Deluge.h DelugePatch.nc DelugePatchC.nc
DelugePatchClientC.nc DelugePatchP.nc DelugeReadIdent.nc
DelugeReadIdentC.nc DelugeReadIdentClientC.nc
DelugeReadIdentP.nc DelugeVerify.nc DelugeVerifyC.nc
DelugeVerifyClientC.nc DelugeVerifyP.nc NWProgC.nc NWProgP.nc
Log Message:
- initial commit of blip (berkeley low-power ip) stack
--- NEW FILE: BootImage.nc ---
interface BootImage {
command void reboot();
command error_t boot(uint8_t img_num);
// Added by Jaein Jeong
command error_t erase(uint8_t img_num);
}
--- NEW FILE: Deluge.h ---
/* Copyright (c) 2007 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
*/
#ifndef __DELUGE_H__
#define __DELUGE_H__
typedef nx_struct DelugeIdent {
nx_uint32_t uidhash; // unique id of the image
nx_uint32_t size; // size of the whole image (ident + CRCs + binary)
nx_uint8_t numPgs; // number of pages of complete image
nx_uint8_t reserved;
nx_uint16_t crc; // crc over the above 4 fields
nx_uint8_t appname[16];
nx_uint8_t username[16];
nx_uint8_t hostname[16];
nx_uint8_t platform[16];
nx_uint32_t timestamp;
nx_uint32_t userhash;
} DelugeIdent;
typedef nx_struct DelugePatchCmd {
nx_uint16_t linenum; // sequence number of patches, starting from 0
nx_uint8_t cmd; // patch cmd: 16 for upload, 17 for copy
nx_uint16_t dst_offset;
nx_uint16_t data_length; // byte length of the data
nx_uint16_t src_offset;
nx_uint8_t reserved[7];
nx_uint8_t data[0]; // data for the upload command
} DelugePatchCmd;
enum {
DELUGE_INVALID_UID = 0xffffffff,
DELUGE_NUM_VOLUMES = 4,
DELUGE_IDENT_SIZE = 128,
DELUGE_MAX_PAGES = 128,
DELUGE_CRC_SIZE = sizeof(uint16_t),
DELUGE_CRC_BLOCK_SIZE = DELUGE_MAX_PAGES * DELUGE_CRC_SIZE,
DELUGE_BYTES_PER_PAGE = 23 * 48,
};
enum {
MAX_PATCH_DATA_SIZE = 512,
PATCH_LINE_SIZE = 16,
};
#define UQ_DELUGE_METADATA "DelugeMetadata.client"
#define UQ_DELUGE_VOLUME_MANAGER "DelugeVolumeManager.client"
#define UQ_DELUGE_VERIFY "DelugeVerify.client"
#define UQ_DELUGE_PATCH "DelugePatch.client"
#define UQ_DELUGE_READ_IDENT "DelugeReadIdent.client"
typedef struct BootArgs {
uint16_t address;
uint32_t imageAddr;
uint8_t gestureCount;
bool noReprogram;
} BootArgs;
enum {
NWPROG_CMD_ERASE = 1,
NWPROG_CMD_WRITE = 2,
};
enum{
PATCH_CMD_UPLOAD = 16,
PATCH_CMD_COPY = 17,
};
typedef nx_struct prog_req {
nx_uint8_t cmd;
nx_uint8_t imgno;
nx_uint16_t offset;
nx_uint8_t data[0];
} prog_req_t;
typedef nx_struct prog_reply {
nx_uint8_t error;
nx_struct prog_req req;
} prog_reply_t;
#endif
--- NEW FILE: DelugePatch.nc ---
/**
* An interface for obtaining the identification data of an
* image. The pointer returned by readDone will be destroyed by the
* next read.
*
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
interface DelugePatch
{
command error_t decodePatch(uint8_t imgNumPatch, uint8_t imgNumSrc, uint8_t imgNumDst);
event void decodePatchDone(uint8_t imgNumPatch, uint8_t imgNumSrc, uint8_t imgNumDst, error_t error);
}
--- NEW FILE: DelugePatchC.nc ---
/* Copyright (c) 2007 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
configuration DelugePatchC
{
provides interface DelugePatch[uint8_t client];
uses event void storageReady();
}
implementation
{
components MainC;
components DelugePatchP;
DelugePatch = DelugePatchP;
storageReady = DelugePatchP;
components new BlockReaderC(VOLUME_GOLDENIMAGE) as BlockReaderGoldenImage;
components new BlockReaderC(VOLUME_DELUGE1) as BlockReaderDeluge1;
components new BlockReaderC(VOLUME_DELUGE2) as BlockReaderDeluge2;
components new BlockReaderC(VOLUME_DELUGE3) as BlockReaderDeluge3;
DelugePatchP.BlockRead[VOLUME_GOLDENIMAGE] -> BlockReaderGoldenImage;
DelugePatchP.BlockRead[VOLUME_DELUGE1] -> BlockReaderDeluge1;
DelugePatchP.BlockRead[VOLUME_DELUGE2] -> BlockReaderDeluge2;
DelugePatchP.BlockRead[VOLUME_DELUGE3] -> BlockReaderDeluge3;
components new BlockWriterC(VOLUME_GOLDENIMAGE) as BlockWriterGoldenImage;
components new BlockWriterC(VOLUME_DELUGE1) as BlockWriterDeluge1;
components new BlockWriterC(VOLUME_DELUGE2) as BlockWriterDeluge2;
components new BlockWriterC(VOLUME_DELUGE3) as BlockWriterDeluge3;
DelugePatchP.BlockWrite[VOLUME_GOLDENIMAGE] -> BlockWriterGoldenImage;
DelugePatchP.BlockWrite[VOLUME_DELUGE1] -> BlockWriterDeluge1;
DelugePatchP.BlockWrite[VOLUME_DELUGE2] -> BlockWriterDeluge2;
DelugePatchP.BlockWrite[VOLUME_DELUGE3] -> BlockWriterDeluge3;
}
--- NEW FILE: DelugePatchClientC.nc ---
/* Copyright (c) 2007 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
generic configuration DelugePatchClientC()
{
provides interface DelugePatch;
}
implementation
{
enum {
CLIENT_ID = unique(UQ_DELUGE_PATCH)
};
components DelugePatchC;
DelugePatch = DelugePatchC.DelugePatch[CLIENT_ID];
}
--- NEW FILE: DelugePatchP.nc ---
/* Copyright (c) 2007 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
#include "imgNum2volumeId.h"
module DelugePatchP
{
provides interface DelugePatch[uint8_t client];
uses {
interface BlockRead[uint8_t volumeId];
interface BlockWrite[uint8_t volumeId];
interface StorageMap[uint8_t volumeId];
event void storageReady();
}
}
implementation
{
enum {
S_READ_IDENT,
S_READY,
S_BUSY,
S_READ_PATCH_CMD,
S_READ_PATCH_DATA,
S_READ_PATCH_COPY,
S_WRITE_PATCH,
};
DelugeIdent ident;
DelugePatchCmd patch;
uint8_t patchData[MAX_PATCH_DATA_SIZE];
uint8_t state;
uint8_t currentClient;
uint16_t patchNumLinesRead;
uint16_t patchNumLines;
uint32_t patchByteAddr;
uint8_t patchVolume;
uint8_t patchImageIdx;
uint8_t patchPage;
uint32_t dstByteAddr;
uint8_t srcVolume;
uint8_t srcImageIdx;
uint8_t srcPage;
uint32_t dstByteAddr;
uint8_t dstVolume;
uint8_t dstImageIdx;
uint8_t dstPage;
void setStorageReady()
{
signal storageReady();
state = S_READY;
}
void notifySuccess()
{
signal DelugePatch.decodePatchDone[currentClient](
patchImageIdx, srcImageIdx, dstImageIdx, SUCCESS);
setStorageReady();
}
void notifyFailure(error_t error)
{
signal DelugePatch.decodePatchDone[currentClient](
patchImageIdx, srcImageIdx, dstImageIdx, error);
setStorageReady();
}
command error_t DelugePatch.decodePatch[uint8_t client](uint8_t imgNumPatch,
uint8_t imgNumSrc,
uint8_t imgNumDst)
{
patchImageIdx = imgNumPatch;
patchVolume = _imgNum2volumeId[patchImageIdx];
srcImageIdx = imgNumSrc;
srcVolume = _imgNum2volumeId[srcImageIdx];
dstImageIdx = imgNumDst;
dstVolume = _imgNum2volumeId[dstImageIdx];
// First, read the DelugeIdent section.
if (patchImageIdx < DELUGE_NUM_VOLUMES) {
state = S_READ_IDENT;
call BlockRead.read[patchVolume](0, &ident, sizeof(ident));
} else {
signal storageReady();
state = S_READY;
}
return SUCCESS;
}
event void BlockRead.readDone[uint8_t imgNum](
storage_addr_t addr, void* buf, storage_len_t len, error_t error)
{
switch (state) {
case S_BUSY:
notifyFailure(error);
break;
// Read the DelugeIdent structure into ident.
// If it is valid, ident.userhash contains
// number of patch command lines.
// Initialize patchByteAddr to the beginning of
// the patch commands.
case S_READ_IDENT:
if (error == SUCCESS) {
if (ident.uidhash != DELUGE_INVALID_UID) {
patchNumLines = ident.userhash;
state = S_READ_PATCH_CMD;
patchByteAddr = DELUGE_IDENT_SIZE + DELUGE_CRC_BLOCK_SIZE;
call BlockRead.read[patchVolume](patchByteAddr, &patch, sizeof(patch));
break;
}
}
notifyFailure(error);
break;
// Read a patch command.
// If successful, check it is UPLOAD or COPY.
// For an UPLOAD commandy
// increment the number of patch lines read,
// increase patchByteAddr by PATCH_LINE_SIZE,
// and read the patch data.
// For a COPY command,
// increment the number of patch lines read,
// increase patchByteAddr by PATCH_LINE_SIZE,
// and read data from the source volume.
case S_READ_PATCH_CMD:
if (error == SUCCESS) {
if (patch.cmd == PATCH_CMD_UPLOAD) {
patchNumLinesRead++;
patchByteAddr += PATCH_LINE_SIZE; // read the next line of patch
state = S_READ_PATCH_DATA;
call BlockRead.read[patchVolume](patchByteAddr, patchData, patch.data_length);
break;
}
else if (patch.cmd == PATCH_CMD_COPY) {
patchNumLinesRead++;
patchByteAddr += PATCH_LINE_SIZE; // read the next line of patch
state = S_READ_PATCH_COPY;
call BlockRead.read[srcVolume](patch.src_offset, patchData, patch.data_length);
break;
}
}
notifyFailure(error);
break;
// When the patch data of PATCH_UPLOAD is ready,
// increase patchByteAddr ceiling(len / PATCH_LINE_SIZE) * PATCH_LINE_SIZE,
// and write it into the destination volume.
case S_READ_PATCH_DATA:
if (error == SUCCESS) {
state = S_WRITE_PATCH;
patchByteAddr += ((len + PATCH_LINE_SIZE - 1) / PATCH_LINE_SIZE * PATCH_LINE_SIZE);
call BlockWrite.write[dstVolume](patch.dst_offset, buf, len);
break;
}
notifyFailure(error);
break;
// When the source data of PATCH_COPY is ready,
// write it into the destination volume.
case S_READ_PATCH_COPY:
if (error == SUCCESS) {
state = S_WRITE_PATCH;
call BlockWrite.write[dstVolume](patch.dst_offset, buf, len);
break;
}
notifyFailure(error);
break;
}
}
event void BlockWrite.writeDone[uint8_t imgNum](
storage_addr_t addr, void* buf, storage_len_t len, error_t error)
{
switch (state) {
case S_WRITE_PATCH:
if (error == SUCCESS) {
// When more patch commands remaining, read the next one.
if (patchNumLinesRead < patchNumLines) {
state = S_READ_PATCH_CMD;
call BlockRead.read[patchVolume](patchByteAddr, &patch, sizeof(patch));
}
else {
notifySuccess();
}
break;
}
notifyFailure(error);
break;
}
}
event void BlockWrite.eraseDone[uint8_t imgNum](error_t error)
{
switch (state) {
case S_READY:
signal BlockWrite.eraseDone[imgNum](error);
break;
}
}
default command error_t BlockWrite.write[uint8_t imgNum](
storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; }
default command error_t BlockRead.read[uint8_t imgNum](
storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; }
default command error_t BlockRead.computeCrc[uint8_t imgNum](
storage_addr_t addr, storage_len_t len, uint16_t crc) { return FAIL; }
event void BlockRead.computeCrcDone[uint8_t imgNum](
storage_addr_t addr, storage_len_t len, uint16_t crc, error_t error) {}
event void BlockWrite.syncDone[uint8_t imgNum](error_t error) {}
default command error_t BlockWrite.erase[uint8_t imgNum]() { return FAIL; }
default event void storageReady() {}
default event void DelugePatch.decodePatchDone[uint8_t client](
uint8_t imgNumPatch, uint8_t imgNumSrc, uint8_t imgNumDst, error_t error) {}
}
--- NEW FILE: DelugeReadIdent.nc ---
/**
* An interface for obtaining the identification data of an
* image. The pointer returned by readDone will be destroyed by the
* next read.
*
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
interface DelugeReadIdent
{
command error_t readNumVolumes();
command error_t readVolume(uint8_t imgNum);
event void readNumVolumesDone(uint8_t validVolumes, uint8_t volumeFields, error_t error);
event void readVolumeDone(uint8_t imgNum, DelugeIdent* ident, error_t error);
//command error_t read(uint8_t imgNum);
//event void readDone(uint8_t imgNum, DelugeIdent* ident, error_t error);
}
--- NEW FILE: DelugeReadIdentC.nc ---
/* Copyright (c) 2007 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
configuration DelugeReadIdentC
{
provides interface DelugeReadIdent[uint8_t client];
uses event void storageReady();
}
implementation
{
components MainC;
components DelugeReadIdentP;
DelugeReadIdent = DelugeReadIdentP;
storageReady = DelugeReadIdentP;
DelugeReadIdentP.Boot -> MainC;
components new BlockReaderC(VOLUME_GOLDENIMAGE) as BlockReaderGoldenImage;
components new BlockReaderC(VOLUME_DELUGE1) as BlockReaderDeluge1;
components new BlockReaderC(VOLUME_DELUGE2) as BlockReaderDeluge2;
components new BlockReaderC(VOLUME_DELUGE3) as BlockReaderDeluge3;
DelugeReadIdentP.BlockRead[VOLUME_GOLDENIMAGE] -> BlockReaderGoldenImage;
DelugeReadIdentP.BlockRead[VOLUME_DELUGE1] -> BlockReaderDeluge1;
DelugeReadIdentP.BlockRead[VOLUME_DELUGE2] -> BlockReaderDeluge2;
DelugeReadIdentP.BlockRead[VOLUME_DELUGE3] -> BlockReaderDeluge3;
}
--- NEW FILE: DelugeReadIdentClientC.nc ---
/* Copyright (c) 2007 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
generic configuration DelugeReadIdentClientC()
{
provides interface DelugeReadIdent;
}
implementation
{
enum {
CLIENT_ID = unique(UQ_DELUGE_READ_IDENT)
};
components DelugeReadIdentC;
DelugeReadIdent = DelugeReadIdentC.DelugeReadIdent[CLIENT_ID];
}
--- NEW FILE: DelugeReadIdentP.nc ---
/* Copyright (c) 2007 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
#include "imgNum2volumeId.h"
module DelugeReadIdentP
{
provides interface DelugeReadIdent[uint8_t client];
uses {
interface Boot;
interface BlockRead[uint8_t volumeId];
interface StorageMap[uint8_t volumeId];
event void storageReady();
}
}
implementation
{
enum {
S_READY,
S_READ_VOLUME,
S_READ_NUM_VOLUMES,
};
DelugeIdent ident;
uint8_t state;
uint8_t currentClient;
uint8_t currentIdx;
uint8_t currentVolume;
uint8_t fields;
uint8_t validVolumes;
event void Boot.booted() { }
command error_t DelugeReadIdent.readVolume[uint8_t client](uint8_t imgNum)
{
if (state != S_READY) {
return FAIL;
}
else {
currentClient = client;
currentIdx = imgNum;
currentVolume = _imgNum2volumeId[currentIdx];
if (imgNum < DELUGE_NUM_VOLUMES) {
state = S_READ_VOLUME;
return call BlockRead.read[currentVolume](0, &ident, sizeof(ident));
}
else {
return FAIL;
}
}
}
command error_t DelugeReadIdent.readNumVolumes[uint8_t client]()
{
if (state != S_READY) {
return FAIL;
}
else {
fields = 0;
validVolumes = 0;
currentClient = client;
currentIdx = 0;
currentVolume = _imgNum2volumeId[currentIdx];
state = S_READ_NUM_VOLUMES;
return call BlockRead.read[currentVolume](0, &ident, sizeof(ident));
}
}
event void BlockRead.readDone[uint8_t imgNum](
storage_addr_t addr, void* buf, storage_len_t len, error_t error)
{
switch (state) {
case S_READ_VOLUME:
if (error == SUCCESS && ident.uidhash != DELUGE_INVALID_UID) {
signal DelugeReadIdent.readVolumeDone[currentClient](currentIdx, buf, SUCCESS);
}
else {
signal DelugeReadIdent.readVolumeDone[currentClient](currentIdx, buf, FAIL);
}
state = S_READY;
signal storageReady();
break;
case S_READ_NUM_VOLUMES:
if (error == SUCCESS && ident.uidhash != DELUGE_INVALID_UID) {
// Increment valid volumes only when uidhash is valid.
fields |= (1 << currentIdx);
validVolumes++;
}
// Increment the number volumes read.
currentIdx++;
currentVolume = _imgNum2volumeId[currentIdx];
// Read the next volume when it didn't reach the end.
if (currentIdx < DELUGE_NUM_VOLUMES) {
call BlockRead.read[currentVolume](0, &ident, sizeof(ident));
}
// Otherwise, notify the success.
else {
state = S_READY;
signal storageReady();
signal DelugeReadIdent.readNumVolumesDone[currentClient](
validVolumes, fields, SUCCESS);
}
break;
}
}
event void BlockRead.computeCrcDone[uint8_t imgNum](
storage_addr_t addr, storage_len_t len, uint16_t crc, error_t error) {}
default command error_t BlockRead.read[uint8_t imgNum](
storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; }
default command error_t BlockRead.computeCrc[uint8_t imgNum](
storage_addr_t addr, storage_len_t len, uint16_t crc) { return FAIL; }
default event void storageReady() {}
default event void DelugeReadIdent.readNumVolumesDone[uint8_t client](
uint8_t validVols, uint8_t volumeFields, error_t error) {}
default event void DelugeReadIdent.readVolumeDone[uint8_t client](
uint8_t imgNum, DelugeIdent* id, error_t error) {}
}
--- NEW FILE: DelugeVerify.nc ---
/**
* An interface for obtaining the identification data of an
* image. The pointer returned by readDone will be destroyed by the
* next read.
*
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
interface DelugeVerify
{
command error_t verifyImg(uint8_t imgNum);
event void verifyImgDone(uint8_t imgNum, error_t error);
}
--- NEW FILE: DelugeVerifyC.nc ---
/* Copyright (c) 2007 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
configuration DelugeVerifyC
{
provides interface DelugeVerify[uint8_t client];
uses event void storageReady();
}
implementation
{
components MainC;
components DelugeVerifyP;
DelugeVerify = DelugeVerifyP;
storageReady = DelugeVerifyP;
components new BlockReaderC(VOLUME_GOLDENIMAGE) as BlockReaderGoldenImage;
components new BlockReaderC(VOLUME_DELUGE1) as BlockReaderDeluge1;
components new BlockReaderC(VOLUME_DELUGE2) as BlockReaderDeluge2;
components new BlockReaderC(VOLUME_DELUGE3) as BlockReaderDeluge3;
DelugeVerifyP.BlockRead[VOLUME_GOLDENIMAGE] -> BlockReaderGoldenImage;
DelugeVerifyP.BlockRead[VOLUME_DELUGE1] -> BlockReaderDeluge1;
DelugeVerifyP.BlockRead[VOLUME_DELUGE2] -> BlockReaderDeluge2;
DelugeVerifyP.BlockRead[VOLUME_DELUGE3] -> BlockReaderDeluge3;
components new BlockWriterC(VOLUME_GOLDENIMAGE) as BlockWriterGoldenImage;
components new BlockWriterC(VOLUME_DELUGE1) as BlockWriterDeluge1;
components new BlockWriterC(VOLUME_DELUGE2) as BlockWriterDeluge2;
components new BlockWriterC(VOLUME_DELUGE3) as BlockWriterDeluge3;
DelugeVerifyP.BlockWrite[VOLUME_GOLDENIMAGE] -> BlockWriterGoldenImage;
DelugeVerifyP.BlockWrite[VOLUME_DELUGE1] -> BlockWriterDeluge1;
DelugeVerifyP.BlockWrite[VOLUME_DELUGE2] -> BlockWriterDeluge2;
DelugeVerifyP.BlockWrite[VOLUME_DELUGE3] -> BlockWriterDeluge3;
}
--- NEW FILE: DelugeVerifyClientC.nc ---
/* Copyright (c) 2007 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
generic configuration DelugeVerifyClientC()
{
provides interface DelugeVerify;
}
implementation
{
enum {
CLIENT_ID = unique(UQ_DELUGE_VERIFY)
};
components DelugeVerifyC;
DelugeVerify = DelugeVerifyC.DelugeVerify[CLIENT_ID];
}
--- NEW FILE: DelugeVerifyP.nc ---
/* Copyright (c) 2007 Johns Hopkins University.
* 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 (updated) modification history and the author appear in
* all copies of this source code.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, LOSS OF USE, DATA,
* OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @author Razvan Musaloiu-E. <razvanm at cs.jhu.edu>
* @author Chieh-Jan Mike Liang <cliang4 at cs.jhu.edu>
*/
#include "imgNum2volumeId.h"
module DelugeVerifyP
{
provides interface DelugeVerify[uint8_t client];
uses {
interface BlockRead[uint8_t volumeId];
interface BlockWrite[uint8_t volumeId];
interface StorageMap[uint8_t volumeId];
event void storageReady();
}
}
implementation
{
enum {
S_READ_IDENT,
S_READ_CRC,
S_CRC,
S_READY,
S_BUSY,
};
DelugeIdent ident;
uint8_t state;
uint8_t currentVolume;
uint8_t currentImageIdx;
uint8_t currentPage;
nx_uint16_t currentCrc;
uint8_t currentClient;
void setStorageReady()
{
signal storageReady();
state = S_READY;
}
uint32_t calcCrcAddr()
{
return DELUGE_IDENT_SIZE + currentPage * sizeof(uint16_t);
}
uint32_t calcPageAddr()
{
return DELUGE_IDENT_SIZE + DELUGE_CRC_BLOCK_SIZE + currentPage * DELUGE_BYTES_PER_PAGE;
}
command error_t DelugeVerify.verifyImg[uint8_t client](uint8_t imgNum)
{
// We are going to verify the integrity of the specified image.
// We first read the ident to find the number of pages and
// then iterate over all of them, compute the CRC and
// check it against the corresponding value from the CRCs block.
state = S_READ_IDENT;
currentImageIdx = imgNum;
currentVolume = _imgNum2volumeId[currentImageIdx];
if (currentImageIdx < DELUGE_NUM_VOLUMES) {
state = S_READ_IDENT;
call BlockRead.read[currentVolume](0, &ident, sizeof(ident));
} else {
signal storageReady();
state = S_READY;
}
return SUCCESS;
}
event void BlockRead.readDone[uint8_t imgNum](storage_addr_t addr, void* buf, storage_len_t len, error_t error)
{
switch (state) {
case S_BUSY:
setStorageReady();
signal DelugeVerify.verifyImgDone[currentClient](imgNum, error);
break;
case S_READ_IDENT:
if (error == SUCCESS) {
if (ident.uidhash != DELUGE_INVALID_UID) {
currentPage = 0;
state = S_READ_CRC;
call BlockRead.read[currentVolume](calcCrcAddr(), ¤tCrc, sizeof(currentCrc));
break;
}
}
setStorageReady();
signal DelugeVerify.verifyImgDone[currentClient](imgNum, FAIL);
break;
case S_READ_CRC:
state = S_CRC;
call BlockRead.computeCrc[currentVolume](calcPageAddr(), DELUGE_BYTES_PER_PAGE, 0);
break;
}
}
event void BlockRead.computeCrcDone[uint8_t imgNum](storage_addr_t addr, storage_len_t len, uint16_t crc, error_t error)
{
switch (state) {
case S_CRC:
if (crc != currentCrc) {
setStorageReady();
signal DelugeVerify.verifyImgDone[currentClient](imgNum, FAIL);
} else {
currentPage++;
if (currentPage < ident.numPgs) {
state = S_READ_CRC;
call BlockRead.read[currentVolume](calcCrcAddr(), ¤tCrc, sizeof(currentCrc));
}
else {
setStorageReady();
signal DelugeVerify.verifyImgDone[currentClient](imgNum, error);
}
}
break;
}
}
default command error_t BlockRead.read[uint8_t imgNum](storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; }
default command error_t BlockRead.computeCrc[uint8_t imgNum](storage_addr_t addr, storage_len_t len, uint16_t crc) { return FAIL; }
event void BlockWrite.writeDone[uint8_t imgNum](storage_addr_t addr, void* buf, storage_len_t len, error_t error) {}
event void BlockWrite.eraseDone[uint8_t imgNum](error_t error)
{
switch (state) {
case S_READY:
signal BlockWrite.eraseDone[imgNum](error);
break;
}
}
event void BlockWrite.syncDone[uint8_t imgNum](error_t error) {}
default command error_t BlockWrite.erase[uint8_t imgNum]() { return FAIL; }
default event void storageReady() {}
default event void DelugeVerify.verifyImgDone[uint8_t client](uint8_t imgNum, error_t error) {}
}
--- NEW FILE: NWProgC.nc ---
#include "StorageVolumes.h"
#include "Deluge.h"
configuration NWProgC {
provides interface BootImage;
} implementation {
// send and receive pages
components MainC, IPDispatchC;
components NetProgC, NWProgP;
BootImage = NWProgP;
components BlockStorageManagerC;
components new BlockStorageLockClientC();
components new BlockWriterC(VOLUME_GOLDENIMAGE) as BlockWriterDeluge0;
components new BlockWriterC(VOLUME_DELUGE1) as BlockWriterDeluge1;
components new BlockWriterC(VOLUME_DELUGE2) as BlockWriterDeluge2;
components new BlockWriterC(VOLUME_DELUGE3) as BlockWriterDeluge3;
NWProgP.Boot -> MainC;
NWProgP.NetProg -> NetProgC;
NWProgP.StorageMap -> BlockStorageManagerC;
NWProgP.Recv -> IPDispatchC.UDP[5213];
NWProgP.Resource -> BlockStorageLockClientC;
NWProgP.BlockWrite[VOLUME_GOLDENIMAGE] -> BlockWriterDeluge0;
NWProgP.BlockWrite[VOLUME_DELUGE1] -> BlockWriterDeluge1;
NWProgP.BlockWrite[VOLUME_DELUGE2] -> BlockWriterDeluge2;
NWProgP.BlockWrite[VOLUME_DELUGE3] -> BlockWriterDeluge3;
components new ShellCommandC("nwprog");
NWProgP.ShellCommand -> ShellCommandC;
components new TimerMilliC();
NWProgP.RebootTimer -> TimerMilliC;
components new DelugeMetadataClientC();
NWProgP.DelugeMetadata -> DelugeMetadataClientC;
}
--- NEW FILE: NWProgP.nc ---
#include <Storage.h>
#include <Shell.h>
#include "imgNum2volumeId.h"
#include "Deluge.h"
module NWProgP {
provides interface BootImage;
uses {
interface Boot;
interface UDP as Recv;
interface StorageMap[uint8_t imag_num];
interface NetProg;
interface BlockWrite[uint8_t img_num];
interface Resource;
interface ShellCommand;
interface DelugeMetadata;
interface Timer<TMilli> as RebootTimer;
event void storageReady();
}
} implementation {
enum {
S_IDLE,
S_BUSY,
};
uint8_t state;
struct sockaddr_in6 endpoint;
prog_reply_t reply;
// Begin-added by Jaein Jeong
command error_t BootImage.erase(uint8_t img_num) {
error_t error = call BlockWrite.erase[img_num]();
return error;
}
// End-added
command void BootImage.reboot() {
call NetProg.reboot();
}
command error_t BootImage.boot(uint8_t img_num) {
return call NetProg.programImageAndReboot(call StorageMap.getPhysicalAddress[img_num](0));
}
event void Boot.booted() {
state = S_IDLE;
}
void sendDone(error_t error) {
reply.error = error;
call Recv.sendto(&endpoint, &reply, sizeof(prog_reply_t));
}
event void Recv.recvfrom(struct sockaddr_in6 *from,
void *payload, uint16_t len,
struct ip_metadata *meta) {
prog_req_t *req = (prog_req_t *)payload;
uint8_t imgNum = imgNum2volumeId(req->imgno);
error_t error = FAIL;
void *buffer;
// just copy the payload out and write it into flash
// we'll send the ack from the write done event.
if (state != S_IDLE) return;
memcpy(&endpoint, from, sizeof(struct sockaddr_in6));
memcpy(&reply.req, req, sizeof(prog_req_t));
if (!call Resource.isOwner()) {
error = call Resource.immediateRequest();
}
if (error == SUCCESS) {
switch (req->cmd) {
case NWPROG_CMD_ERASE:
error = call BlockWrite.erase[imgNum]();
break;
case NWPROG_CMD_WRITE:
len -= sizeof(prog_req_t);
buffer = ip_malloc(len);
if (buffer == NULL) {
error = ENOMEM;
break;
}
memcpy(buffer, req->data, len);
error = call BlockWrite.write[imgNum](req->offset,
buffer,
len);
if (error != SUCCESS) ip_free(buffer);
break;
default:
error = FAIL;
}
}
if (error != SUCCESS) {
sendDone(error);
call Resource.release();
} else {
state = S_BUSY;
}
}
event void BlockWrite.writeDone[uint8_t img_num](storage_addr_t addr, void* buf, storage_len_t len, error_t error) {
if (state != S_BUSY) return;
sendDone(error);
call Resource.release();
state = S_IDLE;
ip_free(buf);
}
event void BlockWrite.eraseDone[uint8_t img_num](error_t error) {
if (state != S_BUSY) return;
if (error == SUCCESS)
call BlockWrite.sync[img_num]();
else {
sendDone(error);
state = S_IDLE;
call Resource.release();
}
}
event void BlockWrite.syncDone[uint8_t img_num](error_t error) {
if (state != S_BUSY) return;
sendDone(error);
state = S_IDLE;
call Resource.release();
}
event void Resource.granted() {
}
/*
* Shell command implementation
*/
char *nwprog_help_str = "nwprog [list | boot <imgno> [when] | reboot]\n";
uint8_t nwprog_currentvol, nwprog_validvols;
uint8_t boot_image;
uint8_t volumeID2imgNum(uint8_t volumeID) {
switch(volumeID) {
case VOLUME_GOLDENIMAGE: return 0;
case VOLUME_DELUGE1: return 1;
case VOLUME_DELUGE2: return 2;
case VOLUME_DELUGE3: return 3;
}
}
event void DelugeMetadata.readDone(uint8_t imgNum, DelugeIdent* ident, error_t error) {
int len;
char *reply_buf = call ShellCommand.getBuffer(MAX_REPLY_LEN);
if (error == SUCCESS) {
if (ident->uidhash != DELUGE_INVALID_UID) {
len = snprintf(reply_buf, MAX_REPLY_LEN,
"image: %i\n\t[size: %li]\n\t[app: %s]\n\t[user: %s]\n\t[host: %s]\n\t[arch: %s]\n\t[time: 0x%lx]\n",
volumeID2imgNum(imgNum), ident->size, (char *)ident->appname, (char *) ident->username,
(char *)ident->hostname, (char *)ident->platform, (uint32_t)ident->timestamp);
nwprog_validvols++;
call ShellCommand.write(reply_buf, len);
}
}
if (++nwprog_currentvol < DELUGE_NUM_VOLUMES) {
call DelugeMetadata.read(imgNum2volumeId(nwprog_currentvol));
} else {
len = snprintf(reply_buf, MAX_REPLY_LEN,
"%i valid image(s)\n", nwprog_validvols);
call ShellCommand.write(reply_buf, len);
}
}
event void RebootTimer.fired() {
call BootImage.boot(boot_image);
}
event char *ShellCommand.eval(int argc, char **argv) {
if (argc >= 2) {
if (memcmp(argv[1], "list", 4) == 0) {
nwprog_currentvol = 0;
nwprog_validvols = 0;
call DelugeMetadata.read(imgNum2volumeId(nwprog_currentvol));
return NULL;
} else if (memcmp(argv[1], "boot", 4) == 0 && (argc == 3 || argc == 4)) {
uint32_t when = 15;
boot_image = atoi(argv[2]),
boot_image = imgNum2volumeId(boot_image);
if (argc == 4)
when = atoi(argv[3]);
if (when == 0)
call RebootTimer.stop();
else {
char *ack = call ShellCommand.getBuffer(15);
snprintf(ack, 15, "REBOOT %li\n", when);
call RebootTimer.startOneShot(when);
return ack;
}
return NULL;
} else if (memcmp(argv[1], "reboot", 6) == 0) {
call BootImage.reboot();
} else if (memcmp(argv[1], "erase", 5) == 0 && argc == 3) {
uint8_t img = atoi(argv[2]);
img = imgNum2volumeId(img);
return NULL;
}
}
return nwprog_help_str;
}
default command error_t BlockWrite.write[uint8_t imgNum](storage_addr_t addr, void* buf, storage_len_t len) { return FAIL; }
default command error_t BlockWrite.erase[uint8_t imgNum]() { return FAIL; }
default command error_t BlockWrite.sync[uint8_t imgNum]() { return FAIL; }
}
- Previous message: [Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/net/blip/interfaces ICMP.nc, NONE, 1.1 ICMPPing.nc, NONE, 1.1 IP.nc, NONE, 1.1 IPAddress.nc, NONE, 1.1 IPRouting.nc, NONE, 1.1 Statistics.nc, NONE, 1.1 Tcp.nc, NONE, 1.1 UDP.nc, NONE, 1.1
- Next message: [Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/net/blip/serial SerialDevConf.h, NONE, 1.1 SerialDevConfC.nc, NONE, 1.1 SerialPacketInfoDevConfP.nc, NONE, 1.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Tinyos-2-commits
mailing list