# Copyright Runtime.io 2018. All rights reserved.
# Copyright Nordic Semiconductor ASA 2020-2022. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# The Kconfig file is dedicated to Application Image management group of
# of MCUmgr subsystem and provides Kconfig options to configure
# group commands behaviour and other aspects.
#
# Options defined in this file should be prefixed:
#  MCUMGR_GRP_IMG_ -- general group options;
#
# When adding Kconfig options, that control the same feature,
# try to group them together by the same stem after prefix.

menuconfig MCUMGR_GRP_IMG
	bool "Mcumgr handlers for image management"
	depends on FLASH
	depends on IMG_MANAGER
	depends on !MCUBOOT_BOOTLOADER_MODE_SINGLE_APP
	select MPU_ALLOW_FLASH_WRITE if ARM_MPU
	select MCUMGR_SMP_CBOR_MIN_DECODING_LEVEL_2
	help
	  Enables MCUmgr handlers for image management

if MCUMGR_GRP_IMG

if HEAP_MEM_POOL_SIZE > 0

config MCUMGR_GRP_IMG_USE_HEAP_FOR_FLASH_IMG_CONTEXT
	bool "Use heap mem pool for flash image DFU context"
	help
	  Use heap to allocate flash image upload context, otherwise a static variable will
	  be used. The context object is used by MCUMGR_GRP_IMG_MANAGER to buffer image writes
	  and has significant size, mainly affected by image write buffer of
	  the CONFIG_IMG_BLOCK_BUF_SIZE size and additional fields that hold the state information
	  (struct flash_img_context).
	  When the option is not enabled it increases static RAM use.
	  Make sure with testing, when enabling the option, that the heap has enough size
	  to allocate this context or it will not be possible to perform DFU; it may also not be
	  possible to allocate such context when heap is under pressure, due to application
	  operation, an issue that should also be addressed within application.

endif

config MCUMGR_GRP_IMG_UPDATABLE_IMAGE_NUMBER
	int "Number of supported images"
	default UPDATEABLE_IMAGE_NUMBER
	range 1 2
	help
	  Sets how many application images are supported (pairs of secondary and primary slots).
	  Setting this to 2 requires MCUMGR_TRANSPORT_NETBUF_SIZE to be at least 512b.
	  NOTE: The UPDATEABLE_IMAGE_NUMBER of MCUBOOT configuration, even for Zephyr build,
	  needs to be set to the same value; this is due to the fact that the MCUmgr uses
	  boot_util and the UPDATEABLE_IMAGE_NUMBER controls number of images supported
	  by that library.

config MCUMGR_GRP_IMG_VERBOSE_ERR
	bool "Verbose error responses when uploading application image"
	select MCUMGR_SMP_VERBOSE_ERR_RESPONSE
	help
	  Add additional "rsn" key to SMP responses, where provided, explaining
	  non-0 "rc" codes.

config MCUMGR_GRP_IMG_DIRECT_UPLOAD
	bool "Allow direct image upload"
	help
	  Enables directly uploading image to selected image partition.
	  This changes how "image" is understood by MCUmgr: normally MCUmgr allows uploading to
	  the first slot of the only image it knows, where image is understood as two slots
	  (two DTS images for Zephyr); this allows to treat every DTS defined image as direct
	  target for upload, and more than two may be used (4 at this time).
	  NOTE: When direct upload is used the image numbers are shifted by + 1, and the default
	  behaviour is, when image is not selected, to upload to image that represents secondary
	  slot in normal operation.

config MCUMGR_GRP_IMG_REJECT_DIRECT_XIP_MISMATCHED_SLOT
	bool "Reject Direct-XIP applications with mismatched address"
	help
	  When enabled, the MCUmgr will compare base address of application,
	  encoded into .bin file header with use of imgtool, on upload and will
	  reject binaries that would not be able to start from available
	  Direct-XIP address.
	  The base address can be set, to an image binary header, with imgtool,
	  using the --rom-fixed command line option.

config MCUMGR_GRP_IMG_FRUGAL_LIST
	bool "Omit zero, empty or false values from status list"
	help
	  The status list send back from the device will only be filled with data that is non-zero,
	  non-empty or true.  This option slightly reduces number of bytes transferred back from
	  a device but requires support in client software, which has to default omitted values.
	  Works correctly with the go mcumgr-cli application.

config MCUMGR_GRP_IMG_VERSION_CMP_USE_BUILD_NUMBER
	bool "Use build number while comparing image version"
	help
	  By default, the image version comparison relies only on version major,
	  minor and revision. Enable this option to take into account the build
	  number as well.

config MCUMGR_GRP_IMG_UPLOAD_CHECK_HOOK
	bool "Upload check hook"
	depends on MCUMGR_MGMT_NOTIFICATION_HOOKS
	help
	  This will enable the upload check hook which will send image upload requests to
	  registered callbacks to check with the user application if an upload should be accepted
	  or rejected.

config MCUMGR_GRP_IMG_STATUS_HOOKS
	bool "Status hooks"
	depends on MCUMGR_MGMT_NOTIFICATION_HOOKS
	help
	  This will enable DFU status hooks which can be checked by the application to monitor DFU
	  uploads. Note that these are status checking only, to allow inspecting of a file upload
	  or prevent it, CONFIG_MCUMGR_GRP_IMG_UPLOAD_CHECK_HOOK must be used.

config MCUMGR_GRP_IMG_MUTEX
	bool "Mutex locking"
	help
	  This will enable use of a mutex to lock the image group object access, preventing issues
	  of concurrent thread (i.e. multiple transport) access. This option also makes the
	  ``img_mgmt_reset_upload()`` function visible in the image management group header, which
	  can be used by applications to reset the image management state (useful if there are
	  multiple ways that firmware updates can be loaded).

module = MCUMGR_GRP_IMG
module-str = mcumgr_grp_img
source "subsys/logging/Kconfig.template.log_config"

endif
