Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
lupyuen committed Feb 20, 2023
1 parent bb53827 commit cd03095
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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...

Expand Down
21 changes: 16 additions & 5 deletions nuttx/README.md
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -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
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down

0 comments on commit cd03095

Please sign in to comment.