@@ -62,10 +62,18 @@ void fl_cmd_print_fpb_info(fl_context_t* ctx) {
6262 (unsigned long )fpb_info .remap_base , fpb_info .remap_supported ? "supported" : "not supported" );
6363
6464 static const char * replace_mode_str [] = {"remap" , "bp_lo" , "bp_hi" , "bp_both" };
65+ static const char * patch_mode_str [] = {"none" , "remap" , "trampoline" , "debugmon" };
6566 for (uint32_t i = 0 ; i < num_comps && i < FL_MAX_SLOTS && i < FPB_MAX_CODE_COMP ; i ++ ) {
6667 fl_slot_state_t * slot = & ctx -> slots [i ];
6768 fpb_comp_info_t * comp = & fpb_info .comp [i ];
68- const char * mode_str = (comp -> replace < 4 ) ? replace_mode_str [comp -> replace ] : "?" ;
69+ const char * mode_str ;
70+
71+ /* Use slot's patch mode if active, otherwise fall back to hardware REPLACE field */
72+ if (slot -> active && slot -> mode < 4 ) {
73+ mode_str = patch_mode_str [slot -> mode ];
74+ } else {
75+ mode_str = (comp -> replace < 4 ) ? replace_mode_str [comp -> replace ] : "?" ;
76+ }
6977
7078 if (slot -> active ) {
7179 fl_println ("Slot[%u]: 0x%08lX -> 0x%08lX, %u bytes (COMP=0x%08lX, %s, %s)" , (unsigned )i ,
@@ -120,6 +128,7 @@ fl_error_t fl_cmd_patch(fl_context_t* ctx, const cmd_args_t* args) {
120128
121129 /* Record slot state, transfer last_alloc ownership to slot */
122130 ctx -> slots [args -> comp ].active = true;
131+ ctx -> slots [args -> comp ].mode = FL_PATCH_MODE_REMAP ;
123132 ctx -> slots [args -> comp ].orig_addr = args -> orig ;
124133 ctx -> slots [args -> comp ].target_addr = args -> target ;
125134 ctx -> slots [args -> comp ].code_size = ctx -> last_alloc_size ;
@@ -163,6 +172,7 @@ fl_error_t fl_cmd_tpatch(fl_context_t* ctx, const cmd_args_t* args) {
163172
164173 /* Record slot state, transfer last_alloc ownership to slot */
165174 ctx -> slots [args -> comp ].active = true;
175+ ctx -> slots [args -> comp ].mode = FL_PATCH_MODE_TRAMPOLINE ;
166176 ctx -> slots [args -> comp ].orig_addr = args -> orig ;
167177 ctx -> slots [args -> comp ].target_addr = args -> target ;
168178 ctx -> slots [args -> comp ].code_size = ctx -> last_alloc_size ;
@@ -211,6 +221,7 @@ fl_error_t fl_cmd_dpatch(fl_context_t* ctx, const cmd_args_t* args) {
211221
212222 /* Record slot state, transfer last_alloc ownership to slot */
213223 ctx -> slots [args -> comp ].active = true;
224+ ctx -> slots [args -> comp ].mode = FL_PATCH_MODE_DEBUGMON ;
214225 ctx -> slots [args -> comp ].orig_addr = args -> orig ;
215226 ctx -> slots [args -> comp ].target_addr = args -> target ;
216227 ctx -> slots [args -> comp ].code_size = ctx -> last_alloc_size ;
@@ -266,6 +277,7 @@ fl_error_t fl_cmd_unpatch(fl_context_t* ctx, const cmd_args_t* args) {
266277
267278 /* Clear slot state */
268279 ctx -> slots [i ].active = false;
280+ ctx -> slots [i ].mode = FL_PATCH_MODE_NONE ;
269281 ctx -> slots [i ].orig_addr = 0 ;
270282 ctx -> slots [i ].target_addr = 0 ;
271283 ctx -> slots [i ].code_size = 0 ;
@@ -300,7 +312,6 @@ fl_error_t fl_cmd_enable(fl_context_t* ctx, const cmd_args_t* args) {
300312 }
301313 }
302314
303- (void )ctx ;
304315 bool en = args -> enable != 0 ;
305316 bool all = args -> all ;
306317 uint32_t comp = (uint32_t )args -> comp ;
@@ -315,10 +326,16 @@ fl_error_t fl_cmd_enable(fl_context_t* ctx, const cmd_args_t* args) {
315326
316327 uint32_t changed = 0 ;
317328 for (uint32_t i = start ; i < end && i < FL_MAX_SLOTS ; i ++ ) {
329+ if (all && !ctx -> slots [i ].active ) {
330+ continue ; /* --all mode: skip inactive slots */
331+ }
332+
318333 fpb_result_t ret = fpb_enable_patch (i , en );
319- if (ret == FPB_OK ) {
320- changed ++ ;
334+ if (ret != FPB_OK ) {
335+ fl_response (false, "Failed to %s patch %lu: %d" , en ? "enable" : "disable" , (unsigned long )i , ret );
336+ return FL_ERR_HW ;
321337 }
338+ changed ++ ;
322339 }
323340
324341 if (all ) {
0 commit comments