From 7342736124792410b5407a74483f8b376311a8f1 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 7 Aug 2020 13:25:16 +0800 Subject: [PATCH] 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. --- src/szl/Cargo.toml | 2 +- src/szl/build.rs | 3 ++- src/szl/src/main.rs | 14 +++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/szl/Cargo.toml b/src/szl/Cargo.toml index 2b541b7..459b6b1 100644 --- a/src/szl/Cargo.toml +++ b/src/szl/Cargo.toml @@ -13,7 +13,7 @@ default = ["target_zc706"] log = "0.4" cstr_core = { version = "0.2", default-features = false } 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" } [build-dependencies] diff --git a/src/szl/build.rs b/src/szl/build.rs index 2fe03fc..90e8692 100644 --- a/src/szl/build.rs +++ b/src/szl/build.rs @@ -32,7 +32,8 @@ pub fn compile_unlzma() { cfg.flag("-fPIC"); cfg.flag("-fno-stack-protector"); cfg.flag("--target=armv7-none-eabihf"); - cfg.flag("-Os"); + cfg.flag("-Oz"); + cfg.flag("-flto=full"); let sources = vec![ "unlzma.c", diff --git a/src/szl/src/main.rs b/src/szl/src/main.rs index 3f2cf75..612884e 100644 --- a/src/szl/src/main.rs +++ b/src/szl/src/main.rs @@ -1,5 +1,6 @@ #![no_std] #![no_main] +#![feature(panic_info_message)] extern crate log; @@ -15,6 +16,7 @@ use libcortex_a9::{ use libboard_zynq::{ self as zynq, println, clocks::Clocks, clocks::source::{ClockSource, ArmPll, IoPll}, + stdio, logger, timer::GlobalTimer, }; @@ -28,7 +30,17 @@ extern "C" { } 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]