Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement "exported" variables allowing to pull data from firmware. #20

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

plaes
Copy link
Contributor

@plaes plaes commented Dec 22, 2023

This implements basic groundwork for pulling data from firmware.

Demo:

 INFO  teleprobe::run > Found 2 exported variables: [
    0x2000c9a0,
    0x2000c9e0,
]
 INFO  teleprobe::run > Found match for addr 536922592 -> "_ZN5timer15_TELEPROBE_VAR217hd7ca27c6503da4d3E"
 INFO  teleprobe::run > Found match for addr 536922528 -> "_TELEPROBE_VAR1"
 INFO  teleprobe::run > run_from_ram: true
 INFO  teleprobe::run > flashing program...
 INFO  teleprobe::run > flashing done!
 INFO  device         > 0.101898 Test OK
 INFO  teleprobe::run > Found: _TELEPROBE_VAR1 -> yesyesno
 INFO  teleprobe::run > Found: _ZN5timer15_TELEPROBE_VAR217hd7ca27c6503da4d3E -> nonoyes!

Firmware-side changes (some "sugaring" would be eventually nice, but it works):

#[repr(C)]
union TPVar {
    f1: [u8; 64],
    f2: u32,
}

#[no_mangle]
static mut _TELEPROBE_VAR1: TPVar = TPVar { f1: [0; 64] };

// This works as well...
static mut _TELEPROBE_VAR2: TPVar = TPVar { f1: [0; 64] };

#[repr(C)]
pub struct TPPtr(*const u32);
unsafe impl Sync for TPPtr {}

#[link_section = ".teleprobe.export"]
#[used]
#[no_mangle]
static _TELEPROBE_EXPORTS: [TPPtr; 2] = [
    TPPtr(unsafe { &_TELEPROBE_VAR1.f2 as *const u32 }),
    TPPtr(unsafe { &_TELEPROBE_VAR2.f2 as *const u32 }),
];

fn main(...) {
    // Update our variables with custom data:
    unsafe {
        let data = b"yesyesno";
        _TELEPROBE_VAR1.f1[..data.len()].copy_from_slice(data);
        let data = b"nonoyes!";
        _TELEPROBE_VAR2.f1[..data.len()].copy_from_slice(data);

        info!(
            "new: _TELEPROBE_VAR1: ptr = {:?}, val = {:?} ",
            &mut _TELEPROBE_VAR1.f1 as *mut _, _TELEPROBE_VAR1.f1
        );
    }
}

@Dirbaio
Copy link
Member

Dirbaio commented Jan 5, 2024

Thanks for the PR! Unfortunately, I feel this is outside teleprobe's scope. Scope is mainly running CI tests, where the firmware outputs just yes/no.

Production mass flashing is out of scope. If we decided it's in scope, there's a lot more features we'd have to have until this becomes a good mass flashing tool, and I just don't have the bandwidth for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants