diff options
Diffstat (limited to 'scripts/perl/dig.pl')
| -rwxr-xr-x | scripts/perl/dig.pl | 197 |
1 files changed, 197 insertions, 0 deletions
diff --git a/scripts/perl/dig.pl b/scripts/perl/dig.pl new file mode 100755 index 0000000..a7f7f08 --- /dev/null +++ b/scripts/perl/dig.pl @@ -0,0 +1,197 @@ +#!/usr/bin/perl + +# Copyright 2012-2022, BlueFANG + +use strict; +use warnings; +use Carp; +use feature 'say'; +use File::Find; +use Getopt::Long; +use Pod::Usage; +use Data::Dumper; +use Cwd; + +my $man = 0; +my $help = 0; +my $initem = ''; +my @hex_addresses = (); +my $print_consts = ''; +my $print_structs = ''; +my $print_reg_map = ''; +my $print_long = ''; +my $reg_idx = 8; +my $verbose = ''; +my $searchdir = "$ENV{HOME}/projects/bk_ble/sdk/driver/ble"; +my $db_file = ''; +my $const_name = ''; +my $preamble = <<EOF; +#include "sys_config.h" +#include "param_config.h" +#include "param_config.h" +#include "rwapp_config.h" +#include "rwip_config.h" +#include "rwprf_config.h" +#include "kernel_config.h" +#include "rwble_hl_config.h" +#include "rwble_config.h" + +#include "rwip.h" +#include "ble_reg_access.h" +#include "reg_blecore.h" +#include "em_map_ble.h" +#include "reg_ble_em_cs.h" +#include "reg_ble_em_rx_buffer.h" +#include "reg_ble_em_rx_desc.h" +#include "reg_ble_em_tx_buffer_cntl.h" +#include "reg_ble_em_tx_desc.h" +#include "reg_ble_em_tx_buffer_data.h" +#include "ecc_p256.h" +#include "llm.h" +#include "llm_util.h" +#include "lld.h" +#include "lld_evt.h" +#include "lld_pdu.h" +#include "lld_util.h" +#include "RomCallFlash.h" +#include "em_buf.h" +#include "ea.h" +#include "common_utils.h" +#include "common_hci.h" +#include "common_llcp.h" +#include "%s"; + +#define diag_const(name,format) __asm__("###CT(" format ") " #name " = %%c0" : :\\ + "i" (__builtin_constant_p(name) ? name : 0x0BADDEED) ); + +void diagnostic_out( void ) { +EOF + + +my $postamble = <<EOF; +#if defined(%s) +#define f "m" +#else +#define f "c" +#endif + diag_const(%s,f); +}; + +EOF + +#Getopt::Long::Configure ("bundling"); # to allow -abc to set a, b, and c + +GetOptions ("help|?" => \$help, + man => \$man, + verbose => \$verbose, + "regname=s" => sub { + if ($verbose) { + print "Pushing name $_[1]\n"; + } + push @hex_addresses, hex $_[1]; + }, + "db-file=s" => \$db_file, + "const=s" => \$const_name, + "dir=s" => \$searchdir, + ) or pod2usage(2); + +pod2usage(-exitval => 0, -verbose => 1) if $help; +pod2usage(-exitval => 0, -verbose => 2) if $man; + +sub get_header { + my $dir = $File::Find::dir; + my $file = $_; + + if ( $file =~ m/.*\.h/ ) { + print "Header: $file\n"; + extract_consts($file); + } +} + +$SIG{INT} = 'quit_all'; +my %const_hash = (); + +sub extract_consts($) { + + my $file = shift; + + open HFILE, $file or die "Where did $file go?\n"; + + while(<HFILE>) { + + my $line = $_; + + while ( $line =~ m/\b([A-Z_][A-Z_0-9]*)\b/g ) { + my $cname = $1; + next if exists $const_hash{$cname}; + $const_hash{$cname} = $file; + open INFILE, ">$ARGV[0]" or die "Cannot open output file $ARGV[0]\n"; + + printf INFILE $preamble, $file; + printf INFILE $postamble, $cname, $cname; + + close INFILE; + + my $sysout; + open my $fh, '>>', "output" or die; + eval { + my $cur_dir = cwd; + chdir "$ENV{HOME}/projects/bk_ble"; + close(STDERR); + + my $out; + open(STDERR, ">>", \$out) or do { print $fh, "failed to open STDERR ($!)\n"; die }; + + $sysout = system("make", "-s", "constant_list"); + + chdir $cur_dir; + }; + + if ($sysout == 0) { + + my $gen_assembly = "$ENV{HOME}/projects/bk_ble/build/usr/ble_tst/src/diagnostic1.S"; + open DIAGCONST, $gen_assembly + or die "Cannot find .S file $gen_assembly\n"; + + while (<DIAGCONST>) { + + if (/^[^#]*###CT\(([^()]*)\)\s*(.*\S)\s*=\s*([0-9]+)$/) { + if ($db_file) { + print DBFILE "$2=$3\{$file\}{$1}\n"; + } + print "$2=$3\n"; + } + } + + if ($cname eq $const_name) { + print "Constant $cname added\n"; + } + + } elsif ($sysout & 0xFF) {# died from a signal so probably was meant for us instead + print "Interrupted\n"; + die; + } else { + if ($cname eq $const_name) { + print "Constant $cname failed to process\n"; + } + } + } + + } + + close HFILE; + +} + +sub quit_all{ # in case one is actually quick enough + print "Interrupted\n"; + close DBFILE if $db_file; + die; +} + +if ( $db_file ) { + open DBFILE, ">$db_file" or die "Cannot open the db file $db_file\n"; +} + +find(\&get_header, $searchdir); +close DBFILE; |
