1
1
/*
2
2
* Copyright (c) 2018-2021 mcumgr authors
3
- * Copyright (c) 2021-2023 Nordic Semiconductor ASA
3
+ * Copyright (c) 2021-2024 Nordic Semiconductor ASA
4
4
* Copyright (c) 2022 Laird Connectivity
5
5
*
6
6
* SPDX-License-Identifier: Apache-2.0
@@ -451,6 +451,7 @@ os_mgmt_bootloader_info(struct smp_streamer *ctxt)
451
451
struct zcbor_string query = { 0 };
452
452
size_t decoded ;
453
453
bool ok ;
454
+ bool has_output = false;
454
455
455
456
#if defined(CONFIG_MCUMGR_GRP_OS_BOOTLOADER_INFO_HOOK )
456
457
enum mgmt_cb_return status ;
@@ -459,7 +460,8 @@ os_mgmt_bootloader_info(struct smp_streamer *ctxt)
459
460
struct os_mgmt_bootloader_info_data bootloader_info_data = {
460
461
.zse = zse ,
461
462
.decoded = & decoded ,
462
- .query = & query
463
+ .query = & query ,
464
+ .has_output = & has_output
463
465
};
464
466
#endif
465
467
@@ -487,24 +489,29 @@ os_mgmt_bootloader_info(struct smp_streamer *ctxt)
487
489
#endif
488
490
489
491
/* If no parameter is recognized then just introduce the bootloader. */
492
+ if (!has_output ) {
490
493
#if defined(CONFIG_BOOTLOADER_MCUBOOT )
491
- if (decoded == 0 ) {
492
- ok = zcbor_tstr_put_lit (zse , "bootloader" ) &&
493
- zcbor_tstr_put_lit (zse , "MCUboot" );
494
- } else if (zcbor_map_decode_bulk_key_found (bootloader_info , ARRAY_SIZE (bootloader_info ),
495
- "query" ) &&
496
- (sizeof ("mode" ) - 1 ) == query .len &&
497
- memcmp ("mode" , query .value , query .len ) == 0 ) {
498
-
499
- ok = zcbor_tstr_put_lit (zse , "mode" ) &&
500
- zcbor_int32_put (zse , BOOTLOADER_MODE );
494
+ if (decoded == 0 ) {
495
+ ok = zcbor_tstr_put_lit (zse , "bootloader" ) &&
496
+ zcbor_tstr_put_lit (zse , "MCUboot" );
497
+ has_output = true;
498
+ } else if (zcbor_map_decode_bulk_key_found (bootloader_info ,
499
+ ARRAY_SIZE (bootloader_info ),
500
+ "query" ) && (sizeof ("mode" ) - 1 ) == query .len &&
501
+ memcmp ("mode" , query .value , query .len ) == 0 ) {
502
+
503
+ ok = zcbor_tstr_put_lit (zse , "mode" ) &&
504
+ zcbor_int32_put (zse , BOOTLOADER_MODE );
501
505
#ifdef CONFIG_MCUBOOT_BOOTLOADER_NO_DOWNGRADE
502
- ok = ok && zcbor_tstr_put_lit (zse , "no-downgrade" ) &&
503
- zcbor_bool_encode (zse , & (bool ){true});
506
+ ok = ok && zcbor_tstr_put_lit (zse , "no-downgrade" ) &&
507
+ zcbor_bool_encode (zse , & (bool ){true});
504
508
#endif
505
- } else
509
+ has_output = true;
510
+ }
506
511
#endif
507
- {
512
+ }
513
+
514
+ if (!has_output ) {
508
515
ok = smp_add_cmd_err (zse , MGMT_GROUP_ID_OS , OS_MGMT_ERR_QUERY_YIELDS_NO_ANSWER );
509
516
}
510
517
0 commit comments