# Copyright (C) Frickly Systems GmbH
# Copyright (C) MBition GmbH
#
# SPDX-License-Identifier: Apache-2.0

mainmenu "Firmware Loader"

comment "UDS Firmware Loader Configuration"

menu "Firmware Loader Settings"

module = APP
module-str = app
source "subsys/logging/Kconfig.template.log_config"

if !UDS_DEFAULT_INSTANCE_EXTERNAL_ADDRESS_PROVIDER

# alias configs for easier access of UDS_DEFAULT_INSTANCE addresses

config FIRMWARE_LOADER_PHYS_SA
    hex "Physical Source Address"
    default 0x7E8
    help
      The physical source address used for UDS communication.
      Should be the same as the main application's address

config FIRMWARE_LOADER_PHYS_TA
    hex "Physical Target Address"
    default 0x7E0
    help
      The physical target address used for UDS communication.
      Should be the same as the main application's address

config FIRMWARE_LOADER_FUNC_SA
    hex "Functional Source Address"
    default 0x7DF
    help
      The functional source address used for UDS communication.
      Should be the same as the main application's address

config UDS_DEFAULT_INSTANCE_SOURCE_ADDRESS
  default FIRMWARE_LOADER_PHYS_SA

config UDS_DEFAULT_INSTANCE_TARGET_ADDRESS
  default FIRMWARE_LOADER_PHYS_TA

config UDS_DEFAULT_INSTANCE_FUNCTIONAL_SOURCE_ADDRESS
  default FIRMWARE_LOADER_FUNC_SA

endif

config DISABLE_WAIT_BEFORE_ERASE
    bool "Disable waiting before erasing slot0"
    default n
    help
      Disables the 150ms wait before erasing slot0, which also disallows using the
      RoutineControl message without the no-reponse setting.

menuconfig FIRMWARE_LOADER_USB_DFU
    bool "Enable USB DFU support"
    default y
    select USBD_DFU
    select USB_DEVICE_STACK_NEXT
    select USBD_DFU_FLASH
    select USBD_DFU_FLASH_SLOT0
    help
      Enable USB Device Firmware Upgrade (DFU) support for firmware updates via USB.

if FIRMWARE_LOADER_USB_DFU
  config FIRMWARE_LOADER_USB_DFU_REBOOT_AFTER_COMPLETION
      bool "Reboot after DFU completion"
      default y
      depends on REBOOT
      help
        Reboot the system automatically after a successful firmware update via USB DFU.
  if FIRMWARE_LOADER_USB_DFU_REBOOT_AFTER_COMPLETION
    config FIRMWARE_LOADER_USB_DFU_REBOOT_DELAY_MS
        int "USB DFU Reboot Delay (ms)"
        default 3000
        help
          Time in milliseconds to wait before rebooting the system after a successful
          firmware update via USB DFU.
  endif
endif


endmenu

comment "Zephyr Configuration"

source "Kconfig.zephyr"
