3434#include "general.h"
3535#include "target.h"
3636#include "target_internal.h"
37+ #include "gdb_reg.h"
3738#include "spi.h"
3839#include "sfdp.h"
3940
@@ -50,6 +51,7 @@ typedef struct onboard_flash {
5051static target_halt_reason_e onboard_flash_halt_poll (target_s * target , target_addr64_t * watch );
5152static bool onboard_flash_check_error (target_s * target );
5253static void onboard_flash_read (target_s * target , void * dest , target_addr64_t src , size_t len );
54+ static const char * onboard_flash_target_description (target_s * target );
5355
5456static void onboard_spi_setup_xfer (const uint16_t command , const target_addr32_t address )
5557{
@@ -173,6 +175,7 @@ bool onboard_flash_scan()
173175 /* Set up GDB support members */
174176 target -> halt_poll = onboard_flash_halt_poll ;
175177 target -> regs_size = 0U ;
178+ target -> regs_description = onboard_flash_target_description ;
176179 return true;
177180}
178181
@@ -200,6 +203,58 @@ static void onboard_flash_read(target_s *const target, void *const dest, const t
200203 priv -> error_state = flash_bad_address ;
201204 else if (len >= flash -> length - (src - flash -> start ))
202205 priv -> error_state = flash_bad_length ;
203- else
206+ else {
204207 onboard_spi_read (target , SPI_FLASH_CMD_PAGE_READ , src - flash -> start , dest , len );
208+
209+ #if ENABLE_DEBUG
210+ DEBUG_PROTO ("%s: @ %08" PRIx32 " len %zu:" , __func__ , (uint32_t )src , len );
211+ #ifndef DEBUG_PROTO_IS_NOOP
212+ const uint8_t * const data = (const uint8_t * )dest ;
213+ #endif
214+ for (size_t offset = 0 ; offset < len ; ++ offset ) {
215+ if (offset == 16U )
216+ break ;
217+ DEBUG_PROTO (" %02x" , data [offset ]);
218+ }
219+ if (len > 16U )
220+ DEBUG_PROTO (" ..." );
221+ DEBUG_PROTO ("\n" );
222+ #endif
223+ }
224+ }
225+
226+ /*
227+ * This function creates the dummy target description XML string for the on-board Flash.
228+ * This is done this way to decrease string duplication and thus code size, making it
229+ * unfortunately much less readable than the string literal it is equivalent to.
230+ *
231+ * This string it creates is the XML-equivalent to the following:
232+ * <?xml version=\"1.0\"?>
233+ * <!DOCTYPE target SYSTEM \"gdb-target.dtd\">
234+ * <target>
235+ * <architecture></architecture>
236+ * </target>
237+ */
238+ static size_t onboard_flash_build_target_description (char * const buffer , const size_t max_length )
239+ {
240+ size_t print_size = max_length ;
241+ /* Start with the "preamble" chunks, which are mostly common across targets save for 2 words. */
242+ int offset = snprintf (
243+ buffer , print_size , "%s target %s%s" , gdb_xml_preamble_first , gdb_xml_preamble_second , gdb_xml_preamble_third );
244+ if (max_length != 0 )
245+ print_size = max_length - (size_t )offset ;
246+
247+ offset += (size_t )snprintf (buffer + offset , print_size , "</target>" );
248+ /* offset is now the total length of the string created, discard the sign and return it. */
249+ return offset ;
250+ }
251+
252+ static const char * onboard_flash_target_description (target_s * const target )
253+ {
254+ (void )target ;
255+ const size_t description_length = onboard_flash_build_target_description (NULL , 0 ) + 1U ;
256+ char * const description = malloc (description_length );
257+ if (description )
258+ (void )onboard_flash_build_target_description (description , description_length );
259+ return description ;
205260}
0 commit comments