forked from M-Labs/artiq
1
0
Fork 0

firmware: use libbuild_misoc in libdrtioaux. NFC.

This commit is contained in:
whitequark 2017-12-28 08:05:38 +00:00
parent 8f33061a6d
commit 1b9b560242
10 changed files with 200 additions and 13 deletions

View File

@ -42,6 +42,16 @@ dependencies = [
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "bootloader"
version = "0.0.0"
dependencies = [
"board 0.0.0",
"build_artiq 0.0.0",
"crc 1.6.0 (git+git://github.com/whitequark/crc-rs?rev=51cd356)",
"rlibc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "build_artiq" name = "build_artiq"
version = "0.0.0" version = "0.0.0"
@ -49,6 +59,11 @@ dependencies = [
"walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "build_const"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "build_misoc" name = "build_misoc"
version = "0.0.0" version = "0.0.0"
@ -77,6 +92,14 @@ name = "compiler_builtins"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/m-labs/compiler-builtins?rev=97916b1#97916b17ca542eac0524b8570c7d05913891a0dc" source = "git+https://github.com/m-labs/compiler-builtins?rev=97916b1#97916b17ca542eac0524b8570c7d05913891a0dc"
[[package]]
name = "crc"
version = "1.6.0"
source = "git+git://github.com/whitequark/crc-rs?rev=51cd356#51cd3560aa9d3823061f2bb46797d8c61f4cfa9e"
dependencies = [
"build_const 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "cslice" name = "cslice"
version = "0.3.0" version = "0.3.0"
@ -87,6 +110,7 @@ name = "drtioaux"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"board 0.0.0", "board 0.0.0",
"build_misoc 0.0.0",
"byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
"std_artiq 0.0.0", "std_artiq 0.0.0",
@ -174,6 +198,11 @@ dependencies = [
"std_artiq 0.0.0", "std_artiq 0.0.0",
] ]
[[package]]
name = "rlibc"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "runtime" name = "runtime"
version = "0.0.0" version = "0.0.0"
@ -261,10 +290,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata] [metadata]
"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" "checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf"
"checksum build_const 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e90dc84f5e62d2ebe7676b83c22d33b6db8bd27340fb6ffbff0a364efa0cb9c9"
"checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" "checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23"
"checksum cc 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a9b13a57efd6b30ecd6598ebdb302cca617930b5470647570468a65d12ef9719" "checksum cc 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a9b13a57efd6b30ecd6598ebdb302cca617930b5470647570468a65d12ef9719"
"checksum compiler_builtins 0.1.0 (git+https://github.com/m-labs/compiler-builtins?rev=97916b1)" = "<none>" "checksum compiler_builtins 0.1.0 (git+https://github.com/m-labs/compiler-builtins?rev=97916b1)" = "<none>"
"checksum compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins?rev=631b568)" = "<none>" "checksum compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins?rev=631b568)" = "<none>"
"checksum crc 1.6.0 (git+git://github.com/whitequark/crc-rs?rev=51cd356)" = "<none>"
"checksum cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0f8cb7306107e4b10e64994de6d3274bd08996a7c1322a27b86482392f96be0a" "checksum cslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0f8cb7306107e4b10e64994de6d3274bd08996a7c1322a27b86482392f96be0a"
"checksum fringe 1.1.0 (git+https://github.com/m-labs/libfringe?rev=bd23494)" = "<none>" "checksum fringe 1.1.0 (git+https://github.com/m-labs/libfringe?rev=bd23494)" = "<none>"
"checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb" "checksum gcc 0.3.54 (registry+https://github.com/rust-lang/crates.io-index)" = "5e33ec290da0d127825013597dbdfc28bee4964690c7ce1166cbc2a7bd08b1bb"
@ -273,6 +304,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b"
"checksum log_buffer 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ec57723b84bbe7bdf76aa93169c9b59e67473317c6de3a83cb2a0f8ccb2aa493" "checksum log_buffer 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ec57723b84bbe7bdf76aa93169c9b59e67473317c6de3a83cb2a0f8ccb2aa493"
"checksum managed 0.4.0 (git+https://github.com/m-labs/rust-managed.git?rev=629a6786a1cf1692015f464ed16c04eafa5cb8d1)" = "<none>" "checksum managed 0.4.0 (git+https://github.com/m-labs/rust-managed.git?rev=629a6786a1cf1692015f464ed16c04eafa5cb8d1)" = "<none>"
"checksum rlibc 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe"
"checksum rustc-cfg 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "56a596b5718bf5e059d59a30af12f7f462a152de147aa462b70892849ee18704" "checksum rustc-cfg 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "56a596b5718bf5e059d59a30af12f7f462a152de147aa462b70892849ee18704"
"checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7" "checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7"
"checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp?rev=507d2fe)" = "<none>" "checksum smoltcp 0.4.0 (git+https://github.com/m-labs/smoltcp?rev=507d2fe)" = "<none>"

View File

@ -1,2 +1,2 @@
[workspace] [workspace]
members = ["runtime", "ksupport", "satman"] members = ["bootloader", "runtime", "ksupport", "satman"]

View File

@ -0,0 +1,18 @@
[package]
authors = ["M-Labs"]
name = "bootloader"
version = "0.0.0"
build = "build.rs"
[lib]
name = "bootloader"
crate-type = ["staticlib"]
path = "main.rs"
[build-dependencies]
build_artiq = { path = "../libbuild_artiq" }
[dependencies]
rlibc = "1.0"
crc = { git = "git://github.com/whitequark/crc-rs", rev = "51cd356", default-features = false }
board = { path = "../libboard", features = ["uart_console"] }

View File

@ -0,0 +1,18 @@
include ../include/generated/variables.mak
include $(MISOC_DIRECTORY)/software/common.mak
RUSTFLAGS += -Cpanic=abort
all:: bootloader.bin
.PHONY: $(RUSTOUT)/libbootloader.a
$(RUSTOUT)/libbootloader.a:
$(cargo) --manifest-path $(BOOTLOADER_DIRECTORY)/Cargo.toml -- \
-Clto
bootloader.elf: $(RUSTOUT)/libbootloader.a
$(link) -T $(BOOTLOADER_DIRECTORY)/bootloader.ld
%.bin: %.elf
$(objcopy) -O binary
$(MSCIMG) $@

View File

@ -0,0 +1,46 @@
INCLUDE generated/output_format.ld
INCLUDE generated/regions.ld
ENTRY(_reset_handler)
SECTIONS
{
.vectors :
{
_begin = .;
*(.vectors)
} > rom
.text :
{
*(.text .text.*)
} > rom
.rodata :
{
*(.rodata.*)
. = ALIGN(4);
_end = .;
} > rom
.crc ALIGN(4) :
{
_crc = .;
. += 4;
}
.bss ALIGN(4) :
{
_fbss = .;
*(.bss .bss.*)
. = ALIGN(4);
_ebss = .;
} > sram
.stack :
{
/* Ensure we have a certain amount of space available for stack. */
. = ORIGIN(sram) + LENGTH(sram) - 0x800;
. = ORIGIN(sram) + LENGTH(sram) - 4;
_fstack = .;
} > sram
}

View File

@ -0,0 +1,6 @@
extern crate build_artiq;
fn main() {
build_artiq::misoc_cfg();
build_artiq::git_describe();
}

View File

@ -0,0 +1,73 @@
#![no_std]
#![feature(lang_items)]
extern crate rlibc;
extern crate crc;
#[macro_use]
extern crate board;
use core::slice;
fn check_integrity() -> bool {
extern {
static _begin: u8;
static _end: u8;
static _crc: u32;
}
unsafe {
let length = &_end as *const u8 as usize -
&_begin as *const u8 as usize;
let bios = slice::from_raw_parts(&_begin as *const u8, length);
crc::crc32::checksum_ieee(bios) == _crc
}
}
fn initialize_sdram() -> bool {
unsafe {
board::sdram_phy::initialize();
true
}
}
#[no_mangle]
pub extern fn main() -> i32 {
println!("");
println!(r" _ ____ _____ ___ ___ ");
println!(r" / \ | _ \_ _|_ _/ _ \ ");
println!(r" / _ \ | |_) || | | | | | |");
println!(r" / ___ \| _ < | | | | |_| |");
println!(r"/_/ \_\_| \_\|_| |___\__\_\");
println!("");
println!("ARTIQ Bootloader");
println!("Copyright (c) 2017 M-Labs Limited");
println!("Version {}", include_str!(concat!(env!("OUT_DIR"), "/git-describe")));
println!("");
if !check_integrity() {
panic!("Bootloader CRC failed");
} else {
println!("Bootloader CRC passed");
}
if !initialize_sdram() {
panic!("SDRAM initialization failed")
} else {
println!("SDRAM initialized");
}
loop {}
}
#[no_mangle]
pub extern fn exception(vect: u32, _regs: *const u32, pc: u32, ea: u32) {
panic!("exception {} at PC {:#08x}, EA {:#08x}", vect, pc, ea)
}
#[no_mangle]
#[lang = "panic_fmt"]
pub extern fn panic_fmt(args: core::fmt::Arguments, file: &'static str, line: u32) -> ! {
println!("panic at {}:{}: {}", file, line, args);
loop {}
}

View File

@ -8,6 +8,9 @@ build = "build.rs"
name = "drtioaux" name = "drtioaux"
path = "lib.rs" path = "lib.rs"
[build-dependencies]
build_misoc = { path = "../libbuild_misoc" }
[dependencies] [dependencies]
log = { version = "0.3", default-features = false } log = { version = "0.3", default-features = false }
std_artiq = { path = "../libstd_artiq", features = ["alloc"] } std_artiq = { path = "../libstd_artiq", features = ["alloc"] }

View File

@ -1,15 +1,5 @@
use std::env; extern crate build_misoc;
use std::path::Path;
use std::io::{BufRead, BufReader};
use std::fs::File;
fn main() { fn main() {
let out_dir = env::var("BUILDINC_DIRECTORY").unwrap(); build_misoc::cfg();
let cfg_path = Path::new(&out_dir).join("generated").join("rust-cfg");
println!("cargo:rerun-if-changed={}", cfg_path.to_str().unwrap());
let f = BufReader::new(File::open(&cfg_path).unwrap());
for line in f.lines() {
println!("cargo:rustc-cfg={}", line.unwrap());
}
} }

View File

@ -48,6 +48,7 @@ def build_artiq_soc(soc, argdict):
builder = Builder(soc, **argdict) builder = Builder(soc, **argdict)
builder.add_software_package("libm") builder.add_software_package("libm")
builder.add_software_package("libunwind") builder.add_software_package("libunwind")
builder.add_software_package("bootloader", os.path.join(artiq_dir, "firmware", "bootloader"))
builder.add_software_package("ksupport", os.path.join(artiq_dir, "firmware", "ksupport")) builder.add_software_package("ksupport", os.path.join(artiq_dir, "firmware", "ksupport"))
builder.add_software_package("runtime", os.path.join(artiq_dir, "firmware", "runtime")) builder.add_software_package("runtime", os.path.join(artiq_dir, "firmware", "runtime"))
try: try: