Skip to content

Commit 9816a76

Browse files
committed
Add the things needed for the host to the demo.
1 parent bff87c4 commit 9816a76

File tree

15 files changed

+1655
-0
lines changed

15 files changed

+1655
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Morello machine setup
2+
=====================
3+
4+
This directory contains the files that are necessary to set up the Morello machine to act as the server in this demo.
5+
6+
Note: This contains the *private* key used on the server for the demo.
7+
This would allow anyone to impersonate the server.
8+
This does not matter because it is used *only* for the demo, never use this key for anything important!
9+
Including the key here remove the need to generate a new header file for the client portion of the demo.
10+
11+
Pure-capability packages:
12+
13+
minicom
14+
openntpd
15+
16+
Hybrid packages:
17+
18+
bind918
19+
isc-dhcp44-server
20+
jq
21+
npm
22+
wireshark
23+
24+
Built from source:
25+
26+
cheriot-audit (no port yet)
27+
mosquitto (xsltproc is broken and the port's no-docs mode doesn't work).
28+
29+
Make sure to build Release builds (-O0 is *really* slow on Morello, with -O0 Mosquitto can't keep up with two clients on FPGA!).
30+
Install in /opt.
31+
32+
The following lines need to be added to /etc/rc.conf:
33+
34+
# Network interface for the demo
35+
ifconfig_ue0="inet 10.0.0.10 netmask 255.0.0.0"
36+
37+
# DHCP server
38+
dhcpd_enable="YES">->--->--->---# dhcpd enabled?
39+
dhcpd_ifaces="ue0">->--->--->---# ethernet interface(s)
40+
dhcpd_withumask="022">-->--->---# file creation mask
41+
42+
# bind
43+
named_enable="YES"
44+
openntpd_enable="YES"
45+
46+
# Mosquitto
47+
mosquitto_enable="YES"
48+
49+
devfs_enable="YES"
50+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Machine-generated file - use setup menu in minicom to change parameters.
2+
pu baudrate 115200
3+
pu bits 8
4+
pu parity N
5+
pu stopbits 1
6+
pu rtscts No
7+
pu addlinefeed No
8+
pu linewrap Yes
9+
pu addcarreturn Yes
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
3+
if [ $# -eq 0 ] ; then
4+
echo Query required. Try one of the following:
5+
echo Print all connection capabilities:
6+
echo -e \\tdata.network_stack.all_connection_capabilities
7+
echo Is the network stack configuration valid?
8+
echo -e "\\t'data.network_stack.valid(kunyan_ethernet)'"
9+
echo Print all allocator capabilities and their owners:
10+
echo -e "\\t'[ { \"owner\": owner, \"capability\": data.rtos.decode_allocator_capability(c) } | c = input.compartments[owner].imports[_] ; data.rtos.is_allocator_capability(c) ]'"
11+
echo Print all compartments that invoke functions in the JavaScript compartment:
12+
echo -e "\\t'data.compartment.compartments_calling(\"javascript\")'"
13+
echo Print all compartments that invoke functions in the allocator:
14+
echo -e "\\t'data.compartment.compartments_calling(\"allocator\")'"
15+
echo Print all compartments that have direct access to the LEDs / switches:
16+
echo -e "\\t'data.compartment.compartments_with_mmio_import(data.board.devices.gpio_led0)'"
17+
else
18+
echo "cheriot-audit --board ibex-arty-a7-100.json --firmware-report cheritech-demo.json --module network_stack.rego --query \"$1\""
19+
cheriot-audit --board ibex-arty-a7-100.json --firmware-report cheritech-demo.json --module network_stack.rego --query "$1" | jq
20+
fi
21+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// FFI Imports
2+
// Each function imported from the host environment needs to be assigned to a
3+
// global like this and identified by a constant that the resolver in the C/C++
4+
// code will understand.
5+
// These constants are defined in the `Exports` enumeration.
6+
7+
8+
var FFINumber = 1;
9+
10+
/**
11+
* Log function, writes all arguments to the UART.
12+
*/
13+
export const print = vmImport(FFINumber++);
14+
15+
/**
16+
* led_on(index).
17+
*
18+
* Turns on the LED at the specified index.
19+
*/
20+
export const led_on = vmImport(FFINumber++);
21+
22+
/**
23+
* led_off(index).
24+
*
25+
* Turns off the LED at the specified index.
26+
*/
27+
export const led_off = vmImport(FFINumber++);
28+
29+
/**
30+
* buttons_read().
31+
*
32+
* Reads the value of all of the buttons, returning a 4-bit value indicating
33+
* the states of all of them.
34+
*/
35+
export const buttons_read = vmImport(FFINumber++);
36+
37+
/**
38+
* switches_read().
39+
*
40+
* Reads the value of all of the switches, returning a 4-bit value indicating
41+
* the states of all of them.
42+
*/
43+
export const switches_read = vmImport(FFINumber++);
44+
45+
46+
export const mqtt_publish = vmImport(FFINumber++);
47+
export const mqtt_subscribe = vmImport(FFINumber++);
48+
49+
/**
50+
* led_set(index, state).
51+
*
52+
* Turns the LED at the specified index on or off depending on whether state is
53+
* true or false.
54+
*/
55+
export function led_set(index, state)
56+
{
57+
if (state)
58+
{
59+
led_on(index);
60+
}
61+
else
62+
{
63+
led_off(index);
64+
}
65+
}
66+
67+
/**
68+
* button_read(index).
69+
*
70+
* Reads the value of the button at the specified index.
71+
*/
72+
export function button_read(index)
73+
{
74+
return (buttons_read() & (1 << index)) !== 0;
75+
}
76+
77+
78+
/**
79+
* switch_read(index).
80+
*
81+
* Reads the value of the switch at the specified index.
82+
*/
83+
export function switch_read(index)
84+
{
85+
return (switches_read() & (1 << index)) !== 0;
86+
}
87+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
set -e
3+
microvium demo.js
4+
echo Publishing code to MQTT broker
5+
mosquitto_pub -h cheriot.demo -p 8883 --cafile /opt/etc/mosquitto/certs/cert.pem -t cheri-code -f demo.mvm-bc
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import * as host from "./cheri.js"
2+
3+
var ticks = 0
4+
var switches = 0
5+
6+
/**
7+
* Subscribe to a topic, print to the UART whether the subscription was
8+
* successful.
9+
*/
10+
function subscribe(topic)
11+
{
12+
var ret = host.mqtt_subscribe(topic)
13+
host.print("Subscribe ", topic, " returned: ", ret)
14+
if (ret)
15+
{
16+
host.print("Subscribed to", topic)
17+
}
18+
else
19+
{
20+
host.print("Failed to subscribe to ", topic)
21+
}
22+
}
23+
24+
/**
25+
* On first run, subscribe to the switch topics.
26+
*/
27+
function first_run()
28+
{
29+
subscribe("cheri-switch-0")
30+
subscribe("cheri-switch-1")
31+
}
32+
33+
/**
34+
* Tick function, called every 100ms (roughly).
35+
*/
36+
function tick()
37+
{
38+
if (ticks === 0)
39+
{
40+
first_run();
41+
}
42+
ticks++
43+
// If we're not a lightswitch, don't do anything else.
44+
if (host.switch_read(3))
45+
{
46+
return;
47+
}
48+
// If we're not a lightbulb, make sure the lights are out
49+
host.led_off(0)
50+
host.led_off(1)
51+
// Uncomment the next block to validate that the tick callback is being called.
52+
/*
53+
if (ticks % 5 === 0)
54+
{
55+
host.print("tick: ", ticks)
56+
}
57+
*/
58+
var new_switches = host.switches_read()
59+
if (new_switches !== switches)
60+
{
61+
for (var i = 0 ; i < 2 ; i++)
62+
{
63+
if ((new_switches & (1 << i)) !== (switches & (1 << i)))
64+
{
65+
host.print("Switch ", i, " changed to ", (new_switches & (1 << i)) ? "on" : "off")
66+
host.mqtt_publish("cheri-switch-" + i, (new_switches & (1 << i)) ? "on" : "off")
67+
}
68+
}
69+
switches = new_switches
70+
}
71+
}
72+
73+
/**
74+
* Publish notification callback, called whenever a new publish message is
75+
* received from the MQTT broker.
76+
*/
77+
function message(topic, message)
78+
{
79+
host.print("Received message on topic: ", topic, " message: ", message)
80+
var switchNumber = -1
81+
// If we're not a lightbulb, don't do anything else.
82+
if (!host.switch_read(3))
83+
{
84+
return;
85+
}
86+
if (topic === "cheri-switch-0")
87+
{
88+
switchNumber = 0
89+
}
90+
else if (topic === "cheri-switch-1")
91+
{
92+
switchNumber = 1
93+
}
94+
else
95+
{
96+
return
97+
}
98+
if (message === "on")
99+
{
100+
host.led_on(switchNumber)
101+
}
102+
else
103+
{
104+
host.led_off(switchNumber)
105+
}
106+
}
107+
108+
vmExport(1234, tick);
109+
vmExport(1235, message);
1.02 KB
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIBgzCCASmgAwIBAgIUeyRaxt/cqeeZ1JByg4V4shx4lhowCgYIKoZIzj0EAwIw
3+
FzEVMBMGA1UEAwwMY2hlcmlvdC5kZW1vMB4XDTI0MDQwODE0NTcwMVoXDTI1MDQw
4+
ODE0NTcwMVowFzEVMBMGA1UEAwwMY2hlcmlvdC5kZW1vMFkwEwYHKoZIzj0CAQYI
5+
KoZIzj0DAQcDQgAE2zq+r59p+QKkoKdBguXxBl4KoX5DYb6gHyI9Wrn7o4bz8rNZ
6+
4JPG4J+mIlEQKv9eIJYn1owIWQ5YbKaHpZqWAqNTMFEwHQYDVR0OBBYEFBdDvYEz
7+
T9pLdHbNwBVFT9wwQGVdMB8GA1UdIwQYMBaAFBdDvYEzT9pLdHbNwBVFT9wwQGVd
8+
MA8GA1UdEwEB/wQFMAMBAf8wCgYIKoZIzj0EAwIDSAAwRQIgb2epifZyBtLofZsk
9+
gs5HqfpKuiMijfe3Q+H7ETP3aIwCIQDYBIR7uQ4s24mK3dcj+u5Qc6gSr/WuBZGO
10+
xzxrtzDGTw==
11+
-----END CERTIFICATE-----
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgFF2t/aeGHzLHsP4k
3+
63Q9yIFLeU8+mtOylWjhfwwQbNihRANCAATbOr6vn2n5AqSgp0GC5fEGXgqhfkNh
4+
vqAfIj1aufujhvPys1ngk8bgn6YiURAq/14glifWjAhZDlhspoelmpYC
5+
-----END PRIVATE KEY-----

0 commit comments

Comments
 (0)