1# C library
2
3# Copyright (c) 2016 Intel Corporation
4# SPDX-License-Identifier: Apache-2.0
5
6menu "C Library"
7
8config REQUIRES_FULL_LIBC
9	bool
10	help
11	  Helper symbol to indicate some feature requires a C library implementation
12	  with more functionality than what MINIMAL_LIBC provides
13
14config SUPPORT_MINIMAL_LIBC
15	bool
16	default y
17
18choice LIBC_IMPLEMENTATION
19	prompt "C Library Implementation"
20	default EXTERNAL_LIBC if NATIVE_APPLICATION
21	default NEWLIB_LIBC if REQUIRES_FULL_LIBC
22	default MINIMAL_LIBC
23
24config MINIMAL_LIBC
25	bool "Minimal C library"
26	depends on !NATIVE_APPLICATION
27	depends on !REQUIRES_FULL_LIBC
28	depends on SUPPORT_MINIMAL_LIBC
29	help
30	  Build with minimal C library.
31
32config NEWLIB_LIBC
33	bool "Newlib C library"
34	depends on !NATIVE_APPLICATION
35	help
36	  Build with newlib library. The newlib library is expected to be
37	  part of the SDK in this case.
38
39config ARCMWDT_LIBC
40	bool "ARC MWDT C library"
41	depends on !NATIVE_APPLICATION
42	depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "arcmwdt"
43	help
44	  C library provided by ARC MWDT toolchain.
45
46config EXTERNAL_LIBC
47	bool "External C library"
48	help
49	  Build with external/user provided C library.
50
51endchoice # LIBC_IMPLEMENTATION
52
53config HAS_NEWLIB_LIBC_NANO
54	bool
55
56if NEWLIB_LIBC
57
58config NEWLIB_LIBC_NANO
59	bool "Build with newlib-nano C library"
60	depends on HAS_NEWLIB_LIBC_NANO
61	default y
62	help
63	  Build with newlib-nano library, for small embedded apps.
64	  The newlib-nano library for ARM embedded processors is a part of the
65	  GNU Tools for ARM Embedded Processors.
66
67config NEWLIB_LIBC_MAX_MAPPED_REGION_SIZE
68	int "Maximum memory mapped for newlib heap"
69	depends on MMU
70	default 1048576
71	help
72	  On MMU-based systems, indicates the maximum amount of memory which
73	  will be used for the newlib malloc() heap. The actual amount of
74	  memory used will be the minimum of this value and the amount of
75	  free physical memory at kernel boot.
76
77config NEWLIB_LIBC_MIN_REQUIRED_HEAP_SIZE
78	int "Newlib minimum required heap size"
79	default 2048 if NEWLIB_LIBC_NANO
80	default 8192 if !NEWLIB_LIBC_NANO
81	help
82	  Specifies the amount of memory space that must be available for the
83	  newlib heap. An assertion failure message will be displayed during
84	  initialization if the memory space available for the newlib heap is
85	  smaller than this value.
86
87config NEWLIB_LIBC_ALIGNED_HEAP_SIZE
88	int "Newlib aligned heap size"
89	depends on MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
90	depends on USERSPACE
91	default 0
92	help
93	  If user mode is enabled, and MPU hardware has requirements that
94	  regions be sized to a power of two and aligned to their size,
95	  and user mode threads need to access this heap, then this is necessary
96	  to properly define an MPU region for the heap.
97
98	  If this is left at 0, then remaining system RAM will be used for this
99	  area and it may not be possible to program it as an MPU region.
100
101config NEWLIB_LIBC_FLOAT_PRINTF
102	bool "Build with newlib float printf"
103	help
104	  Build with floating point printf enabled. This will increase the size of
105	  the image.
106
107config NEWLIB_LIBC_FLOAT_SCANF
108	bool "Build with newlib float scanf"
109	help
110	  Build with floating point scanf enabled. This will increase the size of
111	  the image.
112
113endif # NEWLIB_LIBC
114
115if MINIMAL_LIBC
116
117config MINIMAL_LIBC_MALLOC
118	bool "Enable minimal libc malloc implementation"
119	default y
120	help
121	  Enable the minimal libc's implementation of malloc, free, and realloc.
122	  Disable if you wish to provide your own implementations of these functions.
123
124config MINIMAL_LIBC_MALLOC_ARENA_SIZE
125	int "Size of the minimal libc malloc arena"
126	default 0
127	depends on MINIMAL_LIBC_MALLOC
128	help
129	  Indicate the size in bytes of the memory arena used for
130	  minimal libc's malloc() implementation.
131
132config MINIMAL_LIBC_CALLOC
133	bool "Enable minimal libc trivial calloc implementation"
134	default y
135	help
136	  Enable the minimal libc's trivial implementation of calloc, which
137	  forwards to malloc and memset.
138
139config MINIMAL_LIBC_REALLOCARRAY
140	bool "Enable minimal libc trivial reallocarray implementation"
141	default y
142	help
143	  Enable the minimal libc's trivial implementation of reallocarray, which
144	  forwards to realloc.
145
146config MINIMAL_LIBC_LL_PRINTF
147	bool "Build with minimal libc long long printf" if !64BIT
148	default y if 64BIT
149	help
150	  Build with long long printf enabled. This will increase the size of
151	  the image.
152
153config MINIMAL_LIBC_OPTIMIZE_STRING_FOR_SIZE
154	bool "Use size optimized string functions"
155	default y if SIZE_OPTIMIZATIONS
156	help
157	  Enable smaller but potentially slower implementations of memcpy and
158	  memset. On the Cortex-M0+ this reduces the total code size by 120 bytes.
159
160config MINIMAL_LIBC_RAND
161	bool "Enables rand and srand functions"
162	select NEED_LIBC_MEM_PARTITION
163	help
164	  Enable rand() and srand() for the minimal libc. The
165	  functions implicitly access global/static data.  Such data
166	  must be put into a memory partition if CONFIG_USERSPACE=y,
167	  and disabling this option may save an entry for application
168	  defining many custom partitions.
169
170	  Say 'Y' here if you need rand() and srand(). This might require
171	  an additional memory partition.
172
173endif # MINIMAL_LIBC
174
175config STDOUT_CONSOLE
176	bool "Send stdout to console"
177	depends on CONSOLE_HAS_DRIVER
178	depends on !NATIVE_APPLICATION
179	default y
180	help
181	  This option directs standard output (e.g. printf) to the console
182	  device, rather than suppressing it entirely. See also EARLY_CONSOLE
183	  option.
184
185config NEED_LIBC_MEM_PARTITION
186	bool
187	help
188	  Hidden option to signal that a memory partition is needed for
189	  the C libraray even though it would not have been enabled
190	  otherwise.
191
192endmenu
193