From 795a3e24d8673d757b97803c6b5115dce7e9befb Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 7 Mar 2017 06:44:21 +0000 Subject: [PATCH] artiq_coreboot: block until hotswap image is actually received. --- artiq/coredevice/comm_kernel.py | 4 ++++ artiq/firmware/libproto/session_proto.rs | 5 +++++ artiq/firmware/runtime/session.rs | 9 +++++++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/artiq/coredevice/comm_kernel.py b/artiq/coredevice/comm_kernel.py index 63fe42328..5bcd206bd 100644 --- a/artiq/coredevice/comm_kernel.py +++ b/artiq/coredevice/comm_kernel.py @@ -60,6 +60,8 @@ class _D2HMsgType(Enum): WATCHDOG_EXPIRED = 14 CLOCK_FAILURE = 15 + HOTSWAP_IMMINENT = 16 + class _LogLevel(Enum): OFF = 0 @@ -332,6 +334,8 @@ class CommKernel: self._write_header(_H2DMsgType.HOTSWAP) self._write_bytes(image) + self._read_empty(_D2HMsgType.HOTSWAP_IMMINENT) + def load(self, kernel_library): self._write_header(_H2DMsgType.LOAD_KERNEL) self._write_bytes(kernel_library) diff --git a/artiq/firmware/libproto/session_proto.rs b/artiq/firmware/libproto/session_proto.rs index 31f3cc911..e15eed08d 100644 --- a/artiq/firmware/libproto/session_proto.rs +++ b/artiq/firmware/libproto/session_proto.rs @@ -140,6 +140,8 @@ pub enum Reply<'a> { WatchdogExpired, ClockFailure, + + HotswapImminent, } impl<'a> Reply<'a> { @@ -219,6 +221,9 @@ impl<'a> Reply<'a> { Reply::ClockFailure => { writer.write_u8(15)?; }, + Reply::HotswapImminent => { + writer.write_u8(16)?; + } } Ok(()) } diff --git a/artiq/firmware/runtime/session.rs b/artiq/firmware/runtime/session.rs index 370a9ac34..00cfb7eb7 100644 --- a/artiq/firmware/runtime/session.rs +++ b/artiq/firmware/runtime/session.rs @@ -116,6 +116,7 @@ fn host_read(stream: &mut TcpStream) -> io::Result { let request = host::Request::read_from(stream)?; match &request { &host::Request::LoadKernel(_) => debug!("comm<-host LoadLibrary(...)"), + &host::Request::Hotswap(_) => debug!("comm<-host Hotswap(...)"), _ => debug!("comm<-host {:?}", request) } Ok(request) @@ -269,8 +270,12 @@ fn process_host_message(io: &Io, } // artiq_coreboot - host::Request::Hotswap(binary) => - unsafe { board::hotswap::run(&binary) }, + host::Request::Hotswap(binary) => { + host_write(stream, host::Reply::HotswapImminent)?; + stream.close()?; + warn!("hotswapping firmware"); + unsafe { board::hotswap::run(&binary) } + } // artiq_run/artiq_master host::Request::SwitchClock(clk) => {