From 838fa25badb2618a8460651779e60277e126dff0 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sat, 27 Feb 2021 14:52:21 +0800 Subject: [PATCH] get rid of the awful dummy arg hack and use #used directive to keep font maps in loader --- loader/src/fonts/bold.rs | 1 + loader/src/fonts/emoji.rs | 1 + loader/src/fonts/hanzi.rs | 1 + loader/src/fonts/regular.rs | 1 + loader/src/fonts/small.rs | 1 + loader/src/generate_fonts.py | 18 ++++++++++++++++++ loader/src/main.rs | 7 ------- services/graphics-server/src/main.rs | 8 ++++---- 8 files changed, 27 insertions(+), 11 deletions(-) diff --git a/loader/src/fonts/bold.rs b/loader/src/fonts/bold.rs index e9eb1a076..d18fbae8b 100644 --- a/loader/src/fonts/bold.rs +++ b/loader/src/fonts/bold.rs @@ -2,6 +2,7 @@ #[allow(dead_code)] #[link_section=".fontdata"] #[no_mangle] +#[used] /// Packed glyph pattern data. /// Record format: /// [offset+0]: ((w as u8) << 16) | ((h as u8) << 8) | (yOffset as u8) diff --git a/loader/src/fonts/emoji.rs b/loader/src/fonts/emoji.rs index 28b84af4f..2fc151286 100644 --- a/loader/src/fonts/emoji.rs +++ b/loader/src/fonts/emoji.rs @@ -2,6 +2,7 @@ #[allow(dead_code)] #[link_section=".fontdata"] #[no_mangle] +#[used] /// Packed glyph pattern data. /// Record format: /// [offset+0]: ((w as u8) << 16) | ((h as u8) << 8) | (yOffset as u8) diff --git a/loader/src/fonts/hanzi.rs b/loader/src/fonts/hanzi.rs index 25ec5e251..2f7411e03 100644 --- a/loader/src/fonts/hanzi.rs +++ b/loader/src/fonts/hanzi.rs @@ -2,6 +2,7 @@ #[allow(dead_code)] #[link_section=".fontdata"] #[no_mangle] +#[used] /// Packed glyph pattern data. /// Record format: /// [offset+0]: ((w as u8) << 16) | ((h as u8) << 8) | (yOffset as u8) diff --git a/loader/src/fonts/regular.rs b/loader/src/fonts/regular.rs index 818f1fd8f..20017a586 100644 --- a/loader/src/fonts/regular.rs +++ b/loader/src/fonts/regular.rs @@ -2,6 +2,7 @@ #[allow(dead_code)] #[link_section=".fontdata"] #[no_mangle] +#[used] /// Packed glyph pattern data. /// Record format: /// [offset+0]: ((w as u8) << 16) | ((h as u8) << 8) | (yOffset as u8) diff --git a/loader/src/fonts/small.rs b/loader/src/fonts/small.rs index 0bea1ee21..b01c32d0c 100644 --- a/loader/src/fonts/small.rs +++ b/loader/src/fonts/small.rs @@ -2,6 +2,7 @@ #[allow(dead_code)] #[link_section=".fontdata"] #[no_mangle] +#[used] /// Packed glyph pattern data. /// Record format: /// [offset+0]: ((w as u8) << 16) | ((h as u8) << 8) | (yOffset as u8) diff --git a/loader/src/generate_fonts.py b/loader/src/generate_fonts.py index 9d0577a30..1662e2b38 100755 --- a/loader/src/generate_fonts.py +++ b/loader/src/generate_fonts.py @@ -7,6 +7,23 @@ import sys import re from collections import OrderedDict +""" +This script should be run whenever the fonts are updated inside the blitstr dependency. The +thought is that this is a rare event, and therefore it's better to run this on the rare occassions +that this happens and vendor in the font files as references to their location in the FLASH +memory map. + +The main motivation for this is to disintegrate the font maps from the kernel image itself, +as it is a large ball of static data that rarely changes, and it slows down updates and +development. Maybe once the kernel supports servers that are bootable from disk images, we +can do away with this methodology. But for now, this helps keep the kernel trim, and speeds +up the development process. + +This script is designed to be run "in-place" where it is found in the xous-core tree. It +hard-codes the location of the graphics-server crate to encode the locations of the fonts. +It also, by default, assumes that the `blitstr` crate is cloned into a directory at the +same level as xous-core, but this can be changed with the `-d` command line argument. +""" def main(): parser = argparse.ArgumentParser(description="Build the Betrusted SoC") parser.add_argument( @@ -28,6 +45,7 @@ def main(): outfile.write("#[allow(dead_code)]\n") outfile.write("#[link_section=\".fontdata\"]\n") outfile.write("#[no_mangle]\n") + outfile.write("#[used]\n") copy = False for line in infile: if line.strip() == "/// Packed glyph pattern data.": diff --git a/loader/src/main.rs b/loader/src/main.rs index 20f596a77..6781e3c9e 100644 --- a/loader/src/main.rs +++ b/loader/src/main.rs @@ -367,7 +367,6 @@ extern "C" { entrypoint: usize, stack: usize, debug: bool, - keep: u32, ) -> !; } @@ -1045,11 +1044,6 @@ fn boot_sequence(args: KernelArguments, _signature: u32) -> ! { println!(" Regular @ {:08x}", fonts::regular::DATA_REGULAR.as_ptr() as u32); println!(" Small @ {:08x}", fonts::small::DATA_SMALL.as_ptr() as u32); println!(" Bold @ {:08x}", fonts::bold::DATA_BOLD.as_ptr() as u32); - let keep_fonts = fonts::hanzi::DATA_HANZI.as_ptr() as u32 + - fonts::emoji::DATA_EMOJI.as_ptr() as u32 + - fonts::regular::DATA_REGULAR.as_ptr() as u32 + - fonts::small::DATA_SMALL.as_ptr() as u32 + - fonts::bold::DATA_BOLD.as_ptr() as u32; // The MMU should be set up now, and memory pages assigned to their // respective processes. @@ -1072,7 +1066,6 @@ fn boot_sequence(args: KernelArguments, _signature: u32) -> ! { cfg.processes[0].entrypoint, cfg.processes[0].sp, cfg.debug, - keep_fonts, ); } } diff --git a/services/graphics-server/src/main.rs b/services/graphics-server/src/main.rs index 3a96a9e51..426118595 100644 --- a/services/graphics-server/src/main.rs +++ b/services/graphics-server/src/main.rs @@ -31,20 +31,20 @@ fn draw_boot_logo(display: &mut XousDisplay) { #[cfg(target_os = "none")] fn map_fonts() { - info!("GFX: mapping fonts"); + //info!("GFX: mapping fonts"); // this maps an extra page if the total length happens to fall on a 4096-byte boundary, but this is ok // because the reserved area is much larger let fontlen: u32 = ((fontmap::FONT_TOTAL_LEN as u32) & 0xFFFF_F000) + 0x1000; - info!("GFX: requesting map of length 0x{:08x} at 0x{:08x}", fontlen, fontmap::FONT_BASE); + //info!("GFX: requesting map of length 0x{:08x} at 0x{:08x}", fontlen, fontmap::FONT_BASE); let fontregion = xous::syscall::map_memory( xous::MemoryAddress::new(fontmap::FONT_BASE), None, fontlen as usize, xous::MemoryFlags::R, ).expect("GFX: couldn't map fonts"); - info!("GFX: font base at 0x{:08x}, len of 0x{:08x}", usize::from(fontregion.addr), usize::from(fontregion.size)); + info!("GFX: font base at virtual 0x{:08x}, len of 0x{:08x}", usize::from(fontregion.addr), usize::from(fontregion.size)); - info!("GFX: mapping regular font to 0x{:08x}", usize::from(fontregion.addr) + fontmap::REGULAR_OFFSET as usize); + //info!("GFX: mapping regular font to 0x{:08x}", usize::from(fontregion.addr) + fontmap::REGULAR_OFFSET as usize); blitstr::map_font(blitstr::GlyphData::Emoji((usize::from(fontregion.addr) + fontmap::EMOJI_OFFSET) as usize)); blitstr::map_font(blitstr::GlyphData::Hanzi((usize::from(fontregion.addr) + fontmap::HANZI_OFFSET) as usize)); blitstr::map_font(blitstr::GlyphData::Regular((usize::from(fontregion.addr) + fontmap::REGULAR_OFFSET) as usize));