1# Copyright (c) 2017-2020 Linaro Limited
2# Copyright (c) 2020 Arm Limited
3# Copyright (c) 2017-2023 Nordic Semiconductor ASA
4#
5# SPDX-License-Identifier: Apache-2.0
6
7menuconfig MCUBOOT_SERIAL
8	bool "MCUboot serial recovery"
9	default n
10	select REBOOT
11	select SERIAL
12	select UART_INTERRUPT_DRIVEN
13	select BASE64
14	select CRC
15	select ZCBOR
16	depends on !BOOT_FIRMWARE_LOADER
17	help
18	  If y, enables a serial-port based update mode. This allows
19	  MCUboot itself to load update images into flash over a UART.
20	  If unsure, leave at the default value.
21
22if MCUBOOT_SERIAL
23
24choice BOOT_SERIAL_DEVICE
25	prompt "Serial device"
26	default BOOT_SERIAL_UART if !BOARD_NRF52840DONGLE_NRF52840
27	default BOOT_SERIAL_CDC_ACM if BOARD_NRF52840DONGLE_NRF52840
28
29config BOOT_SERIAL_UART
30	bool "UART"
31	# SERIAL and UART_INTERRUPT_DRIVEN already selected
32	help
33	  The serial device to use will be fist selected via chosen
34	  node "zephyr,uart-mcumgr", when such node does not exist
35	  the "zephyr,console" is used.  In case when
36	  the "zephyr,uart-mcumgr" points to the same device as
37	  the "zephyr,console" compilation error will be triggered.
38
39config BOOT_SERIAL_CDC_ACM
40	bool "CDC ACM"
41	select USB_DEVICE_STACK
42	help
43	  This setting will choose CDC ACM for serial recovery unless chosen
44	  "zephyr,uart-mcumgr" is present, in which case the chosen takes
45	  precedence and redirects serial recovery to uart pointed by
46	  the chosen, leaving console on CDC ACM.
47
48endchoice
49
50config MCUBOOT_SERIAL_DIRECT_IMAGE_UPLOAD
51	bool "Allow to select image number for DFU"
52	depends on !SINGLE_APPLICATION_SLOT
53	help
54	  With the option enabled, the mcuboot serial recovery will
55	  respect the "image" field in mcumgr image update frame
56	  header.
57	  The mapping of image number to partition is as follows:
58	    0 -> default behaviour, same as 1;
59	    1 -> image-0 (primary slot of the first image);
60	    2 -> image-1 (secondary slot of the first image);
61	    3 -> image-2;
62	    4 -> image-3.
63	  Note that 0 is default upload target when no explicit
64	  selection is done.
65
66config BOOT_SERIAL_UNALIGNED_BUFFER_SIZE
67	int "Stack buffer for unaligned memory writes"
68	default 512 if SOC_SERIES_LPC55XXX
69	default 128 if SOC_SERIES_MCXN
70	default 64
71	range 0 1024
72	help
73	  Specifies the stack usage for a buffer which is used for unaligned
74	  memory access when data is written to a device with memory alignment
75	  requirements. Set to 0 to disable.
76
77config BOOT_MAX_LINE_INPUT_LEN
78	int "Maximum input line length"
79	default 128
80	help
81	  Maximum length of input serial port buffer (SMP serial transport uses
82	  fragments of 128-bytes, this should not need to be changed unless a
83	  different value is used for the transport).
84
85config BOOT_LINE_BUFS
86	int "Number of receive buffers"
87	range 2 128
88	default 8
89	help
90	  Number of receive buffers for data received via the serial port.
91
92config BOOT_SERIAL_MAX_RECEIVE_SIZE
93	int "Maximum command line length"
94	default 1024
95	help
96	  Maximum length of received commands via the serial port (this should
97	  be equal to the maximum line length, BOOT_MAX_LINE_INPUT_LEN times
98	  by the number of receive buffers, BOOT_LINE_BUFS to allow for
99	  optimal data transfer speeds).
100
101config BOOT_ERASE_PROGRESSIVELY
102	bool "Erase flash progressively when receiving new firmware"
103	default y if SOC_FAMILY_NORDIC_NRF || SOC_FAMILY_NXP_IMXRT
104	help
105	 If enabled, flash is erased as necessary when receiving new firmware,
106	 instead of erasing the whole image slot at once. This is necessary
107	 on some hardware that has long erase times, to prevent long wait
108	 times at the beginning of the DFU process.
109
110config BOOT_MGMT_ECHO
111	bool "Enable echo command"
112	help
113	  if enabled, support for the mcumgr echo command is being added.
114
115menuconfig ENABLE_MGMT_PERUSER
116	bool "Enable system specific mcumgr commands"
117	help
118	  The option enables processing of system specific mcumgr commands;
119	  system specific commands are within group MGMT_GROUP_ID_PERUSER (64)
120	  and above, as defined within mcumgr library.
121	  These are system specific command and system specific implementation
122	  function is required to process these commands.
123
124if ENABLE_MGMT_PERUSER
125
126config BOOT_MGMT_CUSTOM_STORAGE_ERASE
127	bool "Enable storage erase command"
128	help
129	  The option enables mcumgr command that allows to erase storage
130	  partition.
131	  Note that the storage partition needs to be defined, in DTS, otherwise
132	  enabling the option will cause a compilation to fail.
133
134endif # ENABLE_MGMT_PERUSER
135
136menu "Entrance methods"
137
138menuconfig BOOT_SERIAL_ENTRANCE_GPIO
139	bool "GPIO"
140	default y
141	depends on GPIO
142	help
143	  Use a GPIO to enter serial recovery mode.
144
145config BOOT_SERIAL_DETECT_DELAY
146	int "Serial detect pin detection delay time [ms]"
147	default 0
148	depends on BOOT_SERIAL_ENTRANCE_GPIO
149	help
150	  Used to prevent the bootloader from loading on button press.
151	  Useful for powering on when using the same button as
152	  the one used to place the device in bootloader mode.
153
154menuconfig BOOT_SERIAL_WAIT_FOR_DFU
155	bool "Wait a prescribed duration to see if DFU is invoked by receiving a MCUmgr comand"
156	depends on BOOT_SERIAL_UART || BOOT_SERIAL_CDC_ACM
157	help
158	  If y, MCUboot waits for a prescribed duration of time to allow
159	  for DFU to be invoked. The serial recovery can be entered by receiving any
160	  mcumgr command.
161
162config BOOT_SERIAL_WAIT_FOR_DFU_TIMEOUT
163	int "Duration to wait for the serial DFU timeout in ms"
164	default 500
165	depends on BOOT_SERIAL_WAIT_FOR_DFU
166	help
167	  Timeout in ms for MCUboot to wait to allow for DFU to be invoked.
168
169config BOOT_SERIAL_BOOT_MODE
170	bool "Check boot mode via retention subsystem"
171	depends on RETENTION_BOOT_MODE
172	help
173	  Allows for entering serial recovery mode by using Zephyr's boot mode
174	  retention system (i.e. an application must set the boot mode to stay
175	  in serial recovery mode and reboot the module).
176
177config BOOT_SERIAL_NO_APPLICATION
178	bool "Stay in bootloader if no application"
179	help
180	  Allows for entering serial recovery mode if there is no bootable
181	  application that the bootloader can jump to.
182
183config BOOT_SERIAL_PIN_RESET
184	bool "Check for device reset by pin"
185	select HWINFO
186	help
187	  Checks if the module reset was caused by the reset pin and will
188	  remain in bootloader serial recovery mode if it was.
189
190endmenu
191
192config BOOT_SERIAL_IMG_GRP_HASH
193	bool "Image list hash support"
194	default y
195	help
196	  If y, image list responses will include the image hash (adds ~100
197	  bytes of flash).
198
199config BOOT_SERIAL_IMG_GRP_IMAGE_STATE
200	bool "Image state support"
201	depends on !SINGLE_APPLICATION_SLOT
202	select BOOT_SERIAL_IMG_GRP_HASH if UPDATEABLE_IMAGE_NUMBER > 1
203	help
204	  If y, image states will be included with image lists and the set
205	  state command can be used to mark an image as test/confirmed.
206
207config BOOT_SERIAL_IMG_GRP_SLOT_INFO
208	bool "Slot info"
209	default y if UPDATEABLE_IMAGE_NUMBER > 1
210	help
211	  If y, will include the slot info command which lists what available
212	  slots there are in the system.
213
214endif # MCUBOOT_SERIAL
215