Commit 83ac1505 authored by Simon Duquennoy's avatar Simon Duquennoy Committed by GitHub
Browse files

Merge pull request #112 from sics-iot/cooja

Cooja as a submodule
parents e0f843dc 4c16ce9a
......@@ -19,22 +19,14 @@ tools/tunslip
tools/tunslip6
build
tools/coffee-manager/build/
tools/cooja/dist/
tools/coffee-manager/coffee.jar
tools/collect-view/build/
tools/collect-view/dist/
COOJA.testlog
tools/cooja/apps/mrm/lib/
tools/cooja/apps/mspsim/lib/
tools/cooja/apps/powertracker/lib/
tools/cooja/apps/serial_socket/lib/
tools/coffee-manager/coffee.jar
tools/cooja/apps/avrora/lib/cooja_avrora.jar
tools/cooja/apps/collect-view/cooja-collect-view.jar
# platform build artifacts
*.cc2538dk
*.cooja
*.cooja-ip64
*.jn516x
*.native
*.nrf52dk
......@@ -46,7 +38,6 @@ tools/cooja/apps/collect-view/cooja-collect-view.jar
# do not ignore platform makefiles
!Makefile.cc2538dk
!Makefile.cooja
!Makefile.cooja-ip64
!Makefile.jn516x
!Makefile.native
!Makefile.nrf52dk
......
[submodule "tools/mspsim"]
path = tools/mspsim
url = https://github.com/mspsim/mspsim.git
[submodule "tools/cc2538-bsl"]
path = tools/cc2538-bsl
url = https://github.com/JelmerT/cc2538-bsl.git
......@@ -13,3 +10,6 @@
[submodule "tools/sensniff"]
path = tools/sensniff
url = https://github.com/g-oikonomou/sensniff.git
[submodule "tools/cooja"]
path = tools/cooja
url = https://github.com/sics-iot/cooja.git
# $Id: Makefile.msp430,v 1.35 2011/01/19 07:30:31 adamdunkels Exp $
COOJA_PATH ?= $(CONTIKI)/tools/cooja
ifdef nodeid
CFLAGS += -DNODEID=$(nodeid)
endif
......@@ -215,19 +217,24 @@ else
$(OBJCOPY) $^ -O ihex $@
endif
$(CONTIKI)/tools/mspsim/build.xml:
$(COOJA_PATH)/build.xml:
@echo '----------------'
@echo 'Could not find the COOJA build file. Did you run "git submodule update --init --recursive"?'
@echo '----------------'
$(COOJA_PATH)/mspsim/build.xml: $(COOJA_PATH)/build.xml
@echo '----------------'
@echo 'Could not find the MSPSim build file. Did you run "git submodule update --init"?'
@echo 'Could not find the MSPSim build file. Did you run "git submodule update --init --recursive"?'
@echo '----------------'
$(CONTIKI)/tools/mspsim/mspsim.jar: $(CONTIKI)/tools/mspsim/build.xml
(cd $(CONTIKI)/tools/mspsim && ant jar)
$(COOJA_PATH)/mspsim/mspsim.jar: $(COOJA_PATH)/mspsim/build.xml
(cd $(COOJA_PATH)/mspsim && ant jar)
%.mspsim: %.${TARGET} ${CONTIKI}/tools/mspsim/mspsim.jar
java -jar ${CONTIKI}/tools/mspsim/mspsim.jar -platform=${TARGET} $<
%.mspsim: %.${TARGET} ${COOJA_PATH}/mspsim/mspsim.jar
java -jar ${COOJA_PATH}/mspsim/mspsim.jar -platform=${TARGET} $<
mspsim-maptable: contiki-${TARGET}.map
java -classpath ${CONTIKI}/tools/mspsim/mspsim.jar se.sics.mspsim.util.MapTable $<
java -classpath ${COOJA_PATH}/mspsim/mspsim.jar se.sics.mspsim.util.MapTable $<
core-labels.o: core.${TARGET}
${CONTIKI}/tools/msp430-make-labels core.${TARGET} > core-labels.S
......
Subproject commit a45e22071a2b84cb0e0b037c289e30661053dce1
<?xml version="1.0"?>
<project name="Avrora COOJA support" default="jar" basedir=".">
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="lib" location="lib"/>
<property name="javadoc" location="javadoc"/>
<property name="cooja" location="../.."/>
<property name="cooja_jar" value="${cooja}/dist/cooja.jar"/>
<property name="avrora_jar" value="${lib}/avrora-small.jar"/>
<property name="cooja_avrora_jar" value="${lib}/cooja_avrora.jar"/>
<target name="init">
<tstamp/>
<mkdir dir="${build}"/>
<mkdir dir="${lib}"/>
</target>
<target name="clean">
<delete dir="${build}"/>
<delete file="${cooja_avrora_jar}"/>
</target>
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${build}" debug="on"
includeantruntime="false">
<classpath>
<pathelement location="${avrora_jar}"/>
<pathelement location="${cooja_jar}"/>
<pathelement location="${cooja}/apps/mspsim/build"/>
</classpath>
</javac>
</target>
<target name="javadoc" depends="compile">
<delete dir="${javadoc}" quiet="true"/>
<mkdir dir="${javadoc}/"/>
<javadoc destdir="${javadoc}">
<fileset dir="${src}/" includes="**/*.java"/>
<classpath>
<pathelement location="${avrora_jar}"/>
<pathelement location="${cooja_jar}"/>
</classpath>
</javadoc>
</target>
<target name="jar" depends="init, compile">
<jar destfile="${cooja_avrora_jar}" basedir="${build}">
<manifest>
<attribute name="Class-Path" value="."/>
</manifest>
</jar>
</target>
</project>
org.contikios.cooja.Cooja.MOTETYPES = + org.contikios.cooja.avrmote.MicaZMoteType
org.contikios.cooja.Cooja.JARFILES = + cooja_avrora.jar avrora-small.jar
/*
* Copyright (c) 2014, TU Braunschweig. All rights reserved.
* Copyright (c) 2009, Swedish Institute of Computer Science. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer. 2. Redistributions in
* binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution. 3. Neither the name of the
* Institute nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 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.
*
*/
package org.contikios.cooja.avrmote;
import org.apache.log4j.Logger;
import avrora.arch.avr.AVRProperties;
import avrora.core.SourceMapping;
import avrora.core.SourceMapping.Location;
import avrora.sim.AtmelInterpreter;
import avrora.sim.Simulator.Watch;
import avrora.sim.State;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.contikios.cooja.mote.memory.MemoryInterface;
import org.contikios.cooja.mote.memory.MemoryInterface.SegmentMonitor.EventType;
import org.contikios.cooja.mote.memory.MemoryLayout;
/**
* @author Joakim Eriksson, Fredrik Osterlind, David Kopf, Enrico Jorns
*/
public class AvrMoteMemory implements MemoryInterface {
private static Logger logger = Logger.getLogger(AvrMoteMemory.class);
private static final boolean DEBUG = logger.isDebugEnabled();
private final SourceMapping memoryMap;
private final AVRProperties avrProperties;
private final AtmelInterpreter interpreter;
private final ArrayList<AvrByteMonitor> memoryMonitors = new ArrayList<>();
private final MemoryLayout memLayout = new MemoryLayout(ByteOrder.LITTLE_ENDIAN, MemoryLayout.ARCH_8BIT, 2);
private boolean coojaIsAccessingMemory;
public AvrMoteMemory(SourceMapping map, AVRProperties avrProperties, AtmelInterpreter interpreter) {
memoryMap = map;
this.interpreter = interpreter;
this.avrProperties = avrProperties;
}
@Override
public int getTotalSize() {
return avrProperties.sram_size;
}
@Override
public byte[] getMemory() throws MoteMemoryException {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public byte[] getMemorySegment(long address, int size) throws MoteMemoryException {
/*logger.info("getMemorySegment(" + String.format("0x%04x", address) +
", " + size + ")");*/
if (!accessInRange(address, size)) {
throw new MoteMemoryException(
"Getting memory segment [0x%x,0x%x] failed: Out of range",
address, address + size - 1);
}
/* XXX Unsure whether this is the appropriate method to use, as it
* triggers memoryRead monitor. Right now I'm using a flag to indicate
* that Cooja (as opposed to Contiki) read the memory, to avoid infinite
* recursion. */
coojaIsAccessingMemory = true;
byte[] data = new byte[(int) size];
for (int i = 0; i < size; i++) {
data[i] = (byte) (interpreter.getDataByte((int) address + i) & 0xff);
}
coojaIsAccessingMemory = false;
return data;
}
@Override
public void setMemorySegment(long address, byte[] data) throws MoteMemoryException {
if (!accessInRange(address, data.length)) {
throw new MoteMemoryException(
"Writing memory segment [0x%x,0x%x] failed: Out of range",
address, address + data.length - 1);
}
/* XXX See comment in getMemorySegment. */
coojaIsAccessingMemory = true;
for (int i = 0; i < data.length; i++) {
interpreter.writeDataByte((int) address + i, data[i]);
}
coojaIsAccessingMemory = false;
if (DEBUG) {
logger.debug(String.format(
"Wrote memory segment [0x%x,0x%x]",
address, address + data.length - 1));
}
}
@Override
public void clearMemory() {
setMemorySegment(0L, new byte[avrProperties.sram_size]);
}
private boolean accessInRange(long address, int size) {
return (address >= 0) && (address + size <= avrProperties.sram_size);
}
@Override
public long getStartAddr() {
return 0;// XXX
}
@Override
public Map<String, Symbol> getSymbolMap() {
// XXX do not fetch in function!
Map<String, Symbol> symbols = new HashMap<>();
for (Iterator<Location> iter = memoryMap.getIterator(); iter.hasNext();) {
Location loc = iter.next();
if (loc == null || (loc.section.equals(".text"))) {
continue;
}
symbols.put(loc.name, new Symbol(Symbol.Type.VARIABLE, loc.name, loc.section, loc.vma_addr & 0x7fffff, -1));
}
return symbols;
}
@Override
public MemoryLayout getLayout() {
return memLayout;
}
class AvrByteMonitor extends Watch.Empty {
/** start address to monitor */
final long address;
/** size to monitor */
final int size;
/** Segment monitor to notify */
final SegmentMonitor mm;
/** MonitorType we are listening to */
final EventType flag;
public AvrByteMonitor(long address, int size, SegmentMonitor mm, EventType flag) {
this.address = address;
this.size = size;
this.mm = mm;
this.flag = flag;
}
@Override
public void fireAfterRead(State state, int data_addr, byte value) {
if (flag == EventType.WRITE || coojaIsAccessingMemory) {
return;
}
mm.memoryChanged(AvrMoteMemory.this, EventType.READ, data_addr);
}
@Override
public void fireAfterWrite(State state, int data_addr, byte value) {
if (flag == EventType.READ || coojaIsAccessingMemory) {
return;
}
mm.memoryChanged(AvrMoteMemory.this, EventType.WRITE, data_addr);
}
}
@Override
public boolean addSegmentMonitor(EventType flag, long address, int size, SegmentMonitor mm) {
AvrByteMonitor mon = new AvrByteMonitor(address, size, mm, flag);
memoryMonitors.add(mon);
/* logger.debug("Added AvrByteMonitor " + Integer.toString(mon.hashCode()) + " for addr " + mon.address + " size " + mon.size + " with watch" + mon.watch); */
/* Add byte monitor (watch) for every byte in range */
for (int idx = 0; idx < mon.size; idx++) {
interpreter.getSimulator().insertWatch(mon, (int) mon.address + idx);
/* logger.debug("Inserted watch " + Integer.toString(mon.watch.hashCode()) + " for " + (mon.address + idx)); */
}
return true;
}
@Override
public boolean removeSegmentMonitor(long address, int size, SegmentMonitor mm) {
for (AvrByteMonitor mcm : memoryMonitors) {
if (mcm.mm != mm || mcm.address != address || mcm.size != size) {
continue;
}
for (int idx = 0; idx < mcm.size; idx++) {
interpreter.getSimulator().removeWatch(mcm, (int) mcm.address + idx);
/* logger.debug("Removed watch " + Integer.toString(mcm.watch.hashCode()) + " for " + (mcm.address + idx)); */
}
memoryMonitors.remove(mcm);
return true;
}
return false;
}
}
/*
* Copyright (c) 2012, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* 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.
*/
package org.contikios.cooja.avrmote;
import java.awt.Container;
import java.io.File;
import org.apache.log4j.Logger;
import org.contikios.cooja.Cooja;
import org.contikios.cooja.MoteInterface;
import org.contikios.cooja.MoteType;
import org.contikios.cooja.Simulation;
import org.contikios.cooja.dialogs.AbstractCompileDialog;
public class MicaZCompileDialog extends AbstractCompileDialog {
private static Logger logger = Logger.getLogger(MicaZCompileDialog.class);
public static boolean showDialog(
Container parent,
Simulation simulation,
MoteType moteType) {
final AbstractCompileDialog dialog = new MicaZCompileDialog(parent, simulation, moteType);
/* Show dialog and wait for user */
dialog.setVisible(true); /* BLOCKS */
if (!dialog.createdOK()) {
return false;
}
/* Assume that if a firmware exists, compilation was ok */
return true;
}
private MicaZCompileDialog(Container parent, Simulation simulation, MoteType moteType) {
super(parent, simulation, moteType);
}
public Class<? extends MoteInterface>[] getAllMoteInterfaces() {
return ((MicaZMoteType)moteType).getAllMoteInterfaceClasses();
}
public Class<? extends MoteInterface>[] getDefaultMoteInterfaces() {
return ((MicaZMoteType)moteType).getAllMoteInterfaceClasses();
}
public boolean canLoadFirmware(File file) {
if (file.getName().endsWith(".elf")) {
return true;
}
return false;
}
public String getDefaultCompileCommands(File source) {
/* TODO Split into String[] */
return
/*"make clean TARGET=micaz\n" + */
Cooja.getExternalToolsSetting("PATH_MAKE") + " " + getExpectedFirmwareFile(source).getName() + " TARGET=micaz";
}
public File getExpectedFirmwareFile(File source) {
return ((MicaZMoteType)moteType).getExpectedFirmwareFile(source);
}
public void writeSettingsToMoteType() {
/* Nothing to do */
}
protected String getTargetName() {
return "micaz";
}
}
/*
* Copyright (c) 2007, Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE 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 INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* 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.
*
*/
package org.contikios.cooja.avrmote;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.log4j.Logger;
import org.jdom.Element;
import org.contikios.cooja.Mote;
import org.contikios.cooja.MoteInterface;
import org.contikios.cooja.MoteInterfaceHandler;
import org.contikios.cooja.MoteType;
import org.contikios.cooja.Simulation;
import org.contikios.cooja.mote.memory.MemoryInterface;
import org.contikios.cooja.motes.AbstractEmulatedMote;
import avrora.arch.avr.AVRProperties;
import avrora.core.LoadableProgram;
import avrora.sim.AtmelInterpreter;
import avrora.sim.Simulator;
import avrora.sim.State;
import avrora.sim.mcu.AtmelMicrocontroller;
import avrora.sim.mcu.EEPROM;
import avrora.sim.platform.MicaZ;
import avrora.sim.platform.PlatformFactory;
import org.contikios.cooja.avrmote.interfaces.MicaClock;
/**
* @author Joakim Eriksson, Fredrik Osterlind
*/
public class MicaZMote extends AbstractEmulatedMote implements Mote {
private static Logger logger = Logger.getLogger(MicaZMote.class);
/* 8 MHz according to Contiki config */
public static long NR_CYCLES_PER_MSEC = 8000;
private MoteInterfaceHandler myMoteInterfaceHandler;
private AtmelMicrocontroller myCpu = null;
private MicaZ micaZ = null;
private LoadableProgram program = null;
private AtmelInterpreter interpreter = null;
private AvrMoteMemory myMemory = null;
private AVRProperties avrProperties = null;
private MicaZMoteType myMoteType = null;
private EEPROM eeprom = null;
private long executed = 0;
private long skipped = 0;
/* Stack monitoring variables */
private boolean stopNextInstruction = false;
public MicaZMote() {
myMoteType = null;
myCpu = null;
/* TODO myMemory = null; */
myMoteInterfaceHandler = null;
}
public MicaZMote(Simulation simulation, MicaZMoteType type) {
setSimulation(simulation);
myMoteType = type;
/* Schedule us immediately */
requestImmediateWakeup();
}
protected boolean initEmulator(File fileELF) {
try {
prepareMote(fileELF);
} catch (Exception e) {
logger.fatal("Error when creating MicaZ mote: ", e);
return false;
}
return true;
}