szl: reduced binary size.

* Compiled unlzma with -Oz and enable LTO.
* Changed one unwrap to manual handling to remove fmt code.
* Implemented custom panic handler with minimal code.
This commit is contained in:
pca006132 2020-08-07 13:25:16 +08:00
parent 3a8a025d5f
commit 7342736124
3 changed files with 16 additions and 3 deletions

View File

@ -13,7 +13,7 @@ default = ["target_zc706"]
log = "0.4" log = "0.4"
cstr_core = { version = "0.2", default-features = false } cstr_core = { version = "0.2", default-features = false }
libboard_zynq = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" } libboard_zynq = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" }
libsupport_zynq = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" } libsupport_zynq = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git", default-features = false, features = ["dummy_irq_handler"] }
libcortex_a9 = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" } libcortex_a9 = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" }
[build-dependencies] [build-dependencies]

View File

@ -32,7 +32,8 @@ pub fn compile_unlzma() {
cfg.flag("-fPIC"); cfg.flag("-fPIC");
cfg.flag("-fno-stack-protector"); cfg.flag("-fno-stack-protector");
cfg.flag("--target=armv7-none-eabihf"); cfg.flag("--target=armv7-none-eabihf");
cfg.flag("-Os"); cfg.flag("-Oz");
cfg.flag("-flto=full");
let sources = vec![ let sources = vec![
"unlzma.c", "unlzma.c",

View File

@ -1,5 +1,6 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
#![feature(panic_info_message)]
extern crate log; extern crate log;
@ -15,6 +16,7 @@ use libcortex_a9::{
use libboard_zynq::{ use libboard_zynq::{
self as zynq, println, self as zynq, println,
clocks::Clocks, clocks::source::{ClockSource, ArmPll, IoPll}, clocks::Clocks, clocks::source::{ClockSource, ArmPll, IoPll},
stdio,
logger, logger,
timer::GlobalTimer, timer::GlobalTimer,
}; };
@ -28,7 +30,17 @@ extern "C" {
} }
extern fn lzma_error(message: *const u8) { extern fn lzma_error(message: *const u8) {
error!("LZMA error: {}", unsafe { CStr::from_ptr(message) }.to_str().unwrap()); let msg = unsafe {CStr::from_ptr(message)}.to_str();
if let Ok(msg) = msg {
println!("LZMA error: {}", msg);
}
}
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
stdio::drop_uart();
println!("panicked!");
loop {}
} }
#[no_mangle] #[no_mangle]