mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-21 09:14:34 +00:00
Merge branch 'main' into bunnie-dev
This commit is contained in:
commit
5d59390554
15 changed files with 399 additions and 43 deletions
37
.github/workflows/build.yml
vendored
Normal file
37
.github/workflows/build.yml
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
name: Build xous-core
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Setup Rust
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
task: ["hosted-ci", "renode-image"]
|
||||
steps:
|
||||
- name: Install Ubuntu dependencies
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install -y libxkbcommon-dev
|
||||
|
||||
- name: Install stable toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: "1.59.0"
|
||||
default: true
|
||||
|
||||
- name: Checkout sources
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- uses: Swatinem/rust-cache@v1
|
||||
|
||||
- name: Install RISC-V toolkit
|
||||
run: cargo xtask install-toolkit --force
|
||||
|
||||
- name: Build hosted-ci
|
||||
run: cargo xtask ${{ matrix.task }}
|
||||
17
Cargo.lock
generated
17
Cargo.lock
generated
|
|
@ -1029,6 +1029,23 @@ dependencies = [
|
|||
"xous-names",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hello"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"gam",
|
||||
"graphics-server",
|
||||
"locales",
|
||||
"log",
|
||||
"log-server",
|
||||
"num-derive",
|
||||
"num-traits",
|
||||
"tts-frontend",
|
||||
"xous",
|
||||
"xous-ipc 0.9.7",
|
||||
"xous-names",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.18"
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ default-members = [
|
|||
"services/dns",
|
||||
"services/modals",
|
||||
"apps/ball",
|
||||
"apps/hello",
|
||||
"apps/repl",
|
||||
]
|
||||
members = [
|
||||
|
|
@ -88,6 +89,7 @@ members = [
|
|||
"services/dns",
|
||||
"services/modals",
|
||||
"apps/ball",
|
||||
"apps/hello",
|
||||
"apps/repl",
|
||||
"services/libstd-test",
|
||||
"services/ffi-test",
|
||||
|
|
|
|||
21
apps/hello/Cargo.toml
Normal file
21
apps/hello/Cargo.toml
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
[package]
|
||||
name = "hello"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4.14"
|
||||
num-derive = {version = "0.3.3", default-features = false}
|
||||
num-traits = {version = "0.2.14", default-features = false}
|
||||
xous = { path = "../../xous-rs" }
|
||||
xous-ipc = { path = "../../xous-ipc" }
|
||||
log-server = { path = "../../services/log-server" }
|
||||
xous-names = { path = "../../services/xous-names" }
|
||||
gam = {path = "../../services/gam" }
|
||||
graphics-server = {path = "../../services/graphics-server" }
|
||||
locales = {path = "../../locales"}
|
||||
tts-frontend = {path="../../services/tts"}
|
||||
|
||||
[features]
|
||||
tts = []
|
||||
default = []
|
||||
8
apps/hello/locales/i18n.json
Normal file
8
apps/hello/locales/i18n.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"helloworld.hello": {
|
||||
"en": "Hello World!",
|
||||
"ja": "Hello World!",
|
||||
"zh": "大家好!",
|
||||
"en-tts": "Hello World!"
|
||||
}
|
||||
}
|
||||
155
apps/hello/src/main.rs
Normal file
155
apps/hello/src/main.rs
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
#![cfg_attr(target_os = "none", no_std)]
|
||||
#![cfg_attr(target_os = "none", no_main)]
|
||||
|
||||
use core::fmt::Write;
|
||||
use graphics_server::api::GlyphStyle;
|
||||
use graphics_server::{DrawStyle, Gid, PixelColor, Point, Rectangle, TextBounds, TextView};
|
||||
use num_traits::*;
|
||||
use locales::t;
|
||||
#[cfg(feature = "tts")]
|
||||
use tts_frontend::*;
|
||||
|
||||
/// Basic 'Hello World!' application that draws a simple
|
||||
/// TextView to the screen.
|
||||
|
||||
pub(crate) const SERVER_NAME_HELLO: &str = "_Hello World_";
|
||||
|
||||
/// Top level application events.
|
||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||
pub(crate) enum HelloOp {
|
||||
/// Redraw the screen
|
||||
Redraw = 0,
|
||||
|
||||
/// Quit the application
|
||||
Quit,
|
||||
}
|
||||
|
||||
struct Hello {
|
||||
content: Gid,
|
||||
gam: gam::Gam,
|
||||
_gam_token: [u32; 4],
|
||||
screensize: Point,
|
||||
#[cfg(feature = "tts")]
|
||||
tts: TtsFrontend,
|
||||
}
|
||||
|
||||
impl Hello {
|
||||
fn new(xns: &xous_names::XousNames, sid: xous::SID) -> Self {
|
||||
let gam = gam::Gam::new(&xns).expect("Can't connect to GAM");
|
||||
let gam_token = gam
|
||||
.register_ux(gam::UxRegistration {
|
||||
app_name: xous_ipc::String::<128>::from_str(gam::APP_NAME_HELLO),
|
||||
ux_type: gam::UxType::Chat,
|
||||
predictor: None,
|
||||
listener: sid.to_array(),
|
||||
redraw_id: HelloOp::Redraw.to_u32().unwrap(),
|
||||
gotinput_id: None,
|
||||
audioframe_id: None,
|
||||
rawkeys_id: None,
|
||||
focuschange_id: None,
|
||||
})
|
||||
.expect("Could not register GAM UX")
|
||||
.unwrap();
|
||||
|
||||
let content = gam
|
||||
.request_content_canvas(gam_token)
|
||||
.expect("Could not get content canvas");
|
||||
let screensize = gam
|
||||
.get_canvas_bounds(content)
|
||||
.expect("Could not get canvas dimensions");
|
||||
Self {
|
||||
gam,
|
||||
_gam_token: gam_token,
|
||||
content,
|
||||
screensize,
|
||||
#[cfg(feature = "tts")]
|
||||
tts: TtsFrontend::new(xns).unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear the entire screen.
|
||||
fn clear_area(&self) {
|
||||
self.gam
|
||||
.draw_rectangle(
|
||||
self.content,
|
||||
Rectangle::new_with_style(
|
||||
Point::new(0, 0),
|
||||
self.screensize,
|
||||
DrawStyle {
|
||||
fill_color: Some(PixelColor::Light),
|
||||
stroke_color: None,
|
||||
stroke_width: 0,
|
||||
},
|
||||
),
|
||||
)
|
||||
.expect("can't clear content area");
|
||||
}
|
||||
|
||||
/// Redraw the text view onto the screen.
|
||||
fn redraw(&mut self) {
|
||||
self.clear_area();
|
||||
|
||||
let mut text_view = TextView::new(
|
||||
self.content,
|
||||
TextBounds::GrowableFromBr(
|
||||
Point::new(
|
||||
self.screensize.x - (self.screensize.x / 2),
|
||||
self.screensize.y - (self.screensize.y / 2),
|
||||
),
|
||||
(self.screensize.x / 5 * 4) as u16,
|
||||
),
|
||||
);
|
||||
|
||||
text_view.border_width = 1;
|
||||
text_view.draw_border = true;
|
||||
text_view.clear_area = true;
|
||||
text_view.rounded_border = Some(3);
|
||||
text_view.style = GlyphStyle::Regular;
|
||||
write!(text_view.text, "{}", t!("helloworld.hello", xous::LANG)).expect("Could not write to text view");
|
||||
#[cfg(feature="tts")]
|
||||
self.tts.tts_simple(t!("helloworld.hello", xous::LANG)).unwrap();
|
||||
|
||||
self.gam
|
||||
.post_textview(&mut text_view)
|
||||
.expect("Could not render text view");
|
||||
self.gam.redraw().expect("Could not redraw screen");
|
||||
}
|
||||
}
|
||||
|
||||
#[xous::xous_main]
|
||||
fn xmain() -> ! {
|
||||
log_server::init_wait().unwrap();
|
||||
log::set_max_level(log::LevelFilter::Info);
|
||||
log::info!("Hello world PID is {}", xous::process::id());
|
||||
|
||||
let xns = xous_names::XousNames::new().unwrap();
|
||||
|
||||
// Register the server with xous
|
||||
let sid = xns
|
||||
.register_name(SERVER_NAME_HELLO, None)
|
||||
.expect("can't register server");
|
||||
|
||||
let mut hello = Hello::new(&xns, sid);
|
||||
|
||||
loop {
|
||||
let msg = xous::receive_message(sid).unwrap();
|
||||
log::debug!("Got message: {:?}", msg);
|
||||
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(HelloOp::Redraw) => {
|
||||
log::debug!("Got redraw");
|
||||
hello.redraw();
|
||||
}
|
||||
Some(HelloOp::Quit) => {
|
||||
log::info!("Quitting application");
|
||||
break;
|
||||
}
|
||||
_ => {
|
||||
log::error!("Got unknown message");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log::info!("Quitting");
|
||||
xous::terminate_process(0)
|
||||
}
|
||||
|
|
@ -10,6 +10,17 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"hello": {
|
||||
"context_name": "Hello World",
|
||||
"menu_name": {
|
||||
"appmenu.hello": {
|
||||
"en": "Hello World!",
|
||||
"ja": "Hello World!",
|
||||
"zh": "大家好!",
|
||||
"en-tts": "Hello World!"
|
||||
}
|
||||
}
|
||||
},
|
||||
"repl": {
|
||||
"context_name": "repl demo app",
|
||||
"menu_name": {
|
||||
|
|
@ -21,4 +32,4 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::api::Point;
|
||||
use crate::api::{LINES, WIDTH};
|
||||
use susres::{ManagedMem, RegManager, RegOrField, SuspendResume};
|
||||
use utralib::generated::*;
|
||||
use xous::MemoryRange;
|
||||
use crate::api::{LINES, WIDTH};
|
||||
|
||||
pub const FB_WIDTH_WORDS: usize = 11;
|
||||
pub const FB_WIDTH_PIXELS: usize = WIDTH;
|
||||
|
|
@ -10,7 +10,6 @@ pub const FB_LINES: usize = LINES;
|
|||
pub const FB_SIZE: usize = FB_WIDTH_WORDS * FB_LINES; // 44 bytes by 536 lines
|
||||
const CONFIG_CLOCK_FREQUENCY: u32 = 100_000_000;
|
||||
|
||||
|
||||
pub struct XousDisplay {
|
||||
fb: MemoryRange,
|
||||
hwfb: MemoryRange,
|
||||
|
|
@ -91,19 +90,36 @@ impl XousDisplay {
|
|||
if draw_note {
|
||||
let note = crate::sleep_note::LOGO_MAP;
|
||||
let note_lines = note.len() / FB_WIDTH_WORDS;
|
||||
let start_line = (FB_LINES - note_lines) / 2;
|
||||
let note_start_line = (FB_LINES - note_lines) / 2;
|
||||
let note_end_line = note_start_line + note_lines;
|
||||
let hwfb: *mut [u32; FB_SIZE] = self.hwfb.as_mut_ptr() as *mut [u32; FB_SIZE];
|
||||
for words in 0..note.len() {
|
||||
unsafe {
|
||||
(*hwfb)[words + start_line * FB_WIDTH_WORDS] = note[words];
|
||||
|
||||
for lines in 0..FB_LINES {
|
||||
for words in 0..FB_WIDTH_WORDS {
|
||||
if lines >= note_start_line && lines < note_end_line {
|
||||
// We're on a line that has the 'Sleeping...' note.
|
||||
// Draw it into the frame buffer.
|
||||
let note_index = ((lines - note_start_line) * FB_WIDTH_WORDS) + words;
|
||||
unsafe {
|
||||
(*hwfb)[words + lines * FB_WIDTH_WORDS] = note[note_index];
|
||||
}
|
||||
} else {
|
||||
// We're not on a line that has the note. Clear the pixels,
|
||||
// since we don't want any secrets to linger in the framebuffer
|
||||
// and stay visible on the persistent display while the device is
|
||||
// sleeping.
|
||||
unsafe {
|
||||
(*hwfb)[words + lines * FB_WIDTH_WORDS] = 0xFFFF_FFFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for lines in start_line..start_line + note_lines {
|
||||
|
||||
// set the dirty bits
|
||||
unsafe {
|
||||
(*hwfb)[lines * FB_WIDTH_WORDS + (FB_WIDTH_WORDS - 1)] |= 0x1_0000;
|
||||
}
|
||||
}
|
||||
|
||||
self.update_dirty();
|
||||
while self.busy() {
|
||||
// busy wait, blocking suspend until this has happened
|
||||
|
|
|
|||
BIN
tools/csr_data_0.9.5.bin
Normal file
BIN
tools/csr_data_0.9.5.bin
Normal file
Binary file not shown.
BIN
tools/csr_data_0.9.6.bin
Normal file
BIN
tools/csr_data_0.9.6.bin
Normal file
Binary file not shown.
BIN
tools/csr_data_0.9.7.bin
Normal file
BIN
tools/csr_data_0.9.7.bin
Normal file
Binary file not shown.
|
|
@ -13,10 +13,7 @@ if ($decision -eq 0) {
|
|||
Exit
|
||||
}
|
||||
|
||||
Invoke-WebRequest https://ci.betrusted.io/releases/latest/loader.bin -OutFile loader.bin
|
||||
python usb_update.py -l loader.bin
|
||||
Remove-Item loader.bin
|
||||
|
||||
python usb_update.py --disable-boot
|
||||
Write-Output "waiting for device to reboot"
|
||||
Start-Sleep 5
|
||||
|
||||
|
|
@ -27,13 +24,6 @@ Remove-Item xous.img
|
|||
Write-Output "waiting for device to reboot"
|
||||
Start-Sleep 5
|
||||
|
||||
Invoke-WebRequest https://ci.betrusted.io/releases/latest/soc_csr.bin -OutFile soc_csr.bin
|
||||
python usb_update.py --soc soc_csr.bin --force
|
||||
Remove-Item soc_csr.bin
|
||||
|
||||
Write-Output "waiting for device to reboot"
|
||||
Start-Sleep 5
|
||||
|
||||
Invoke-WebRequest https://ci.betrusted.io/releases/latest/ec_fw.bin -OutFile ec_fw.bin
|
||||
python usb_update.py -e ec_fw.bin
|
||||
Remove-Item ec_fw.bin
|
||||
|
|
@ -45,4 +35,15 @@ Invoke-WebRequest https://ci.betrusted.io/releases/latest/wf200_fw.bin -OutFile
|
|||
python usb_update.py -w wf200_fw.bin
|
||||
Remove-Item wf200_fw.bin
|
||||
|
||||
Write-Output "waiting for device to reboot"
|
||||
Start-Sleep 5
|
||||
|
||||
Invoke-WebRequest https://ci.betrusted.io/releases/latest/soc_csr.bin -OutFile soc_csr.bin
|
||||
Invoke-WebRequest https://ci.betrusted.io/releases/latest/loader.bin -OutFile loader.bin
|
||||
python usb_update.py --enable-boot --soc soc_csr.bin -l loader.bin
|
||||
Remove-Item soc_csr.bin
|
||||
Remove-Item loader.bin
|
||||
|
||||
Write-Output "Please insert a paperclip in the hard reset hole in the lower right hand corner to ensure the new FPGA gateware is loaded."
|
||||
Write-Output "After inserting the paperclip you will need to apply power via USB to boot."
|
||||
Write-Output "IMPORTANT: you must run 'ecup auto' to update the EC with the staged firmware objects."
|
||||
|
|
|
|||
|
|
@ -29,10 +29,7 @@ else
|
|||
LOCALE=""
|
||||
fi
|
||||
|
||||
wget https://ci.betrusted.io/$REVISION/loader.bin -O /tmp/loader.bin
|
||||
./usb_update.py -l /tmp/loader.bin
|
||||
rm /tmp/loader.bin
|
||||
|
||||
./usb_update.py --disable-boot
|
||||
echo "waiting for device to reboot"
|
||||
sleep 5
|
||||
|
||||
|
|
@ -43,13 +40,6 @@ rm /tmp/xous.img
|
|||
echo "waiting for device to reboot"
|
||||
sleep 5
|
||||
|
||||
wget https://ci.betrusted.io/$REVISION/soc_csr.bin -O /tmp/soc_csr.bin
|
||||
./usb_update.py --soc /tmp/soc_csr.bin --force
|
||||
rm /tmp/soc_csr.bin
|
||||
|
||||
echo "waiting for device to reboot"
|
||||
sleep 5
|
||||
|
||||
wget https://ci.betrusted.io/$REVISION/ec_fw.bin -O /tmp/ec_fw.bin
|
||||
./usb_update.py -e /tmp/ec_fw.bin
|
||||
rm /tmp/ec_fw.bin
|
||||
|
|
@ -60,5 +50,16 @@ wget https://ci.betrusted.io/$REVISION/wf200_fw.bin -O /tmp/wf200_fw.bin
|
|||
./usb_update.py -w /tmp/wf200_fw.bin
|
||||
rm /tmp/wf200_fw.bin
|
||||
|
||||
echo " "
|
||||
echo "waiting for device to reboot"
|
||||
sleep 5
|
||||
|
||||
# this should sequence last because it overwrites all of the CSR values on the currently loaded SoC
|
||||
wget https://ci.betrusted.io/$REVISION/soc_csr.bin -O /tmp/soc_csr.bin
|
||||
wget https://ci.betrusted.io/$REVISION/loader.bin -O /tmp/loader.bin
|
||||
./usb_update.py --enable-boot --soc /tmp/soc_csr.bin -l /tmp/loader.bin
|
||||
rm /tmp/loader.bin
|
||||
rm /tmp/soc_csr.bin
|
||||
|
||||
echo "Please insert a paperclip in the hard reset hole in the lower right hand corner to ensure the new FPGA gateware is loaded."
|
||||
echo "After inserting the paperclip you will need to apply power via USB to boot."
|
||||
echo "IMPORTANT: you must run 'ecup auto' to update the EC with the staged firmware objects."
|
||||
|
|
|
|||
|
|
@ -197,10 +197,16 @@ class PrecursorUsb:
|
|||
self.spinor_command_value(exec=1, lock_reads=1, cmd_code=self.PP4B, has_arg=1, data_words=(data_bytes//2))
|
||||
)
|
||||
|
||||
def load_csrs(self):
|
||||
def load_csrs(self, fname=None):
|
||||
LOC_CSRCSV = 0x20277000 # this address shouldn't change because it's how we figure out our version number
|
||||
# CSR extraction:
|
||||
# dd if=soc_csr.bin of=csr_data_0.9.6.bin skip=2524 count=32 bs=1024
|
||||
if fname == None:
|
||||
csr_data = self.burst_read(LOC_CSRCSV, 0x8000)
|
||||
else:
|
||||
with open(fname, "rb") as f:
|
||||
csr_data = f.read(0x8000)
|
||||
|
||||
csr_data = self.burst_read(LOC_CSRCSV, 0x8000)
|
||||
hasher = hashlib.sha512()
|
||||
hasher.update(csr_data[:0x7FC0])
|
||||
digest = hasher.digest()
|
||||
|
|
@ -404,6 +410,12 @@ def main():
|
|||
parser.add_argument(
|
||||
"-l", "--loader", required=False, help="Loader", type=str, nargs='?', metavar=('loader file'), const='../target/riscv32imac-unknown-xous-elf/release/loader.bin'
|
||||
)
|
||||
parser.add_argument(
|
||||
"--disable-boot", required=False, action='store_true', help="Disable system boot (for use in multi-stage updates)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--enable-boot", required=False, action='store_true', help="Re-enable system boot. Requires both a loader and a soc spec."
|
||||
)
|
||||
parser.add_argument(
|
||||
"-k", "--kernel", required=False, help="Kernel", type=str, nargs='?', metavar=('kernel file'), const='../target/riscv32imac-unknown-xous-elf/release/xous.img'
|
||||
)
|
||||
|
|
@ -446,6 +458,9 @@ def main():
|
|||
parser.add_argument(
|
||||
"--factory-new", help="reset the entire image to mimic exactly what comes out of the factory, including temp files for testing. Warning: this will take a long time.", action="store_true"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--override-csr", required=False, help="CSR file to use instead of CSR values stored with the image. Used to recover in case of partial update of soc_csr.bin", type=str,
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if not len(sys.argv) > 1:
|
||||
|
|
@ -488,7 +503,7 @@ def main():
|
|||
# print("match")
|
||||
exit(0)
|
||||
|
||||
pc_usb.load_csrs() # prime the CSR values
|
||||
pc_usb.load_csrs(args.override_csr) # prime the CSR values
|
||||
if "v0.8" in pc_usb.gitrev:
|
||||
locs = {
|
||||
"LOC_SOC" : [0x0000_0000, "soc_csr.bin"],
|
||||
|
|
@ -539,6 +554,38 @@ def main():
|
|||
print("Erasing PDDB region")
|
||||
pc_usb.erase_region(locs['LOC_PDDB'][0], locs['LOC_EC'][0] - locs['LOC_PDDB'][0])
|
||||
|
||||
if args.disable_boot:
|
||||
print("Disabling boot")
|
||||
pc_usb.erase_region(locs['LOC_LOADER'][0], 1024 * 256)
|
||||
|
||||
if args.enable_boot:
|
||||
if args.loader == None:
|
||||
print("Must provide both a loader and soc image")
|
||||
if args.soc == None:
|
||||
print("Must provide both a soc and loader image")
|
||||
print("Enabling boot with {} and {}".format(args.loader, args.soc))
|
||||
print("Programming loader image {}".format(args.loader))
|
||||
with open(args.loader, "rb") as f:
|
||||
image = f.read()
|
||||
pc_usb.flash_program(locs['LOC_LOADER'][0], image, verify=verify)
|
||||
print("Programming SoC gateware".format(args.soc))
|
||||
with open(args.soc, "rb") as f:
|
||||
image = f.read()
|
||||
pc_usb.flash_program(locs['LOC_SOC'][0], image, verify=verify)
|
||||
|
||||
print("Erasing PDDB root structures")
|
||||
pc_usb.erase_region(locs['LOC_PDDB'][0], 1024 * 1024)
|
||||
|
||||
print("Resuming CPU.")
|
||||
pc_usb.poke(vexdbg_addr, 0x02000000)
|
||||
|
||||
print("Resetting SOC...")
|
||||
try:
|
||||
pc_usb.poke(pc_usb.register('reboot_soc_reset'), 0xac, display=False)
|
||||
except usb.core.USBError:
|
||||
pass # we expect an error because we reset the SOC and that includes the USB core
|
||||
exit(0)
|
||||
|
||||
if args.image:
|
||||
image_file, addr_str = args.image
|
||||
addr = int(addr_str, 0)
|
||||
|
|
|
|||
|
|
@ -165,6 +165,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
let lkey = args.nth(3);
|
||||
let kkey = args.nth(4);
|
||||
match task.as_deref() {
|
||||
Some("install-toolkit") => {
|
||||
let arg = env::args().nth(2);
|
||||
ensure_compiler(
|
||||
&Some(PROGRAM_TARGET),
|
||||
true,
|
||||
arg.map(|x| x == "--force").unwrap_or(false),
|
||||
)?
|
||||
}
|
||||
Some("renode-image") => {
|
||||
let mut args = env::args();
|
||||
args.nth(1);
|
||||
|
|
@ -185,7 +193,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
&hw_pkgs,
|
||||
&[],
|
||||
None,
|
||||
Some(&["--features", "renode-bypass"]),
|
||||
None,
|
||||
)?
|
||||
}
|
||||
Some("renode-test") => {
|
||||
|
|
@ -602,6 +610,7 @@ Various debug configurations:
|
|||
pddb-ci PDDB config for CI testing (eg: TRNG->deterministic for reproducible errors)
|
||||
ffi-test builds an image for testing C-FFI bindings and integration
|
||||
tts builds an image with text to speech support via externally linked C executable
|
||||
install-toolkit installs Xous toolkit with no prompt, useful in CI. Specify `--force` to remove existing toolchains
|
||||
"
|
||||
)
|
||||
}
|
||||
|
|
@ -1015,7 +1024,11 @@ static DONE_COMPILER_CHECK: std::sync::atomic::AtomicBool =
|
|||
/// Ensure we have a compatible compiler toolchain. We use a new Target,
|
||||
/// and we want to give the user a friendly way of installing the latest
|
||||
/// Rust toolchain.
|
||||
fn ensure_compiler(target: &Option<&str>) -> Result<(), String> {
|
||||
fn ensure_compiler(
|
||||
target: &Option<&str>,
|
||||
force_install: bool,
|
||||
remove_existing: bool,
|
||||
) -> Result<(), String> {
|
||||
use std::process::Stdio;
|
||||
if DONE_COMPILER_CHECK.load(std::sync::atomic::Ordering::SeqCst) {
|
||||
return Ok(());
|
||||
|
|
@ -1079,16 +1092,39 @@ fn ensure_compiler(target: &Option<&str>) -> Result<(), String> {
|
|||
|
||||
// If the sysroot exists, then we're good.
|
||||
let target = target.unwrap_or(PROGRAM_TARGET);
|
||||
if get_sysroot(Some(target))?.is_some() {
|
||||
DONE_COMPILER_CHECK.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
return Ok(());
|
||||
if let Some(path) = get_sysroot(Some(target))? {
|
||||
let mut version_path = PathBuf::from(&path);
|
||||
version_path.push("lib");
|
||||
version_path.push("rustlib");
|
||||
version_path.push(PROGRAM_TARGET);
|
||||
if remove_existing {
|
||||
println!("Target path exists, removing it");
|
||||
std::fs::remove_dir_all(version_path)
|
||||
.or_else(|e| Err(format!("unable to remove existing toolchain: {}", e)))?;
|
||||
println!("Also removing target directories for existing toolchain");
|
||||
let mut target_main = project_root();
|
||||
target_main.push("target");
|
||||
target_main.push(PROGRAM_TARGET);
|
||||
std::fs::remove_dir_all(target_main).ok();
|
||||
|
||||
let mut target_loader = project_root();
|
||||
target_loader.push("loader");
|
||||
target_loader.push("target");
|
||||
target_loader.push(PROGRAM_TARGET);
|
||||
std::fs::remove_dir_all(target_loader).ok();
|
||||
|
||||
} else {
|
||||
DONE_COMPILER_CHECK.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
// Since no sysroot exists, we must download a new one.
|
||||
let toolchain_path =
|
||||
get_sysroot(None)?.ok_or_else(|| "default toolchain not installed".to_owned())?;
|
||||
// If the terminal is a tty, offer to download the latest toolchain.
|
||||
if !atty::is(atty::Stream::Stdin) {
|
||||
// If the terminal is a tty, or if toolchain installation is forced,
|
||||
// download the latest toolchain.
|
||||
if !atty::is(atty::Stream::Stdin) && !force_install {
|
||||
return Err(format!("Toolchain for {} not found", target));
|
||||
}
|
||||
|
||||
|
|
@ -1108,6 +1144,10 @@ fn ensure_compiler(target: &Option<&str>) -> Result<(), String> {
|
|||
target
|
||||
);
|
||||
loop {
|
||||
if force_install {
|
||||
break;
|
||||
}
|
||||
|
||||
print!("Would you like this program to attempt to download and install it? [Y/n] ");
|
||||
stdout.flush().unwrap();
|
||||
buffer.clear();
|
||||
|
|
@ -1251,7 +1291,7 @@ fn build(
|
|||
extra_args: Option<&[&str]>,
|
||||
features: Option<&[&str]>,
|
||||
) -> Result<PathBuf, DynError> {
|
||||
ensure_compiler(&target)?;
|
||||
ensure_compiler(&target, false, false)?;
|
||||
let stream = if debug { "debug" } else { "release" };
|
||||
let mut args = vec!["build"];
|
||||
print!("Building");
|
||||
|
|
|
|||
Loading…
Reference in a new issue