@@ -47,20 +47,20 @@ impl DebugProbe for Fe310JLinkDebugProbe {
47
47
let exe = exe. to_owned ( ) ;
48
48
Box :: pin ( async move {
49
49
// Extract loadable sections
50
- let sections = read_loaded_region_from_elf ( & exe)
50
+ let LoadableCode { regions , entry } = read_elf ( & exe)
51
51
. await
52
52
. map_err ( Fe310JLinkDebugProbeGetOutputError :: ProcessElf ) ?;
53
53
54
- // Extract loadable sections to separate binary files
54
+ // Extract loadable regions to separate binary files
55
55
let tempdir = TempDir :: new ( "constance_test_runner" )
56
56
. map_err ( Fe310JLinkDebugProbeGetOutputError :: CreateTempDir ) ?;
57
- let section_files: Vec < _ > = ( 0 ..sections . len ( ) )
57
+ let section_files: Vec < _ > = ( 0 ..regions . len ( ) )
58
58
. map ( |i| {
59
59
let name = format ! ( "{}.bin" , i) ;
60
60
tempdir. path ( ) . join ( & name)
61
61
} )
62
62
. collect ( ) ;
63
- for ( path, ( data, _) ) in section_files. iter ( ) . zip ( sections . iter ( ) ) {
63
+ for ( path, ( data, _) ) in section_files. iter ( ) . zip ( regions . iter ( ) ) {
64
64
log:: debug!( "Writing {} byte(s) to '{}'" , data. len( ) , path. display( ) ) ;
65
65
tokio:: fs:: write ( & path, data)
66
66
. await
@@ -69,10 +69,12 @@ impl DebugProbe for Fe310JLinkDebugProbe {
69
69
70
70
// Generate commands for `JLinkExe`
71
71
let mut cmd = String :: new ( ) ;
72
- for ( path, ( _, offset) ) in section_files. iter ( ) . zip ( sections. iter ( ) ) {
72
+ writeln ! ( cmd, "r" ) . unwrap ( ) ;
73
+ for ( path, ( _, offset) ) in section_files. iter ( ) . zip ( regions. iter ( ) ) {
73
74
writeln ! ( cmd, "loadbin \" {}\" 0x{:08x}" , path. display( ) , offset) . unwrap ( ) ;
74
75
}
75
- writeln ! ( cmd, "rnh" ) . unwrap ( ) ;
76
+ writeln ! ( cmd, "setpc 0x{:x}" , entry) . unwrap ( ) ;
77
+ writeln ! ( cmd, "g" ) . unwrap ( ) ;
76
78
writeln ! ( cmd, "q" ) . unwrap ( ) ;
77
79
78
80
// Flash the program and reset the chip
@@ -99,14 +101,11 @@ impl DebugProbe for Fe310JLinkDebugProbe {
99
101
. await
100
102
. map_err ( Fe310JLinkDebugProbeGetOutputError :: Flash ) ?;
101
103
102
- log:: debug!( "Waiting for 2 seconds" ) ;
103
-
104
- // Red-V's bootloader doesn't start the user program right away
105
- // so wait for some time. The stale RTT data from a previous run
106
- // might still be there until the new startup code zero-fills the
107
- // memory.
108
- tokio:: time:: delay_for ( std:: time:: Duration :: from_secs ( 2 ) ) . await ;
104
+ log:: debug!( "Waiting for 1 seconds" ) ;
109
105
106
+ // The stale RTT data from a previous run might still be there until
107
+ // the new startup code zero-fills the memory.
108
+ tokio:: time:: delay_for ( std:: time:: Duration :: from_secs ( 1 ) ) . await ;
110
109
log:: debug!( "Opening the debug probe using `probe-rs`" ) ;
111
110
112
111
// Open the probe using `probe-rs`
@@ -150,8 +149,15 @@ enum ProcessElfError {
150
149
Parse ( #[ source] goblin:: error:: Error ) ,
151
150
}
152
151
152
+ struct LoadableCode {
153
+ /// The regions to be loaded onto the target.
154
+ regions : Vec < ( Vec < u8 > , u64 ) > ,
155
+ /// The entry point.
156
+ entry : u64 ,
157
+ }
158
+
153
159
/// Read the specified ELF file and return regions to be loaded onto the target.
154
- async fn read_loaded_region_from_elf ( exe : & Path ) -> Result < Vec < ( Vec < u8 > , u64 ) > , ProcessElfError > {
160
+ async fn read_elf ( exe : & Path ) -> Result < LoadableCode , ProcessElfError > {
155
161
let elf_bytes = tokio:: fs:: read ( & exe) . await . map_err ( ProcessElfError :: Read ) ?;
156
162
let elf = goblin:: elf:: Elf :: parse ( & elf_bytes) . map_err ( ProcessElfError :: Parse ) ?;
157
163
@@ -170,7 +176,10 @@ async fn read_loaded_region_from_elf(exe: &Path) -> Result<Vec<(Vec<u8>, u64)>,
170
176
} )
171
177
. collect ( ) ;
172
178
173
- Ok ( regions)
179
+ Ok ( LoadableCode {
180
+ regions,
181
+ entry : elf. entry ,
182
+ } )
174
183
}
175
184
176
185
struct OutputReader {
0 commit comments