From cd030954c2ace4cf0207872f275abc3ffb7343c6 Mon Sep 17 00:00:00 2001 From: Lee Lup Yuen Date: Mon, 20 Feb 2023 16:32:52 +0800 Subject: [PATCH] Clean up --- README.md | 17 +++++++++-------- nuttx/README.md | 21 ++++++++++++++++----- src/main.rs | 7 ++++--- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4442512..53b95a3 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ TODO: What happens when we run [Apache NuttX RTOS for PinePhone](nuttx) in Unico ```rust // Arm64 Memory Address where emulation starts - const ADDRESS: u64 = 0x40080000; + const ADDRESS: u64 = 0x4008_0000; // Arm64 Machine Code for the above address let arm64_code = include_bytes!("../nuttx/nuttx.bin"); @@ -154,22 +154,23 @@ TODO: What happens when we run [Apache NuttX RTOS for PinePhone](nuttx) in Unico ).expect("failed to initialize Unicorn instance"); let emu = &mut unicorn; - // Map 2 MB memory at the above address for Arm64 Machine Code + // Map executable memory at the above address for Arm64 Machine Code emu.mem_map( - ADDRESS, // Address - 2 * 1024 * 1024, // Size - Permission::ALL // Read, Write and Execute Access + ADDRESS, // Address + arm64_code.len(), // Size + Permission::ALL // Read, Write and Execute Access ).expect("failed to map code page"); - // Map 16 MB at 0x01000000 for Memory-Mapped I/O by Allwinner A64 Peripherals + // Map 16 MB at 0x0100 0000 for Memory-Mapped I/O by Allwinner A64 Peripherals + // https://github.com/apache/nuttx/blob/master/arch/arm64/src/a64/hardware/a64_memorymap.h#L33-L51 emu.mem_map( - 0x01000000, // Address + 0x0100_0000, // Address 16 * 1024 * 1024, // Size Permission::READ | Permission::WRITE // Read and Write Access ).expect("failed to map memory mapped I/O"); ``` -[(Source)](https://github.com/lupyuen/pinephone-emulator/blob/main/src/main.rs#L6-L31) +[(Source)](https://github.com/lupyuen/pinephone-emulator/blob/main/src/main.rs#L6-L32) Here's the output... diff --git a/nuttx/README.md b/nuttx/README.md index 7345da6..3c66707 100644 --- a/nuttx/README.md +++ b/nuttx/README.md @@ -1,20 +1,31 @@ # Apache NuttX RTOS for PinePhone -See ["Build Apache NuttX RTOS for PinePhone"](https://lupyuen.github.io/articles/lvgl2#appendix-build-apache-nuttx-rtos-for-pinephone) +See the articles... -Apache NuttX RTOS for PinePhone was built with these commands... +- ["NuttX RTOS for PinePhone: What is it?"](https://lupyuen.github.io/articles/what) + +- ["Build Apache NuttX RTOS for PinePhone"](https://lupyuen.github.io/articles/lvgl2#appendix-build-apache-nuttx-rtos-for-pinephone) + +Apache NuttX RTOS for PinePhone was built with... ```bash +## Download NuttX Source Code mkdir nuttx cd nuttx git clone https://github.com/apache/nuttx nuttx git clone https://github.com/apache/nuttx-apps apps +## Configure NuttX for PinePhone NSH Minimal Build cd nuttx tools/configure.sh pinephone:nsh + +## Build NuttX make +## Save the Build Config cp .config nuttx.config + +## Generate the Arm64 Disassembly aarch64-none-elf-objdump \ -t -S --demangle --line-numbers --wide \ nuttx \ @@ -24,8 +35,8 @@ aarch64-none-elf-objdump \ Which produces... -- [nuttx.bin](nuttx.bin): Binary image for Apache NuttX +- [nuttx.bin](nuttx.bin): Binary image for Apache NuttX RTOS - (Address: `0x40080000`, Size: 279 KB) + (Address: `0x4008` `0000`, Size: 279 KB) -- [nuttx.S](nuttx.S): Arm64 Disassembly for Apache NuttX +- [nuttx.S](nuttx.S): Arm64 Disassembly for Apache NuttX RTOS diff --git a/src/main.rs b/src/main.rs index 78ec7b9..714b62a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use unicorn_engine::unicorn_const::{Arch, HookType, MemType, Mode, Permission}; /// Emulate some Arm64 Machine Code fn main() { // Arm64 Memory Address where emulation starts - const ADDRESS: u64 = 0x40080000; + const ADDRESS: u64 = 0x4008_0000; // Arm64 Machine Code for the above address let arm64_code = include_bytes!("../nuttx/nuttx.bin"); @@ -23,9 +23,10 @@ fn main() { Permission::ALL // Read, Write and Execute Access ).expect("failed to map code page"); - // Map 16 MB at 0x01000000 for Memory-Mapped I/O by Allwinner A64 Peripherals + // Map 16 MB at 0x0100 0000 for Memory-Mapped I/O by Allwinner A64 Peripherals + // https://github.com/apache/nuttx/blob/master/arch/arm64/src/a64/hardware/a64_memorymap.h#L33-L51 emu.mem_map( - 0x01000000, // Address + 0x0100_0000, // Address 16 * 1024 * 1024, // Size Permission::READ | Permission::WRITE // Read and Write Access ).expect("failed to map memory mapped I/O");