Scratching debug tool for anc poking

This commit is contained in:
Ben V. Brown 2023-07-04 22:56:35 +10:00 committed by Rudis Muiznieks
parent ced171a5c5
commit f12e474b2f
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
4 changed files with 256 additions and 0 deletions

1
dev_tools/anc_decoder/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
target/

119
dev_tools/anc_decoder/Cargo.lock generated Normal file
View File

@ -0,0 +1,119 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "anc_decoder"
version = "0.1.0"
dependencies = [
"declio",
]
[[package]]
name = "darling"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c"
dependencies = [
"darling_core",
"darling_macro",
]
[[package]]
name = "darling_core"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
dependencies = [
"darling_core",
"quote",
"syn",
]
[[package]]
name = "declio"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae2d0ab09a05314050f1b66e78c2497af54dad2335e15b815f208d1594c85264"
dependencies = [
"declio_derive",
]
[[package]]
name = "declio_derive"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5eb284008990d1298ed56c741ca8823481789d72ff055031bf21ceaeb61c0053"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "fnv"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "ident_case"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
[[package]]
name = "proc-macro2"
version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105"
dependencies = [
"proc-macro2",
]
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "unicode-ident"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22049a19f4a68748a168c0fc439f9516686aa045927ff767eca0a85101fb6e73"

View File

@ -0,0 +1,9 @@
[package]
name = "anc_decoder"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
declio = "0.2.0"

View File

@ -0,0 +1,127 @@
use declio::ctx::Endian;
use declio::{Decode, Encode};
use std::fs::File;
use std::io::Read;
//Super experimental dumb tooling for parsing out the ANC data
// This is not production code, expect panics
const AUDIO_START: usize = 0x003EE000;
const AUDIO_LEN: usize = 16;
const AUD_IIR_NUM: usize = 8;
const AUD_COEF_LEN: usize = 0;
#[derive(Debug, PartialEq, Encode, Decode, Copy, Clone, Default)]
struct AudSectionHead {
#[declio(ctx = "Endian::Little")]
magic: u16,
#[declio(ctx = "Endian::Little")]
vesrion: u16,
#[declio(ctx = "Endian::Little")]
crc: u32,
#[declio(ctx = "Endian::Little")]
reserved0: u32,
#[declio(ctx = "Endian::Little")]
reserved1: u32,
}
#[derive(Debug, PartialEq, Encode, Decode, Copy, Clone, Default)]
struct AudSectionBodyIdent {
anc_ver: [u8; 16], // These are actually char* but honestly doesnt matter as seem to always be 0x00
batch_info: [u8; 16], // These are actually char* but honestly doesnt matter as seem to always be 0x00
serial: [u8; 16], // These are actually char* but honestly doesnt matter as seem to always be 0x00
}
#[derive(Debug, PartialEq, Encode, Decode, Copy, Clone, Default)]
struct anc_iir_coefs {
#[declio(ctx = "Endian::Little")]
coef_b: [i32; 3],
#[declio(ctx = "Endian::Little")]
coef_a: [i32; 3],
}
#[derive(Debug, PartialEq, Encode, Decode, Copy, Clone, Default)]
struct aud_item {
#[declio(ctx = "Endian::Little")]
total_gain: u32,
#[declio(ctx = "Endian::Little")]
iir_bypass_flag: u16,
#[declio(ctx = "Endian::Little")]
iir_counter: u16,
iir_coef: [anc_iir_coefs; AUD_IIR_NUM],
// #if (AUD_SECTION_STRUCT_VERSION == 1)
// #[declio(ctx = "Endian::Little")]
// fir_bypass_flag: u16,
// #[declio(ctx = "Endian::Little")]
// fir_len: u16,
// #[declio(ctx = "Endian::Little")]
// fir_coef: [i16; AUD_COEF_LEN],
// pos_tab: [i8; 16],
// #elif (AUD_SECTION_STRUCT_VERSION == 2)
#[declio(ctx = "Endian::Little")]
reserved_for_drc: [u32; 32],
// #elif (AUD_SECTION_STRUCT_VERSION == 3)
// #endif
#[declio(ctx = "Endian::Little")]
reserved1: i16,
dac_gain_offset: i8, // in qdb (quater of dB)
adc_gain_offset: i8, // in qdb (quater of dB)
}
#[derive(Debug, PartialEq, Encode, Decode, Copy, Clone, Default)]
struct struct_anc_cfg {
//
anc_cfg_ff_l: aud_item,
anc_cfg_ff_r: aud_item,
anc_cfg_fb_l: aud_item,
anc_cfg_fb_r: aud_item,
}
#[derive(Debug, PartialEq, Encode, Decode, Copy, Clone, Default)]
struct pctool_struct_anc_cfg {
//
anc_cfg: [struct_anc_cfg; 2],
}
#[derive(Debug, PartialEq, Encode, Decode, Copy, Clone, Default)]
struct AudSectionBodyConfig {
anc_config_arr: [pctool_struct_anc_cfg; 4],
}
#[derive(Debug, PartialEq, Encode, Decode, Copy, Clone, Default)]
struct AudSectionBody {
anc_ident: AudSectionBodyIdent,
anc_config: AudSectionBodyConfig,
}
#[derive(Debug, PartialEq, Encode, Decode, Copy, Clone, Default)]
struct PctoolAudSection {
header: AudSectionHead,
body: AudSectionBody,
}
fn main() {
println!("Super dumb anc firmware details dumper");
println!("By Ralim <ralim@ralimtek.com>");
println!("Reading firmware.bin");
let file_contents = get_firmware_file("firmware.bin");
println!("Running decoder");
let dummy_init: PctoolAudSection = PctoolAudSection::default();
let dummy_serialised = declio::to_bytes(dummy_init).unwrap();
let decoded: PctoolAudSection =
declio::from_bytes(&file_contents[AUDIO_START..AUDIO_START + dummy_serialised.len()])
.expect("decode failed");
println!("Decoded {:#?}", decoded)
}
fn get_firmware_file(filename: &str) -> Vec<u8> {
let mut f = File::open(&filename).expect("no file found");
let mut buffer = Vec::new();
// read the whole file
f.read_to_end(&mut buffer).expect("could not read file");
buffer
}