From 9c6e7ce9df2a9be35a6319034e52d9605e8e0adf Mon Sep 17 00:00:00 2001 From: Dave Marples Date: Sun, 25 Aug 2024 17:33:54 +0100 Subject: [PATCH] Add support for TPIU encoded orbflow channel 1 --- Src/oflow.c | 4 +-- Src/orbuculum.c | 72 ++++++++++++++++++++++++------------------- Support/gdbtrace.init | 1 + 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/Src/oflow.c b/Src/oflow.c index 8f1330a3..48bb463b 100644 --- a/Src/oflow.c +++ b/Src/oflow.c @@ -105,8 +105,8 @@ static void _pumpcb( struct Frame *p, void *param ) } void OFLOWPump( struct OFLOW *t, const uint8_t *incoming, int len, - void ( *packetRxed )( struct OFLOWFrame *p, void *param ), - void *param ) + void ( *packetRxed )( struct OFLOWFrame *p, void *param ), + void *param ) /* Assemble this packet into a complete frame and call back */ diff --git a/Src/orbuculum.c b/Src/orbuculum.c index 169a95b4..cb590a8a 100644 --- a/Src/orbuculum.c +++ b/Src/orbuculum.c @@ -483,7 +483,7 @@ bool _processOptions( int argc, char *argv[], struct RunTime *r ) case 'm': r->options->intervalReportTime = atoi( optarg ); - if ( r->options->intervalReportTime<100 ) + if ( r->options->intervalReportTime < 100 ) { genericsReport( V_ERROR, "intervalReportTime is out of range" EOL ); return false; @@ -759,7 +759,7 @@ void _checkInterval( void *params ) if ( tnow - r->tagCount[i].ts < LAST_TAG_SEEN_TIME_NS ) { - if ( !r->tagCount[i].hasHandler ) + if ( ( !r->tagCount[i].hasHandler ) && r->options->useTPIU ) { genericsPrintf( C_NOCHAN" [%d:" "%3d%%] " C_RESET, i, w / 10 ); } @@ -828,8 +828,6 @@ static void _purgeBlock( struct RunTime *r, bool createOFLOW ) h++; } - - _checkInterval( r ); } // ==================================================================================================== static void _TPIUpacketRxed( enum TPIUPumpEvent e, struct TPIUPacket *p, void *param ) @@ -913,6 +911,12 @@ static void _OFLOWpacketRxed( struct OFLOWFrame *p, void *param ) { genericsReport( V_WARN, "Bad packet received" EOL ); } + else if ( ( r->options->useTPIU ) && ( h->channel == DEFAULT_ITM_STREAM ) ) + { + /* Deal with the bizzare combination of OFLOW and TPIU in channel 1 */ + /* Accounting will be done in TPIUPump2 */ + TPIUPump2( &r->t, p->d, p->len, _TPIUpacketRxed, r ); + } else { /* Account for this reception */ @@ -981,8 +985,8 @@ static void _processNonOFLOWBlock( struct RunTime *r, ssize_t fillLevel, uint8_t while ( fillLevel ) { OFLOWEncode( DEFAULT_ITM_STREAM, 0, b, - ( fillLevel < OFLOW_MAX_PACKET_LEN ) ? fillLevel : OFLOW_MAX_PACKET_LEN, - &oflowOtg ); + ( fillLevel < OFLOW_MAX_PACKET_LEN ) ? fillLevel : OFLOW_MAX_PACKET_LEN, + &oflowOtg ); nwclientSend( r->oflowHandler, oflowOtg.len, oflowOtg.d ); b += ( fillLevel < OFLOW_MAX_PACKET_LEN ) ? fillLevel : OFLOW_MAX_PACKET_LEN; fillLevel -= ( fillLevel < OFLOW_MAX_PACKET_LEN ) ? fillLevel : OFLOW_MAX_PACKET_LEN; @@ -996,36 +1000,45 @@ static void _handleBlock( struct RunTime *r, ssize_t fillLevel, uint8_t *buffer /* Handle an incoming block from any source in either 'conventional' or orbflow format */ { - genericsReport( V_DEBUG, "RXED Packet of %d bytes%s" EOL, fillLevel, ( r->options->intervalReportTime ) ? EOL : "" ); - - if ( r->opFileHandle ) + if ( fillLevel ) { - if ( write( r->opFileHandle, buffer, fillLevel ) <= 0 ) + genericsReport( V_DEBUG, "RXED Packet of %d bytes%s" EOL, fillLevel, ( r->options->intervalReportTime ) ? EOL : "" ); + + if ( r->opFileHandle ) { - genericsExit( -3, "Writing to file failed" EOL ); + if ( write( r->opFileHandle, buffer, fillLevel ) <= 0 ) + { + genericsExit( -3, "Writing to file failed" EOL ); + } } - } - if ( r->usingOFLOW ) - { - if ( r->options->intervalReportTime ) + if ( r->usingOFLOW ) { - /* We need to decode this so we can get the stats out of it .. we don't bother if we don't need stats */ - OFLOWPump( &r->oflow, buffer, fillLevel, _OFLOWpacketRxed, r ); + if ( r->options->intervalReportTime ) + { + /* We need to decode this so we can get the stats out of it .. we don't bother if we don't need stats */ + OFLOWPump( &r->oflow, buffer, fillLevel, _OFLOWpacketRxed, r ); + } + + /* ...and reflect this packet to the outgoing OFLOW channels, if we don't need to reconstruct them */ + if ( !r->options->useTPIU ) + { + nwclientSend( r->oflowHandler, fillLevel, buffer ); + } + } + else + { + _processNonOFLOWBlock( r, fillLevel, buffer ); } - /* ...and reflect this packet to the outgoing OFLOW channels */ - nwclientSend( r->oflowHandler, fillLevel, buffer ); - } - else - { - _processNonOFLOWBlock( r, fillLevel, buffer ); - } + r->intervalRawBytes += fillLevel; - r->intervalRawBytes += fillLevel; + /* Send the block to clients, but only send OFLOW if it wasn't OFLOW already */ + /* or if we're decoding TPIU in the default tag */ + _purgeBlock( r, ( !r->usingOFLOW ) || r->options->useTPIU ); + } - /* Send the block to clients, but only send OFLOW if it wasn't OFLOW already */ - _purgeBlock( r, !r->usingOFLOW ); + _checkInterval( r ); } // ==================================================================================================== @@ -1037,10 +1050,7 @@ static void _usb_callback( struct libusb_transfer *t ) { /* Whatever the status that comes back, there may be data... */ - if ( t->actual_length > 0 ) - { - _handleBlock( &_r, t->actual_length, t->buffer ); - } + _handleBlock( &_r, t->actual_length, t->buffer ); if ( ( t->status != LIBUSB_TRANSFER_COMPLETED ) && ( t->status != LIBUSB_TRANSFER_TIMED_OUT ) && diff --git a/Support/gdbtrace.init b/Support/gdbtrace.init index d2ed8961..00d5b728 100644 --- a/Support/gdbtrace.init +++ b/Support/gdbtrace.init @@ -384,6 +384,7 @@ end # ==================================================================== define stopETM + _setAddressesETM4 if (((*$TRCDEVARCH)&0xfff0ffff) ==0x47704a13) set *($TRCPRGCTLR) &= ~(1<<0) while ((*$TRCSTATR)&(1<<0)==0)