Skip to content

Commit 96c4cb6

Browse files
committed
Update RoT before SP so it is ready to measure SP when SP resets.
Fix `json_to_map()` so that JSON errors are reported properly. Some calls to `print()` change to logging to debug or info. Add configuration for `faux-ipcc`. - since system() needs to be used to run faux-ipcc, should there be a regex to parse or are Rhai's existing string functions sufficient to pull out certs and measurements? Since faux-ipcc doesn't handle attestations yet, we'll wait a bit.
1 parent 370c141 commit 96c4cb6

File tree

5 files changed

+82
-56
lines changed

5 files changed

+82
-56
lines changed

faux-mgs/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,5 @@ thiserror = { workspace = true, optional = true }
4444
toml = { workspace = true, optional = true }
4545

4646
[features]
47-
# XXX remove rhaiscript as a defailt feature
4847
default = ["rhaiscript"]
4948
rhaiscript = [ "dep:async-recursion", "dep:hubtools", "dep:lpc55_areas", "dep:lpc55_sign", "dep:rhai", "dep:rhai-chrono", "dep:rhai-env", "dep:rhai-fs", "dep:thiserror", "dep:toml"]

faux-mgs/src/rhaiscript.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,12 +334,11 @@ pub async fn interpreter(
334334
})
335335
// Offer proper JSON to Dynamic::Map conversion
336336
.register_fn("json_to_map", move |v: Dynamic| -> Dynamic {
337-
match v.into_string() {
337+
match v.clone().into_string() {
338338
Ok(s) => match serde_json::from_str::<Dynamic>(&s) {
339339
Ok(v) => v,
340340
Err(e) => {
341-
let err = format!("{{\"error\": \"{:?}\"}}", e)
342-
.to_string();
341+
let err = json!(e.to_string()).to_string();
343342
serde_json::from_str::<Dynamic>(&err).unwrap()
344343
}
345344
},

scripts/targets.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@
2626
"rot_b": "${ut_repo}/target/${bord.rot}/dist/b/build-${bord.rot}-image-b.zip",
2727
"stage0": "${keyset-dvt-dock}/gimlet/bootleby-${ut-b-ver}-${keyset}-gimlet.zip"
2828
}
29+
},
30+
31+
"ipcc": {
32+
"faux_ipcc": "${HOME}/.cargo/bin/faux-ipcc",
33+
"port": "/dev/ttyUSB0"
2934
}
3035
}

scripts/upgrade-rollback.rhai

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
// Display start time
1717
let start_ts = timestamp();
1818
let start_time = datetime_local();
19-
print(`Starting at ${start_time}`);
19+
debug(`info|Starting at ${start_time}`);
2020

2121
let conf = process_cli(argv);
2222
switch type_of(conf) {
@@ -58,7 +58,7 @@ fn main() {
5858
print(`The SP probably needs to be reset before continuing`);
5959
print(`Trying to abort the update with id=${id}`);
6060
let r = faux_mgs(["update-abort", component, `${id}`]);
61-
debug(`update-abort = ${r}`);
61+
debug(`info|update-abort = ${r}`);
6262
}
6363
}
6464
if problems == 0 {
@@ -107,7 +107,7 @@ fn main() {
107107
}
108108

109109
// Update RoT with baseline image
110-
debug(`Flash baseline rot hubris`);
110+
debug(`info|Flash baseline rot hubris`);
111111
if flash_rot && !update_rot_hubris(conf.base.rot_a, conf.base.rot_b) {
112112
return 1
113113
}
@@ -120,7 +120,7 @@ fn main() {
120120
let result = image_check("base", images);
121121
if result?.error != () || result.ok.sp || result.ok.rot {
122122
// Not able to check images or one or both base images not installed.
123-
debug(`image_check error or failed BASE image updates: ${result}`);
123+
debug(`warn|image_check error or failed BASE image updates: ${result}`);
124124
return 1;
125125
}
126126
}
@@ -145,21 +145,24 @@ fn main() {
145145
}
146146
] {
147147
print("");
148+
149+
debug(`info|${v.up_down} Rot Hubris to ${v.label} image`);
150+
if !update_rot_hubris(v.rot_a_path, v.rot_b_path) {
151+
debug(`error|Failed to ${v.up_down} RoT Hubris to ${v.label} image: ${r}`);
152+
return 1
153+
}
154+
148155
print(`## ${v.up_down} to ${v.label} images`);
149-
debug(`${v.up_down} SP Hubris to ${v.label} image`);
156+
debug(`info|${v.up_down} SP Hubris to ${v.label} image`);
150157
if !update_sp(v.sp_path) {
151-
print(`Failed to ${v.up_down} SP Hubris to ${v.label} image: ${r}`);
158+
debug(`error|Failed to ${v.up_down} SP Hubris to ${v.label} image: ${r}`);
152159
return 1;
153160
}
154-
debug(`${v.up_down} Rot Hubris to ${v.label} image`);
155-
if !update_rot_hubris(v.rot_a_path, v.rot_b_path) {
156-
print(`Failed to ${v.up_down} RoT Hubris to ${v.label} image: ${r}`);
157-
return 1
158-
}
161+
159162
let result = image_check(v.branch, images);
160163
if result?.error != () || result.ok.sp || result.ok.rot {
161164
// Not able to check images or one or both ${branch} images not installed.
162-
debug(`image_check error or failed ${label} image updates: ${result}`);
165+
debug(`error|image_check error or failed ${label} image updates: ${result}`);
163166
return 1;
164167
}
165168
print(`### SUCCESS: ${v.up_down} to SP and RoT ${v.label} images`);
@@ -242,15 +245,37 @@ fn process_cli(argv) {
242245
print(`No configuration for image ${branch}.${image}`);
243246
} else {
244247
conf[branch][image] = zip_path;
245-
debug(`conf.${branch}.${image}=${zip_path}`);
248+
debug(`info|conf.${branch}.${image}=${zip_path}`);
246249
}
247250
};
248251
}
249252

