Comments (10)
So I think I include the file with include_bytes! and I also tried to print to console but failed hahah :) no_std is a huge constraint so I don't know how to convert &[u8;x](byte slice array I think) to str without std crate (just as a debug log). Any advice? IDK if I should keep trying to print this because that was like a side/debug task or shall we continue with my only 1 new line of code :D.
from pinetime-rust-mynewt.
No worries :-) We can use semihosting to show debug output. I'll post the steps in a while...
from pinetime-rust-mynewt.
To dump a binary array to Semihosting Log
Call console::dump
...
https://github.com/lupyuen/pinetime-rust-mynewt/blob/master/rust/mynewt/src/sys/console.rs#L67-L68
/// Write "length" number of bytes from "buffer" to the output buffer in hex format.
pub fn dump(buffer: *const u8, len: u32) { ...
Remember to call console::flush
after console::dump
Semihosting Logging is really slow, so perhaps we can dump the first 16 bytes and the last 16 bytes of the array.
Or print a crypto hash of the array. We'll probably need this for integrity checking.
To enable Semihosting Log
Semihosting is disabled by default. To enable it, edit
https://github.com/lupyuen/pinetime-rust-mynewt/blob/master/targets/nrf52_my_sensor/pkg.yml
And change the line...
- -DDISABLE_SEMIHOSTING # Uncomment to disable Arm Semihosting
To...
# - -DDISABLE_SEMIHOSTING # Uncomment to disable Arm Semihosting
And your debug messages will appear in the Remote PineTime Log Channel:
https://t.me/remotepinetimelog
Lemme know if you're not sure of anything thanks :-)
from pinetime-rust-mynewt.
Thanks for the instructions, pretty clear. Here is the commit 41a5e8a and snippet of the semihosting log validating that the file is actually being loaded, I displayed the first and last 16 bytes, seems ok. I learned a little about references in Rust :).
One question: What crate in the repo has the crypto hash functionality?
what's next :D?
from pinetime-rust-mynewt.
Looks great! Can you find something no_std from the Rust Core Library that computes hashes? If there isn't any, then try crates.io?
Lemme post more steps for writing the bootloader to flash memory in a while...
from pinetime-rust-mynewt.
To write the bootloader to Flash ROM we need to call the Mynewt functions hal_flash_erase and hal_flash_write like this...
hal_flash_erase( // Erase...
0, // Internal Flash ROM
(uint32_t) relocated_vector_table, // At the relocated address
0x100 // Assume that we erase an entire page
);
hal_flash_write( // Write...
0, // Internal Flash ROM
(uint32_t) relocated_vector_table, // To the relocated address
vector_table, // From the original address
0x100 // Assume that we copy an entire page
);
Mynewt doc for hal_flash_erase: https://mynewt.apache.org/latest/os/modules/hal/hal_flash/hal_flash.html#c.hal_flash_erase
Mynewt doc for hal_flash_write: https://mynewt.apache.org/latest/os/modules/hal/hal_flash/hal_flash.html#c.hal_flash_write
The first parameter for hal_flash_erase and hal_flash_write should be 0, since we're writing to Internal Flash ROM.
The last parameter for hal_flash_erase and hal_flash_write should be 0x1000 (instead of 0x100), since we can write at most 4 KB in a sector at a time.
For NOR Flash we must always erase a sector before writing. So inside a loop we call hal_flash_erase then hal_flash_write for every 4 KB sector.
We will need to declare the Mynewt functions as...
extern {
hal_flash_erase(flash_id: u8, address: u32, num_bytes: u32) -> i32;
hal_flash_write(flash_id: u8, address: u32, src: *core::ffi::c_void, num_bytes: u32) -> i32;
}
This article may be helpful:
https://lupyuen.github.io/pinetime-rust-mynewt/articles/spiflash
from pinetime-rust-mynewt.
My build keeps failing :( https://github.com/Killerpug/pinetime-rust-mynewt/commit/5ebc2bfdf5f107ade04c83bbc83e07379fd6424e, here is what the log says about not finding the functions https://github.com/Killerpug/pinetime-rust-mynewt/runs/1317090619?check_suite_focus=true. what's happening?
from pinetime-rust-mynewt.
The code I gave you was in C... we need to convert to Rust. You need help with that?
from pinetime-rust-mynewt.
Yes please, I thought it was just using the C functions in Rust code. How can you convert those into Rust :o? I appreciate any help :)
from pinetime-rust-mynewt.
Hi: Thank you so much for helping out :-) I'm sorry I have to drop this Bootloader Enhancement due to a health bug (I have hypertension)
Meanwhile I'll be slowing working on 2 projects (that are less stressful)...
If you're keen on learning Embedded Rust, you might wanna follow the two projects above.
Thanks again for all your support :-)
from pinetime-rust-mynewt.
Related Issues (15)
- install-pi.sh stops on non-existent path HOT 4
- build-app.sh is missing some libraries HOT 2
- build-app.sh can't build cortex-m HOT 9
- Missing file target/nrf52.cfg HOT 4
- MCUBoot built by GitHub Actions doesn't boot HOT 1
- Send bootloader version to application HOT 3
- Bootloader does not start properly after a watchdog reset/incoherent SPI state HOT 15
- Tickle Watchdog to prevent reboot after 7 seconds HOT 3
- [FR] OTA istallation HOT 1
- Higher consumption on nRF52832 when boot from mcuboot HOT 12
- Build failes on Build Rust app HOT 2
- Bluetooth adapter is not available
- Broken build
- How to activate bluetooth on pinetime after flashing mynewt HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pinetime-rust-mynewt.