253+
// If ipcc has been specified, then include that as well
254+
let faux_ipcc_path = config?.ipcc?.faux_ipcc;
255+
let x = 1;
256+
let a = if x == 2 {
257+
3
258+
} else {
259+
4
260+
};
261+
print(x);
262+
conf.ipcc = if faux_ipcc_path != () {
263+
#{
264+
"use_ipcc": true,
265+
"faux_ipcc": util::env_expand(config.ipcc.faux_ipcc, config),
266+
"port": util::env_expand(config.ipcc?.port, config),
267+
}
268+
} else {
269+
#{
270+
"use_ipcc": false,
271+
}
272+
};
273+
250274
if conf.verbose {
251275
print("");
252276
print(`Parsed conf=${conf}`);
253277
}
278+
254279
conf
255280
}
256281

@@ -350,7 +375,7 @@ fn check_update_in_progress(component) {
350375
let r = faux_mgs(["update-status", component]);
351376
debug(`update_status(${component})=${r}`);
352377
if r?.Err != () {
353-
debug(`failed update-status: ${r}`);
378+
debug(`error|failed update-status: ${r}`);
354379
return r;
355380
}
356381
if r?.Ok == "None" {
@@ -374,7 +399,7 @@ fn check_update_in_progress(component) {
374399
"id": util::to_hexstring(r.Complete),
375400
};
376401
}
377-
debug(`update-status: ${r}`);
402+
debug(`error|update-status: ${r}`);
378403
return #{"Err": `unknown update-status: ${r}`};
379404
}
380405

@@ -388,7 +413,7 @@ fn update_sp(sp_zip) {
388413
if r?.ack == "updated" {
389414
print("flash_sp updated");
390415
} else {
391-
debug("#### FAILED flash_sp update");
416+
debug("error|#### FAILED flash_sp update");
392417
print("FAIL\n");
393418
return false;
394419
}
@@ -404,7 +429,7 @@ fn update_sp(sp_zip) {
404429
let r = faux_mgs(["component-active-slot", "--persist", "-s", "0", "sp"]);
405430
debug(`persist result = ${r}`);
406431
if r?["ack"] == () || r.ack != "set" || r.slot != 0 {
407-
debug("Failed to persist");
432+
debug("error|Failed to persist");
408433
print("FAIL\n");
409434
return false;
410435
}
@@ -414,7 +439,7 @@ fn update_sp(sp_zip) {
414439
let r = faux_mgs(["reset"]);
415440
debug(`faux-mgs reset => ${r}`);
416441
if r?.ack != "reset" {
417-
debug(`unexpected sp reset response: ${r}`);
442+
debug(`warn|unexpected sp reset response: ${r}`);
418443
print("FAIL\n");
419444
return false;
420445
}
@@ -463,13 +488,13 @@ fn update_rot_hubris(path_a, path_b) {
463488
let r = faux_mgs(["component-active-slot", "-p", "-s", `${rot_update_slot}`, "rot"]);
464489
debug(`persist result = ${r}`);
465490
if r?.ack == () || r.ack != "set" || r.slot != rot_update_slot {
466-
debug(`Failed to persist rot: r=${r}`);
491+
debug(`error|Failed to persist rot: r=${r}`);
467492
print("");
468493
return false;
469494
}
470495
let r = faux_mgs(["reset-component", "rot"]);
471496
if r?.ack != "reset" {
472-
debug(`reset failed: ${r}`);
497+
debug(`error|reset failed: ${r}`);
473498
print("");
474499
return false;
475500
}
@@ -535,7 +560,7 @@ fn image_check(branch, images) {
535560

536561
let need_flash = rot_needs_flashing(`${branch}`, images.by_gitc);
537562
if need_flash?.error != () {
538-
debug(`Error: ${need_flash}`);
563+
debug(`error|${need_flash}`);
539564
error["rot"] = `${flash_rot}`;
540565
} else {
541566
ok["rot"] = need_flash.ok;
@@ -583,13 +608,13 @@ fn rot_needs_flashing(branch, gitc) {
583608
debug(`gitc[${rot_gitc}]=${gitc?[rot_gitc]}`);
584609
let known_gitc = gitc?[rot_gitc];
585610
if known_gitc == () {
586-
print(" the RoT is not running a BASE or UNDER-TEST image.");
611+
debug("info|the RoT is not running a BASE or UNDER-TEST image.");
587612
#{"ok": true}
588613
} else if branch_rot_name in known_gitc {
589-
debug(`${branch_rot_name} IS in ${known_gitc}`);
614+
debug(`info|${branch_rot_name} IS in ${known_gitc}`);
590615
#{"ok": false}
591616
} else {
592-
debug(`${branch_rot_name} IS NOT in ${known_gitc}`);
617+
debug(`info|${branch_rot_name} IS NOT in ${known_gitc}`);
593618
#{"ok": true}
594619
}
595620
}

scripts/util.rhai

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
/// Print out commonly available environment variables to demonstrate
77
/// the env_expand function.
88
fn show_env() {
9-
print(`cwd=${cwd().to_string()}`);
10-
print("Common environment variables:");
11-
print(` ${env_expand("PWD=${PWD}", #{})}`);
12-
print(` ${env_expand("HOME=${HOME}", #{})}`);
13-
print(` ${env_expand("LOGNAME=${LOGNAME}", #{})}`);
14-
print(` ${env_expand("SHELL=${SHELL}", #{})}`);
15-
print(` ${env_expand("USER=${USER}", #{})}`);
9+
debug(`info|cwd=${cwd().to_string()}`);
10+
debug("info|Common environment variables:");
11+
debug(`info| ${env_expand("PWD=${PWD}", #{})}`);
12+
debug(`info| ${env_expand("HOME=${HOME}", #{})}`);
13+
debug(`info| ${env_expand("LOGNAME=${LOGNAME}", #{})}`);
14+
debug(`info| ${env_expand("SHELL=${SHELL}", #{})}`);
15+
debug(`info| ${env_expand("USER=${USER}", #{})}`);
1616
}
1717

1818
// Reformat a byte array as a hex byte string representation.
@@ -65,7 +65,7 @@ fn ab_to_01(v) {
6565
// For no override, use #{} in place of the override map.
6666
fn env_expand(s, override) {
6767
if s == () {
68-
print!("Warning: trying to expand ()");
68+
debug("error|Warning: trying to expand ()");
6969
return ();
7070
}
7171
// Note: Using an ImmutableString when there are usually
@@ -78,7 +78,7 @@ fn env_expand(s, override) {
7878
let envmap = envs();
7979
while remain.len() > 0 {
8080
if out.len() > 2048 {
81-
print(`env_expand error: out.len() has reached ${out.len()}`);
81+
debug(`error|env_expand error: out.len() has reached ${out.len()}`);
8282
return ();
8383
}
8484
let i = remain.index_of("${");
@@ -109,17 +109,17 @@ fn env_expand(s, override) {
109109
key = key[dot+1..];
110110
vars = vars?[topkey];
111111
if vars == () {
112-
print("Error: env_expand: out of vars!");
113-
print(`Expansion of "${s}" is "${out}" with remainder "${remain}"`);
112+
debug("error|env_expand: out of vars!");
113+
debug(`error|Expansion of "${s}" is "${out}" with remainder "${remain}"`);
114114
return ();
115115
}
116116
dot = key.index_of(".");
117117
}
118118
if key in vars {
119119
value = vars[key];
120120
} else {
121-
print(`Cannot expand ${orig_key}`);
122-
print(`Expansion of "${s}" is "${out}" with remainder "${remain}"`);
121+
debug(`error|Cannot expand ${orig_key}`);
122+
debug(`error|Expansion of "${s}" is "${out}" with remainder "${remain}"`);
123123
}
124124
} else {
125125
// No dot in key, top-level from `override` or
@@ -130,8 +130,8 @@ fn env_expand(s, override) {
130130
value = env(key);
131131
} else {
132132
// TODO: tie into faux-mgs logging
133-
print(`Cannot expand ${key}`);
134-
print(`Expansion of "${s}" is "${out}" with remainder "${remain}"`);
133+
debug(`error|Cannot expand ${key}`);
134+
debug(`error|Expansion of "${s}" is "${out}" with remainder "${remain}"`);
135135
return ()
136136
}
137137
}
@@ -145,8 +145,6 @@ fn env_expand(s, override) {
145145
/// Make RotBootInfoV3 more rhai friendly.
146146
fn rot_boot_info() {
147147
let r = faux_mgs(["rot-boot-info", "--version", "3"]);
148-
// print(`RESULTS: ${type_of(r)}:`);
149-
// print(`${r}`);
150148
if r.V3?.active == () {
151149
return (#{})
152150
}
@@ -200,19 +198,19 @@ fn caboose_value(component, slot, key) {
200198

201199
// Connect though the SP to get caboose values for all RoT and SP images.
202200
fn get_device_cabooses() {
203-
let caboose = #{};
204-
for component in ["stage0", "rot", "sp"] {
201+
let caboose = #{};
202+
for component in ["stage0", "rot", "sp"] {
205203
for slot in ["0", "1"] {
206-
if (component in caboose) == false {
207-
caboose[component] = #{};
204+
if (component in caboose) == false {
205+
caboose[component] = #{};
206+
}
207+
if (slot in caboose[component]) == false {
208+
caboose[component][slot] = #{};
209+
}
210+
caboose[component][slot] = get_caboose(component, slot);
208211
}
209-
if (slot in caboose[component]) == false {
210-
caboose[component][slot] = #{};
211-
}
212-
caboose[component][slot] = get_caboose(component, slot);
213-
}
214-
}
215-
caboose
212+
}
213+
caboose
216214
}
217215

218216
// Translate the LPC55's Root Key Table Hash to a well-known keyset name or

0 commit comments

Comments
 (0)