Commit graph

650 commits

Author SHA1 Message Date
Paul Sokolovsky 0906671a7b posix: pthread: pthread_mutex_timedlock should accept absolute deadline
It was coded as if it accepts relative timeout. Normative reference:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_timedlock.html

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-08-27 17:50:48 -04:00
Paul Sokolovsky 68c7dc6b96 posix: pthread: pthread_cond_timedwait should accept absolute deadline
Instead, it was coded as if it accepted a relative timeout. Normative
reference:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_timedwait.html

Fixes: #17812

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-08-27 17:50:48 -04:00
Paul Sokolovsky 6c5a08899a posix: fs: ZFD_IOCTL_CLOSE: Be sure to call posix_fs_free_obj()
To make sure that entry in fs.c:desc_array[] is freed. Note that
freeing an entry in fdtable is handled by generic implementation
of close().

Fixes: #17231

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-08-27 10:34:54 -04:00
Andrew Boie aed767a98c libc: newlib: make sbrk() thread-safe
Concurrent use of this function could lead to corruption.
Use a sys_sem to synchronize access.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-08-22 07:38:56 -05:00
Paul Sokolovsky 5b3df8a180 posix: pthread_create: Ignore retval of pthread_mutex_init() calls
pthread_mutex_init() just redirects to Zephyr kernel primitive, for
initializing structure fields. So, use the knowledge that it can't
fail (for as long as structure pointer is initialized, and here it's
from pre-allocated array), and ignore return value of
pthread_mutex_init()

Coverity-CID: 203542
Fixes: #18371

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-08-21 07:26:59 -05:00
Peter Bigot 96c1b05125 lib/newlib: revert treatment of libc files as system includes
The solution from #14312 of using -isystem to prioritize the position of
the libc directory bypasses the effect of -ffreestanding with respect to
libc symbols expected to be present in a non-hosted environment.

Further, it breaks C++ with the ARM Embedded toolchain as the system
fails to find the right file with #include_next.

Use a more fine-grained solution that explicitly includes the underlying
newlib header required for <inttypes.h> support before moving on to
include the next available one, whether system or non-system.

Closes #17564

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-08-20 12:51:16 -05:00
Peter Bigot 849df51666 lib/libc: rearrange for standard use of extern "C"
Consistently place C++ use of extern "C" after all include directives,
within the negative branch of _ASMLANGUAGE if used.

Background from issue #17997:

Declarations that use C linkage should be placed within extern "C"
so the language linkage is correct when the header is included by
a C++ compiler.

Similarly #include directives should be outside the extern "C" to
ensure the language-specific default linkage is applied to any
declarations provided by the included header.

See: https://en.cppreference.com/w/cpp/language/language_linkage
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-08-19 23:36:59 +02:00
Peter Bigot b6dafeb612 include/lvgl: rearrange for standard use of extern "C"
Consistently place C++ use of extern "C" after all include directives,
within the negative branch of _ASMLANGUAGE if used.

Background from issue #17997:

Declarations that use C linkage should be placed within extern "C"
so the language linkage is correct when the header is included by
a C++ compiler.

Similarly #include directives should be outside the extern "C" to
ensure the language-specific default linkage is applied to any
declarations provided by the included header.

See: https://en.cppreference.com/w/cpp/language/language_linkage
Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2019-08-13 18:00:31 +02:00
Jan Van Winkel 55c3585f18 gui: Corrected paths in Zephyr to LVGL FS mapping
Corrected path handling between zephyr and LVGL FS API

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-08-09 07:35:38 -05:00
Jan Van Winkel fa27e583a1 gui: Disable LVGL features by default
Removed 'default y' from LVGL Kconfig files to disable features by
default

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-08-09 07:35:38 -05:00
Jan Van Winkel 6bbd4cbaa3 gui: Add support for lvgl API version 6
Added support for lvgl API version 6

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-08-09 07:35:38 -05:00
Peter A. Bigot ef4cd6a1ab lib/libc/minimal: Refined handle duplicate time definitions
Follow the approach of newlib to use a file sys/_types.h to specify the
underlying type for POSIX/libc types that must be provided in multiple
headers.  The identifier for this type is in the reserved namespace.

Use this type rather than a specific standard type in all headers that
need to provide the type under its public name.

Remove the inclusion of <sys/types.h> from headers that should not bring
in all symbols present in that header, replacing it with the standard
boilerplate to expose the specific symbols that are required.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-08-09 00:43:09 -07:00
Kumar Gala daf9f11024 lib/libc/min: Handle duplicate time definitions
time_t and suseconds_t are defined in time.h and sys/types.h.  Handle
the duplication by adding ifdef protection around them similar to what
is being done for other types.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-08-09 00:43:09 -07:00
Paul Sokolovsky f0d483aaa6 lib: posix: Switch to use zephyr_interface_library_named cmake directive
Similar to how other sub-libraries are defined in Zephyr tree, e.g.
"fs", "lgvl", etc. This is supposed to help with the need to
explicitly add posix include path to each and every application using
POSIX subsys.

Fixes: #15627

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-08-08 14:31:35 +02:00
Paul Sokolovsky 7d2df83b51 libc: minimal: Add headers as system includes
This is consistent with how newlib headers are treated, and will
have effect of ninlibc headers to be further down in the include
order. This is important, because some POSIX subsys headers
override those of libc. Without this change, we can't streamline
POSIX build config using zephyr_interface_library_named() cmake
directive, because includes will be in wrong order.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-08-08 14:31:35 +02:00
Paul Sokolovsky ff6432edad lib: posix: Use "posix_subsys" as the CMake lib for the subsystem.
Historically, it used to be "PTHREAD", which is no longer true, as
POSIX subsys offers much more functionality than just Pthreads. Use
detailed name, like "posix_subsys", to avoid possible confusion with
ARCH_POSIX-related matters.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-08-08 14:31:35 +02:00
Nicolas Pitre 1f4b5ddd0f riscv32: rename to riscv
With the upcoming riscv64 support, it is best to use "riscv" as the
subdirectory name and common symbols as riscv32 and riscv64 support
code is almost identical. Then later decide whether 32-bit or 64-bit
compilation is wanted.

Redirects for the web documentation are also included.

Then zephyrbot complained about this:

"
New files added that are not covered in CODEOWNERS:

dts/riscv/microsemi-miv.dtsi
dts/riscv/riscv32-fe310.dtsi

Please add one or more entries in the CODEOWNERS file to cover
those files
"

So I assigned them to those who created them. Feel free to readjust
as necessary.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-08-02 13:54:48 -07:00
Peter A. Bigot 8420f43b86 libc: minimal: add strspn and strcspn support
These functions are useful for determining prefixes, as with file system
paths.  They are required by littlefs.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-07-31 09:22:49 -07:00
Peter A. Bigot b8af1a6a4e libc/minimal: fix reproducibility of gmtime
struct tm has fields that were not being set by the implementation,
causing the test to fail when the uninitialized values were compared
with a static initialized result.  Zero the structure before filling it.

Closes #17794

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-07-31 11:48:18 +03:00
Paul Sokolovsky 6b90a02bb4 libc: minimal: time.h: Don't (re)define struct timespec.
By the latest convention, libc's define struct timespec in
sys/_timespec.h. This is consistent with Newlib and ensures
about errors due to redefinitions.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-07-25 13:50:58 -04:00
Paul Sokolovsky b7bb48eeac posix: unistd.h: open() doesn't belong here
Per POSIX, open() is defined in <fcntl.h>. fcntl.h in turn comes from
the underlying libc, either newlib, or minimal libc.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-07-25 13:50:58 -04:00
Paul Sokolovsky 1347bf9b48 posix: mqueue.h: Move O_CREAT and friends to fcntl.h
That's the header which is supposed to define them, there was even
FIXME on that in mqueue.h.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-07-25 13:50:58 -04:00
Paul Sokolovsky 3a4553913e posix: struct timespec: Move definition to sys/_timespec.h
POSIX subsys defines struct timespec in <time.h> (as POSIX public
API requires), but newlib defines in in sys/_timespec.h, which
inevitably leads to inclusion order and redifinition conflicts.
Follow newlib way and define it in single place, sys/_timespec.h,
which belongs to libc namespace. Thus, we move current definition
to minimal libc, and will use either minlibc's or newlib's
definition, instead of trying to redefine it.

This is similar to the introduction of sys/_timeval.h done earlier.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-07-25 13:50:58 -04:00
Paul Sokolovsky 3693f85805 posix: Move sys/stat.h to minimal libc
Newlib libc already provides sys/stat.h, so trying to have sys/stat.h
on the level of POSIX subsys inevitable leads to include order and
definition conflicts. Instead (as most of other sys/* includes)
should come from the underlying libc.

While moving, made unrelated change of removing #include <kernel.h>,
to accommodate the change reviewers.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-07-25 13:50:58 -04:00
Wentong Wu 715369350d lib: os: add sys_sem data type
For systems with userspace, the sys_sem exist in user memory working
as counter semaphore for user mode thread. The implemention of sys_sem
is based on k_futex. And the majority of the synchronization operations
are performed in user mode to reduce the calling of system call.
And for systems without userspace enabled, sys_sem behaves like k_sem.

Fixes: #15139.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-07-24 10:12:25 -07:00
Andrew Boie 39425eaada assert: generate oops if invoked from usermode
User mode isn't allowed to generate a panic and this would
lead to a confusing privilege violation exception.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-07-20 08:29:39 -04:00
Peter A. Bigot 9d25b671bc sys: timeutil: add module
Add a generic API to provide the inverse operation for gmtime and as a
home for future generic time-related functions that are not in POSIX.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-07-17 14:04:44 +02:00
Peter A. Bigot 3e8df8b369 libc: minimal: provide gmtime implementation
Implement the conversion from UNIX time to broken-down civil time per
the gmtime() and gmtime_r() functions.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-07-17 14:04:44 +02:00
Peter A. Bigot acc1703241 libc: minimal: provide types in time.h
Provide definitions for a subset of the standard time types that must be
provided by this file, in anticipation of supporting civil time in
Zephyr.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
2019-07-17 14:04:44 +02:00
Nicolas Pitre 629bd85612 mempool: significant reduction of memory waste
The mempool allocator implementation recursively breaks a memory block
into 4 sub-blocks until it minimally fits the requested memory size.

The size of each sub-blocks is rounded up to the next word boundary to
preserve word alignment on the returned memory, and this is a problem.

Let's consider max_sz = 2072 and n_max = 1. That's our level 0.

At level 1, we get one level-0 block split in 4 sub-blocks whose size
is WB_UP(2072 / 4) = 520. However 4 * 520 = 2080 so we must discard the
4th sub-block since it doesn't fit inside our 2072-byte parent block.

We're down to 3 * 520 = 1560 bytes of usable memory.
Our memory usage efficiency is now 1560 / 2072 = 75%.

At level 2, we get 3 level-1 blocks, and each of them may be split
in 4 sub-blocks whose size is WB_UP(520 / 4) = 132. But 4 * 132 = 528
so the 4th sub-block has to be discarded again.

We're down to 9 * 132 = 1188 bytes of usable memory.
Our memory usage efficiency is now 1188 / 2072 = 57%.

At level 3, we get 9 level-2 blocks, each split into WB_UP(132 / 4)
= 36 bytes. Again 4 * 36 = 144 so the 4th sub-block is discarded.

We're down to 27 * 36 = 972 bytes of usable memory.
Our memory usage efficiency is now 972 / 2072 = 47%.

What should be done instead, is to round _down_ sub-block sizes
not _up_. This way, sub-blocks still align to word boundaries, and
they always fit within their parent block as the total size may
no longer exceed the initial size.

Using the same max_sz = 2072 would yield a memory usage efficiency of
99% at level 3, so let's demo a worst case 2044 instead.

Level 1: 4 sub-blocks of WB_DN(2044 / 4) = 508 bytes.
We're down to 4 * 508 = 2032 bytes of usable memory.
Our memory usage efficiency is now 2032 / 2044 = 99%.

Level 2: 4 * 4 sub-blocks of WB_DN(508 / 4) = 124 bytes.
We're down to 16 * 124 = 1984 bytes of usable memory.
Our memory usage efficiency is now 1984 / 2044 = 97%.

Level 3: 16 * 4 sub-blocks of WB_DN(124 / 4) = 28 bytes.
We're down to 64 * 28 = 1792 bytes of usable memory.
Our memory usage efficiency is now 1792 / 2044 = 88%.

Conclusion: if max_sz is a power of 2 then we get 100% efficiency at
all levens in both cases. But if not, then the rounding-up method has
a far worse degradation curve than the rounding-down method, wasting
more than 50% of memory in some cases.

So let's round sub-block sizes down rather than up, and remove
block_fits() which purpose was to identify sub-blocks that didn't
fit within their parent block and is now useless.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-16 14:21:21 -07:00
Nicolas Pitre 8e11970378 realloc(): struct sys_mem_pool_block is word aligned
Since commit 39cd2ebef7 ("malloc: make sure returned memory is
properly aligned") the size of struct sys_mem_pool_block size is
rounded up to the next word boundary.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-16 14:42:37 +02:00
Joakim Andersson 7a93e948a9 kernel: lib: Add convert functions for hex strings and binary arrays
Move duplicate hex2bin and add bin2hex function so that application can
use the functions and avoid code duplication.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2019-07-16 12:44:18 +02:00
Nicolas Pitre 3c0cc08657 prf.c: handle denormals properly
Denormals need to be normalized to be displayed properly.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-14 23:07:44 -04:00
Nicolas Pitre 53169743d2 prf.c: properly format INF/NAN/zero with prefix
The space or plus prefix must appear when requested even with INF and
NAN. And no zero-padding in that case.

Also, 0.0 and -0.0  are distinct values. It is necessary to display
the minus sign with a negative zero.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-14 23:07:44 -04:00
Nicolas Pitre 90ec5360be prf.c: fix wrong results with %g conversion
The precision parameter to the %g conversion indicates the maximum
number of significant digits and not the number of digits to appear
after the radix character. Here's a few examples this patch fixes:

                                expected        before
----------------------------------------------------------
printf("%.3g", 150.12)          150             150.12
printf("%.2g", 150.1)           1.5e+02         150.1
printf("%#.3g", 150.)           150.            150.000
printf("%#.2g", 15e-5)          0.00015         0.00
printf("%#.4g", 1505e-7)        0.0001505       0.0002
printf("%#.4g", 1505e-8)        1.505e-05       1.5050e-05

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-14 23:07:44 -04:00
Nicolas Pitre 132a286c39 prf.c: fix display of float exponent >= 100
The code accounts only for 2 exponent digits even though the exponent
may grow up to 308. Before this change, printf("%g", 1e300) would
produce "1e+N0".

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-14 23:07:44 -04:00
Nicolas Pitre f286eda6f0 prf.c: remove arbitrary large stack buffer usage
The on-stack work buffer occupies 201 bytes by default. Now that we've
made the code able to cope with virtually unlimited width and precision
values, we can reduce stack usage to its strict minimum i.e. 25 bytes.

This allows for some additional sprintf tests exercizing wide results.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-14 23:07:44 -04:00
Nicolas Pitre d28434b4fa prf.c: remove buffer limitation on precision and padding for floats
Even if the code used to limit the precision to the on-stack buffer
size, it was still possible to do:

    printf("%f", 1.0e300);

which would overflow the stack and crash the program. Let fix this issue
and remove the precision limitation by recording the number of zeroes to
insert while converting the value and generating those zeroes only
when outputting the data.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-14 23:07:44 -04:00
Nicolas Pitre 7c7f107885 prf.c: remove buffer limitation on field width and padding for integers
Zero-padding of integers took place in the on-stack buffer before
justification. Let's perform that padding on the fly while sending
out data instead.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-14 23:07:44 -04:00
Nicolas Pitre 33312cfd98 prf.c: remove buffer limitation on field width and string copy
The z_prf() function currently allocates a 200-byte buffer on the
stack to copy strings into, and then perform left/right alignment
and padding. Not only this is a pretty large chunk of stack usage,
but this imposes limitations on field width and string length. Also
the string is copied not only once but _thrice_ making this code
less than optimal.

Let's rework the code to get rid of both the field width limit and
string length limit, as well as the two extra memory copy instances.

While at it, let's fixes printf("%08s", "abcd") which used to
produce "0000abcd".

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-14 23:07:44 -04:00
Nicolas Pitre 4ad2a8f990 prf.c: don't be silent with unknown conversion specifiers
Mimic the glibc behavior when encountering an unknown conversion
specifier rather than silently skipping it.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-14 23:07:44 -04:00
Nicolas Pitre ab59209ea6 prf.c: abstract output method call
This makes for nicer code by avoiding repetitions of the same pattern.
Changes to come will make more use of it.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-14 23:07:44 -04:00
Nicolas Pitre e1d8c1f8ca prf.c: implement the "hh" length modifier
For completeness.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-14 23:07:44 -04:00
Nicolas Pitre e9b1cc5f31 prf.c: code and style cleanup
Some cleanups before further changes:

- Remove dead leftover from the "case 's'" code.

- Remove needless parents and casts.

- Remove "register" qualifier as it is ignored. The compiler knows
  better these days.

- Adjust tabs assuming standard 8-columns tab spacing.

- Make multi-line comments start with "/*" on a line of its own.

- Make the format string const to match  prototypes in other files.

- Declare boolean variable and parameters as bool.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-14 23:07:44 -04:00
Nicolas Pitre ff7e4e69c8 realloc(): fix possible memory leak
If size is equal to zero, and ptr is not NULL, then the call must be
equivalent to free(ptr).

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-12 14:08:02 -07:00
Nicolas Pitre ffab197928 libc: fix memchr() prototype
The standard memchr() uses an int for its second argument.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-10 13:42:31 -07:00
Timo Teräs 55dc481a15 libc: add strnlen implementation
This is standard function and useful for application writers.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
2019-07-10 13:41:20 -07:00
Jukka Rissanen b889120ca7 Revert "libc: types: Remove wrong definition"
This reverts commit 2a63e342f4.

This needs to be reverted as otherwise the type of ssize_t will be
"unsigned long" which is not correct.

    (gdb) ptype ssize_t
    type = unsigned long

For example this check would fail in that case

    ssize_t foo(void)
    {
        return -1;
    }
    ...
    if (foo() < 0) {
        printk("This is never called\n");
    }

Fixes #17378

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2019-07-09 21:55:05 +03:00
Jan Van Winkel 18ef131c80 gui: Move lvgl into a zephyr module
Removed lvgl sources from CMakefile.txt and only keep zephyr glue
logic.

Further added lvgl module to west.yml.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-07-06 07:58:44 -04:00
Nicolas Pitre 1b359e6426 limits.h: streamline value definitions
Compilers (at least gcc and clang) already provide max value definitions
for basic types. It makes sense to rely on them to properly support
both 32-bit and 64-bit builds.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-05 10:05:37 -04:00
Nicolas Pitre 39cd2ebef7 malloc: make sure returned memory is properly aligned
The accounting data stored at the beginning of a memory block used by
malloc must push the returned memory address to a word boundary. This
is already the case on 32-bit systems, but not on 64-bit systems where
e.g. struct k_mem_block_id still has a size of 4.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-03 14:17:29 -07:00
Andy Ross ee4c23cc1f CMSIS v2: Work around time unit confusion
The current CMSIS v2 implementation is clearly assuming that timeout
arguments being passed to e.g. osDelay() are in units of Zephyr ticks,
not milliseconds as specified by ARM or (inconsistently) assumed by
our test code.

Most tests work with the ~100 Hz default tick rate, but they tend to
fail on precision issues at higher tick rates.  Force the CMSIS v2
applications to be 1000 Hz for now as a workaround, and detect the
mismatch as a build failure.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-07-02 22:52:29 -04:00
Nicolas Pitre fc4ca923bb mempool: fully use the inline free block bitmap on 64-bit targets
The "bits" field in struct sys_mem_pool_lvl is unioned with a pointer.
That leaves more space for inline free bits on 64-bit targets.
Let's declare it as an array and adjust its size based on the pointer
size. On 32-bit targets the generated code remains identical.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-02 19:41:20 -07:00
Nicolas Pitre cf974371fb mempool: make alignment/rounding 64-bit compatible
Minimum alignment and rounding must be done on a word boundary. Let's
replace _ALIGN4() with WB_UP() which is equivalent on 32-bit targets,
and 64-bit aware.

Also enforce a minimal alignment on the memory pool. This is making
a difference mostly on64-bit targets where the widely used 4-byte
alignment is not sufficient.

The _ALIGN4() macro has no users left so it is removed.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-02 19:41:20 -07:00
Andrew Boie d045bd7673 lib: os: exclude z_arch_printk_char_out()
This function doesn't do anything, and only exists so that
it can be overridden later, exclude from coverage reports.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-28 20:04:29 -07:00
Andrew Boie 05212e823f lib: os: fix vsnprintk coverage
vsnprintk() was uncovered. Simply adjust snprintk() to use
it, instead of duplicating logic.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-28 20:04:29 -07:00
Anas Nashif 5b0aa794b2 cleanup: include/: move misc/reboot.h to power/reboot.h
move misc/reboot.h to power/reboot.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif efb8df5366 cleanup: include/: move misc/stack.h to debug/stack.h
move misc/stack.h to debug/stack.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif a2fd7d70ec cleanup: include/: move misc/util.h to sys/util.h
move misc/util.h to sys/util.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif d222553931 cleanup: include/: move misc/speculation.h to sys/speculation.h
move misc/speculation.h to sys/speculation.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 536dd5a71f cleanup: include/: move misc/slist.h to sys/slist.h
move misc/slist.h to sys/slist.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 1859244b64 cleanup: include/: move misc/rb.h to sys/rb.h
move misc/rb.h to sys/rb.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 9ab2a56751 cleanup: include/: move misc/printk.h to sys/printk.h
move misc/printk.h to sys/printk.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 0c9e280547 cleanup: include/: move misc/mutex.h to sys/mutex.h
move misc/mutex.h to sys/mutex.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 08ee8b09ba cleanup: include/: move misc/mempool.h to sys/mempool.h
move misc/mempool.h to sys/mempool.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 1ed300b318 cleanup: include/: move misc/mempool_base.h to sys/mempool_base.h
move misc/mempool_base.h to sys/mempool_base.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 6ecadb03ab cleanup: include/: move misc/math_extras.h to sys/math_extras.h
move misc/math_extras.h to sys/math_extras.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 447311ec3e cleanup: include/: move misc/libc-hooks.h to sys/libc-hooks.h
move misc/libc-hooks.h to sys/libc-hooks.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 8be9f5de03 cleanup: include/: move misc/fdtable.h to sys/fdtable.h
move misc/fdtable.h to sys/fdtable.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 896b8d3c50 cleanup: include/: move misc/errno_private.h to sys/errno_private.h
move misc/errno_private.h to sys/errno_private.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 5eb90ec169 cleanup: include/: move misc/__assert.h to sys/__assert.h
move misc/__assert.h to sys/__assert.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 7435e5e089 cleanup: include/: move ring_buffer.h to sys/ring_buffer.h
move ring_buffer.h to sys/ring_buffer.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 9e35d53d1f cleanup: include/: move display.h to drivers/display.h
move display.h to drivers/display.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif f901e26de9 cleanup: include/: move hwinfo.h to drivers/hwinfo.h
move hwinfo.h to drivers/hwinfo.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif fe051a9055 cleanup: include/: move flash.h to drivers/flash.h
move flash.h to drivers/flash.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 0abdacf3a4 cleanup: include/: move json.h to data/json.h
move json.h to data/json.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 4e48e87fd2 cleanup: include/: move crc.h to sys/crc.h
move crc.h to sys/crc.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif bd977d06f8 cleanup: include/: move base64.h to sys/base64.h
move base64.h to sys/base64.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif e1e05a2eac cleanup: include/: move atomic.h to sys/atomic.h
move atomic.h to sys/atomic.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Anas Nashif 656f4dfdac cleanup: include/: move fs.h to fs/fs.h
move fs.h to fs/fs.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-27 22:55:49 -04:00
Daniel Leung 1c5fa6a128 cmake: use sdk-ng built toolchain for x86_64
This adds the necessary bits to utilize the x86_64 toolchain
built by sdk-ng for x86_64 when toolchain variant is either
zephyr or xtools. This allows decoupling the builds from
the host toolchain.

Newlib is also available with this toolchain so remove
the Kconfig restriction on CONFIG_NEWLIB_LIBC.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-06-27 16:08:32 -04:00
Flavio Ceolin 2a63e342f4 libc: types: Remove wrong definition
types.h was wrongly defining unsigned as signed and following
undefining it. This definition was not being used anywhere though.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-06-27 07:17:04 -04:00
Ioannis Glaropoulos ff07fc7f0a lib: libc: fix alignment of HEAP base address for ARM
In ARM builds with support for user mode, i.e. with
CONFIG_USERSPACE=y, we need to align the beginning
of the heap space, to respect the ARM MPU region
alignment requirements.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-26 09:11:45 -04:00
Ioannis Glaropoulos 53ec19c3cc lib: libc: newlib: define USED_RAM_END_ADDR only where it is needed
USED_RAM_END_ADDR is not used when Kconfig option
CONFIG_NEWLIB_LIBC_ALIGNED_HEAP_SIZE is defined,
therefore, we do not need to define the macro in
that specific case.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-26 09:11:45 -04:00
Nicolas Pitre f32330b22c stdint.h: streamline type definitions
Compilers (at least gcc and clang) already provide definitions to
create standard types and their range. For example, __INT16_TYPE__ is
normally defined as a short to be used with the int16_t typedef, and
__INT16_MAX__ is defined as 32767. So it makes sense to rely on them
rather than hardcoding our own, especially for the fast types where
the compiler itself knows what basic type is best.

Using compiler provided definitions makes even more sense when dealing
with 64-bit targets where some types such as intptr_t and size_t must
have a different size and range. Those definitions are then adjusted
by the compiler directly.

However there are two cases for which we should override those
definitions:

* The __INT32_TYPE__ definition on 32-bit targets vary between an int
  and a long int depending on the architecture and configuration.
  Notably, all compilers shipped with the Zephyr SDK, except for the
  i586-zephyr-elfiamcu variant, define __INT32_TYPE__ to a long int.
  Whereas, all Linux configurations for gcc, both 32-bit and 64-bit,
  always define __INT32_TYPE__ as an int. Having variability here is
  not welcome as pointers to a long int and to an int are not deemed
  compatible by the compiler, and printing an int32_t defined with a
  long using %d makes the compiler to complain, even if they're the
  same size on 32-bit targets. Given that an int is always 32 bits
  on all targets we might care about, and given that Zephyr hardcoded
  int32_t to an int before, then we just redefine __INT32_TYPE__ and
  derrivatives to an int to keep the peace in the code.

* The confusion also exists with __INTPTR_TYPE__. Looking again at the
  Zephyr SDK, it is defined as an int, even even when __INT32_TYPE__ is
  initially a long int. One notable exception is i586-zephyr-elf where
  __INTPTR_TYPE__ is a long int even when using -m32. On 64-bit targets
  this is always a long int. So let's redefine __INTPTR_TYPE__ to always
  be a long int on Zephyr which simplifies the code, works for both
  32-bit and 64-bit targets, and mimics what the Linux kernel does.
  Only a few print format strings needed adjustment.

In those two cases, there is a safeguard to ensure the type we're
enforcing has the right size and fail the build otherwise.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-25 23:29:22 -04:00
Nicolas Pitre d4b60d691c malloc: no longer need to round mempool's max_sz
Since commit 465b2cf31b this value is rounded at compile time instead.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-25 23:24:53 -04:00
Nicolas Pitre 1140bd090c mempool: properly use the inline free block bitmap
The free block bitmap uses either extra memory specified by a pointer
in struct sys_mem_pool_lvl or the space occupied by that pointer
directly if the bitmap length is small enough to fit it.

But the test is wrong. the inline bitmap should be used if the number
of required bits is smaller or _equal_ to the pointer size. Not doing so
would wrongly bounce the free block bitmap to extra memory when the
number of blocks is exactly 32, which is in disagreement with
Z_MPOOL_LBIT_WORDS() that correctly returns 0 in that case.

In theory that mean that this bug would causes an overflow of the free
block bitmap whenever one level has exactly 32 blocks. But right now
there is a separate bug fixed separately that over-sizes the extra block
bitmap mitigating this bug.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-25 23:24:05 -04:00
Andy Ross d0490fe9f9 lib/os/mempool: Fix corruption case with block splitting
The block_fits() predicate was borked.  It would check that a block
fits within the bounds of the whole heap.  But that's not enough:
because of alignment changes between levels the sub-blocks may be
adjusted forward.  It needs to fit inside the PARENT block that it was
split from.

What could happen at runtime is that the last subblocks of a
misaligned parent block would overlap memory from subsequent blocks,
or even run off the end of the heap.  That's bad.

Change the API of block_fits() a little so it can extract the parent
region and do this properly.

Fixes #15279.  Passes test introduced in #16728 to demonstrate what
seems like the same issue.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-06-25 18:51:08 -07:00
Nicolas Pitre 465b2cf31b mempool: fix corruption of the free block bitmap and beyond
In z_sys_mem_pool_block_alloc() the size of the first level block
allocation is rounded up to the next 4-bite boundary. This means one
or more of the trailing blocks could overlap the free block bitmap.

Let's consider this code from kernel.h:

  #define K_MEM_POOL_DEFINE(name, minsz, maxsz, nmax, align) \
       char __aligned(align) _mpool_buf_##name[_ALIGN4(maxsz * nmax) \
                              + _MPOOL_BITS_SIZE(maxsz, minsz, nmax)]; \

The static pool allocation rounds up the product of maxsz and nmax not
size of individual blocks. If we have, say maxsz = 10 and nmax = 20,
the result of _ALIGN4(10 * 20) is 200. That's the offset at which the
free block bitmap will be located.

However, because z_sys_mem_pool_block_alloc() does this:

        lsizes[0] = _ALIGN4(p->max_sz);

Individual level 0 blocks will have a size of 12 not 10. That means
the 17th block will extend up to offset 204, 18th block up to 216, 19th
block to 228, and 20th block to 240. So 4 out of the 20 blocks are
overflowing the static pool area and 3 of them are even located
completely outside of it.

In this example, we have only 20 blocks that can't be split so there is
no extra free block bitmap allocation beyond the bitmap embedded in the
sys_mem_pool_lvl structure. This means that memory corruption will
happen in whatever data is located alongside the _mpool_buf_##name
array. But even with, say, 40 blocks, or larger blocks, the extra bitmap
size would be small compared to the extent of the overflow, and it would
get corrupted too of course.

And the data corruption will happen even without allocating any memory
since z_sys_mem_pool_base_init() stores free_list pointer nodes into
those blocks, which in turn may get corrupted if that other data is
later modified instead.

Fixing this issue is simple: rounding on the static pool allocation is
"misparenthesized". Let's turn

	_ALIGN4(maxsz * nmax)

into

	_ALIGN4(maxsz) * nmax

But that's not sufficient.

In z_sys_mem_pool_base_init() we have:

        size_t buflen = p->n_max * p->max_sz, sz = p->max_sz;
        u32_t *bits = (u32_t *)((u8_t *)p->buf + buflen);

Considering the same parameters as above, here we're locating the extra
free block bitmap at offset `buflen` which is 20 * 10 = 200, again below
the reach of the last 4 memory blocks. If the number of blocks gets past
the size of the embedded bitmap, it will overlap memory blocks.

Also, the block_ptr() call used here to initialize the free block linked
list uses unrounded p->max_sz, meaning that it is initially not locating
dlist nodes within the same block boundaries as what is expected from
z_sys_mem_pool_block_alloc(). This opens the possibility for allocated
adjacent blocks to overwrite dlist nodes, leading to random crashes in
the future.

So a complete fix must round up p->max_sz here too.

Given that runtime usage of max_sz should always be rounded up, it is
then preferable to round it up once at compile time instead and avoid
further mistakes of that sort. The existing _ALIGN4() usage on p->max_sz
at run time are then redundant.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-24 12:10:09 -07:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
David B. Kinder 2aebc980e2 doc: fix Kconfig misspellings
Fix misspellings in Kconfig files missed during regular reviews.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2019-06-18 15:07:52 -04:00
Andrew Boie db84a76379 lib: os: remove dead code
If multithreading is disabled, thread_entry() never runs
since we cannot create threads; the non-multithreading case
was simply dead code.

Indicate to code coverage that CODE_UNREACHABLE should be
skipped.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-06-18 09:08:01 -04:00
Nicolas Pitre c47bf1fa5e prf.c: implement the ll length modifiers
This allows for printing long long values. Because the code size
increase may be significant, this is made optional on 32-bit targets.
On 64-bit targets this doesn't change the code much as longs and
long longs are the same size so it is always enabled in that case.

The test on MAXFLD has to be adjusted accordingly. Yet, its minimum
value wasn't large enough to store a full-scale octal value, so this
is fixed as well.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-17 10:58:09 -07:00
Nicolas Pitre 2b32059a61 printk: make it 64-bit compatible
On 64-bit systems the most notable difference is due to longs and
pointers being 64-bit wide. Therefore there must be a distinction
between ints and longs. Similar to the prf.c case, this patch properly
implements the h, hh, l, ll and z length modifiers as well as some small
cleanups.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-17 10:28:44 -07:00
Nicolas Pitre a6891e0313 prf.c: make it 64-bit compatible
On 64-bit systems the most notable difference is due to longs and
pointers being 64-bit wide. Therefore there must be a distinction
between ints and longs.

This patch:

- Make support functions take a long rather than an int as this can
  carry both longs and ints just fine.

- Use unsigned values in _to_x() to cover the full unsigned range
  and avoid sign-extending big values. Negative values are already
  converted to unsigned after printing the minus sign. This also makes
  division and modulus operations slightly faster.

- Remove excessive casts around va_arg() and use proper types with it.

- Implement the l and z length modifiers as they're significant on
  64-bit targets. While at it, throw in the z modifier as well.
  Since they all come down to 32-bit values on 32-bit targets, the
  added code should get optimized away as duplicate by the compiler
  in that case.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-13 12:55:17 -07:00
Nicolas Pitre 03170c040c string.c: make it 64-bit compatible
Casting a pointer to an int produces warnings with 64-bit targets.
Furthermore, an int is not always the optimal memory element that
can be copied in that case.

Let's use uintptr_t to cast pointers to integers for alignment
determination purposes, and mem_word_t to denote the optimal memory
"word" that can be copied on the platform.

The mem_word_t definition is equivalent to uintptr_t by default.
However, some 32-bit targets such as ARM platforms with the LDRD/STRD
instructions could benefit from word_t being an uint64_t.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-07 13:19:51 -07:00
Nicolas Pitre eeb2e67f2b time_t: define using a fixed-width type
Make sure type_t and suseconds_t keep the same size on 32-bit and
64-bit targets.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-06 14:22:09 -07:00
Anas Nashif 4c32258606 style: add braces around if/while statements
Per guidelines, all statements should have braces around them. We do not
have a CI check for this, so a few went in unnoticed.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-06 15:20:21 +02:00
Nicolas Pitre 4323d381e7 json: make it 64-bit compatible
The struct json_obj_descr definition allocates only 2 bits for type
alignment. Instead of using them literally minus 1 to encode 1, 2, or 4,
let's store the alignment's shift value instead so that 1, 2, 4 or 8 can
be encoded with the same 2 bits to accommodate 64-bit builds.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-05 07:47:41 -04:00
Christian Tavares 543de09357 lib: updatehub: add support ipv6
This extends the UpdateHub library code to allow the
use of IPV6 for communication.

Signed-off-by: Christian Tavares <christian.tavares@ossystems.com.br>
2019-06-05 00:20:37 +02:00
Christian Tavares c5d74eccda lib: updatehub: add suport a CoAPS/DTLS
This extends the UpdateHub library code to allow the
use of CoAPS/DTLS for communication.

Refs: #13039.

Signed-off-by: Christian Tavares <christian.tavares@ossystems.com.br>
2019-06-05 00:20:37 +02:00
Christian Tavares 297ac3765f lib: updatehub: Add UpdateHub.io support
UpdateHub is an enterprise-grade solution which makes simple to
remotely update all your embedded devices in the field. It
handles all aspects related to sending Firmware Over-the-Air(FOTA)
updates with maximum security and efficiency, while you focus in
adding value to your product.

Signed-off-by: Christian Tavares <christian.tavares@ossystems.com.br>
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
2019-06-05 00:20:37 +02:00
Jan Van Winkel 539d16fca8 gui: Corrected RGB888 pointer in LVGL write function
Corrected buffer pointer in LVGL zephyr_vdb_write function for
converting RGBA8888 to RGB888 pixel format.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-05-30 09:33:07 -04:00
Paul Sokolovsky af529d1158 libc: minimal: Implement exit()/_exit() functions.
Behavior is similar to newlib version: print "exit" message and go
into infinite loop.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-23 09:27:59 -04:00
Ulf Magnusson 927012dd7f lvgl: kconfig: Remove menu and use a 'menuconfig' symbol
The 'Graphical user interface' menu currently contains just the
'LittlevGL Support' symbol and its indented children.

To remove one menu level, remove the 'Graphical user interface' menu,
rename the symbol to 'LittlevGL GUI library' (consistent with e.g.
'Logging' and 'Bluetooth'), and turn it into a 'menuconfig' symbol.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-05-21 14:19:20 -05:00
Alexander Mihajlovic f19787bb84 posix: Fix calculation of clock base in clock_settime
Previous version calculated rt_clock_base incorrectly by subtracting
clock_gettime from the specified time. Effectively the following
formula was used.

    rt_clock_base := new_time - clock_gettime()

This is clearly incorrect when we consider what should happen if we
call clock_settime with the result of clock_gettime. It ought to be
approximately a no-op, but instead we end up zeroing the clock.

    rt_clock_base := clock_gettime() - clock_gettime() = 0

This patch fixes clock_settime by instead using k_uptime_get to
calculate rt_clock_base, like so:

    rt_clock_base := new_time - k_uptime_get()

Trying the earlier thought experiment we get:

    rt_clock_base := clock_gettime() - k_uptime_get()

Using the definition of clock_gettime this expands to:

    rt_clock_base := (rt_clock_base + k_uptime_get()) - k_uptime_get()

The two k_uptime_get() terms cancel out, leaving:

    rt_clock_base := rt_clock_base

I.e. the no-op that we expect when calling clock_settime with
the result of clock_gettime.

Note: The bug is only observable when rt_clock_base is non-zero.
So when clock_settime is called for the first time, it will appear
to work correctly since rt_clock_base is initialized to 0.

Signed-off-by: Alexander Mihajlovic <alexander.mihajlovic@endian.se>
2019-05-21 08:24:59 -04:00
Benoit Leforestier 472ea92e79 Build: Build with newlib-nano c library
Add an option for building with newlib-nano library.
The newlib-nano library for ARM embedded processors is a part of the
GNU Tools for ARM Embedded Processors.
Add mem_alloc tests with newlib nano.

Signed-off-by: Benoit Leforestier <benoit.leforestier@gmail.com>
2019-05-15 10:46:44 -05:00
Jakob Olesen c8708d9bf3 misc: Replace uses of __builtin_*_overflow() with <misc/math_extras.h>.
Use the new math_extras functions instead of calling builtins directly.

Change a few local variables to size_t after checking that all uses of
the variable actually expects a size_t.

Signed-off-by: Jakob Olesen <jolesen@fb.com>
2019-05-14 19:53:30 -05:00
Wentong Wu 6922d93d8e lib/posix: correct the meaning of CONFIG_MAX_PTHREAD_COUNT
Current code implement CONFIG_MAX_PTHREAD_COUNT as the maximum number
of POSIX threads that can ever be created, rather than the maximum
number of active POSIX threads. Use pthread_state of struct posix_thread
to track the state of posix thread in posix_thread_pool so that we can
reuse the unused posix thread.

Fixes #15516.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-05-11 08:24:36 -04:00
Paul Sokolovsky 81fa697f32 posix: Move gettimeofday declaration to <sys/time.h>
According to POSIX, that's the header which defines this function.
Similarly, nothing in POSIX indicates that <time.h> should have
access to struct timeval, so it's removed (it's made accessible
to <sys/time.h> via <sys/_timeval.h> introduced earlier).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-07 22:18:09 -04:00
Paul Sokolovsky c896f87d5d libc: minimal: Introduce sys/_timeval.h
This is implementation-level header which defines struct timeval, and
intended to be included by headers which need this structure. This
implementation scheme is compatible with Newlib, and thus provides a
step to use minlibc vs Newlib interchangeably.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-07 22:18:09 -04:00
Paul Sokolovsky d79d3eb725 libc: minimal: Define time_t and suseconds_t
According to POSIX, these types should be defined by sys/types.h.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-05-07 22:18:09 -04:00
Andrew Boie 7153a2eec5 lib: cmsis_v1: set stack size larger if coverage
Use some large value, coverage targets have lots of RAM.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-05-02 15:42:33 -04:00
Andrew Boie 8502a2ea73 lib: cmsis_v2: increase stack sizes if coverage
Set to 4096, coverage targets have lots of RAM.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-05-02 15:42:33 -04:00
Andrew Boie 16317c1a9f lib: cmsis_v2: set default dynamic stack size
Set to same default as regular stacks. This doesn't use
any extra memory until CMSIS_V2_THREAD_DYNAMIC_MAX_COUNT
is set. 0 is not a valid default if that is set.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-05-02 15:42:33 -04:00
Andrew Boie b8c560a439 newlib: fix user mode calls to _sbrk
Depending on configuration, this value could end up as
a variable and not an array symbol, causing a crash if
newlib decides to call _sbrk on behalf of a user thread,
which needs to perform arithmetic on it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-05-02 07:25:19 -04:00
Balaji Kulkarni a25dce964b libc: minimal: Add bsearch function
This function implements generic binary-search.

Fixes #15159

Signed-off-by: Balaji Kulkarni <balaji.kulkarni92@gmail.com>
2019-04-25 20:39:36 -07:00
Tomasz Gorochowik 1afa9d0e5d libc: minimal: fix realloc function
Excerpt from the manual:

  If ptr is NULL, then the call is equivalent to malloc(size) [...]

Without this commit, such calls end with a BUS FAULT.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-04-19 16:17:14 -04:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier.  Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.

By default all files without license information are under the default
license of Zephyr, which is Apache version 2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-04-07 08:45:22 -04:00
Patrik Flykt 4aa48833d8 subsystems: Rename reserved function names
Rename reserved function names in the subsys/ subdirectory except
for static _mod_pub_set and _mod_unbind functions in bluetooth mesh
cfg_srv.c which clash with the similarly named global functions.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Andrew Boie c8aee7b413 sys_mem_pool: use sys_mutex
Permission management no longer necessary, the former
parameter for the mutex is now simply ignored.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-03 13:47:45 -04:00
Andrew Boie f0835674a3 lib: os: add sys_mutex data type
For systems without userspace enabled, these work the same
as a k_mutex.

For systems with userspace, the sys_mutex may exist in user
memory. It is still tracked as a kernel object, but has an
underlying k_mutex that is looked up in the kernel object
table.

Future enhancements will optimize sys_mutex to not require
syscalls for uncontended sys_mutexes, using atomic ops
instead.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-03 13:47:45 -04:00
Pawel Dunaj 2189d9b56d lib: mempool: Alloc and break must happen atomically
This fixes a regression caused by 41e90630d.

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-04-03 12:36:36 -04:00
Patrik Flykt 21358baa72 all: Update unsigend 'U' suffix due to multiplication
As the multiplication rule is updated, new unsigned suffixes
are added in the code.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Flavio Ceolin c2b25151cb lib: printk: Make if/iterations evaluate boolean operands
MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-26 22:06:45 -04:00
Flavio Ceolin 44fc55e209 lib: crc16_sw: Add missing U to unsigned constants
Add U to unsigned integer constants to avoid implicit cast.

MISRA-C rule 10.1

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-26 22:06:45 -04:00
Flavio Ceolin ce696e9aa2 lib: rb: Make operands have an appropriate essential type
MISRA-C 8.10.2 defines essential operand types and how to handle them
through rules 10.1 .. 10.5. This commit adds an U to unsigned constants
to avoid implicit casts and make if/while statements evaluate a boolean
to avoid other types being casted to boolean.

MISRA-C rules 10.1, 10.2 and 10.3

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-26 22:06:45 -04:00
Flavio Ceolin 9d5936c04f lib: posix: fs: Fix access invalid memory
fs_dirent.name is MAX_FILE_NAME + 1 bytes long, not PATH_MAX. Just
fixing it to avoid access invalid memory.

Coverity CID: 186037

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-23 09:52:51 -05:00
Vincent Wan 3609e261bb net: sockets: move fcntl back to socket_offload.c
We are reverting the changes in commit
55b3f05932 given build errors are seen
when fcntl.h is included, as it declares fcntl() as a non-static
function. The same function cannot be declared as both static and
non-static.

Instead, we avoid redefining fcntl() in lib/os/fdtable.c specifically
for case of the SimpleLink family, til we have support for the new
socket_op_vtable.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2019-03-20 11:36:18 -05:00
Pawel Dunaj 41e90630d7 lib: mempool: Synchronize level checks
Do not perform early level usage check. This can lead to situation
where block is seen as available on level when it was taken from
the other context.

Fixes: #14504

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-03-19 13:38:46 -05:00
Pawel Dunaj 2c7d68009a lib: mempool: Return error if no block found
Return -ENOMEM if no block is available on any level.

Fixes: #14504

Signed-off-by: Pawel Dunaj <pawel.dunaj@nordicsemi.no>
2019-03-19 13:38:46 -05:00
Krzysztof Chruscinski 9502b8b80b lib: os: ring_buffer: Fix not handled return value
Some function return values were not handled. Added assert in case
those functions return error. It is possible only if same ring buffer
instance is used without any protection from multiple contexts.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-03-14 08:40:18 +01:00
Ulf Magnusson 53376394b7 kconfig: Remove blank lines at the beginning/end of files
Maybe this is some "just in case" thing that got copied around. There's
no need to have a blank line at the beginning or end of Kconfig files.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-13 07:29:42 -05:00
Kumar Gala 7aa8e43add libc: newlib: Cleanup/fix setting of system include paths
When we build with newlib we don't set -nostdinc.  In that case make
sure that we leave it to the toolchain to set the system include paths.

The one exception to leaving to the toolchain to set the system include
paths is the path to the newlib headers.  Since we build
with -ffreestanding we need to make sure the newlib header path is the
before the toolchain headers. Otherwise the toolchain's 'freestanding'
headers get picked up and that causes issues (for example getting PRI*64
defined properly from inttypes.h due to __STDC_HOSTED__ being '0').

For newlib we accomplish this by having the only system header specified
by zephyr_system_include_directories() being just the newlib headers.

Note: for minlibc we leave things alone as things just happen to work as
the -I include of the libc headers takes precedence over -isystem so we
get the libc headers over the toolchain ones.  For the newlib case it
appears that setting both -I and -isystem for the same dir causes the
-I to be ignored.

Fixes #14310

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-13 06:50:23 -05:00
Maureen Helm f8c4808d96 boards: mimxrt10{50,60}_evk: Set lvgl defaults in board defconfigs
Configure lvgl defaults for imx rt boards in their respective board
defconfigs rather than the lvgl sample application.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2019-03-13 06:02:42 -05:00
Kumar Gala 276f766317 libc: rename _zephyr_fputc to zephyr_fputc
For some reason we missed _zephyr_fputc in commit
4344e27c26.  Rename _zephyr_fputc to just
zephyr_fputc and fixup associated code to build.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-12 13:59:06 -05:00
Kumar Gala c82f23cada libc: Fix fwrite function name
Commit 4344e27c26 changed the reserved
function names, but got the naming wrong for fwrite.  Just use the
name zephyr_fwrite everywhere.

Fixes #14275

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-12 13:59:06 -05:00
Patrik Flykt 4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00
Andrew Boie 7416457b87 lib: fdtable: safely bounds check file descriptors
Prevent speculative attacks with out-of-bounds fd
values.

Won't affect code generation for systems that don't
enable CONFIG_BOUNDS_CHECK_BYPASS_MITIGATION.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-11 09:54:04 -07:00
Dennis Wildmark ce4b282717 lib: cmsis_rtos_v2: changed printformat that produced warnings
Changed the print format for unsigned 32-bit variables that produced
warnings when compiled with newlib instead of the standard C library.
Chose to replace %d with PRIu32 because the latter is more portable
and adapts to the types of the standard C libraries.
Tested with and without newlib, and with sanitycheck.

Signed-off-by: Dennis Wildmark <dennis.wildmark@assaabloy.com>
2019-03-11 11:02:20 -05:00
Ulf Magnusson da704c453f kconfig: lvgl: Remove redundant LVGL dep.
Appears within an 'if LVGL'.

'if FOO' is just shorthand for adding 'depends on FOO' to each item
within the 'if'. Dependencies on menus work similarly. There are no
"conditional includes" in Kconfig, so 'if FOO' has no special meaning
around a source. Conditional includes wouldn't be possible, because an
if condition could include (directly or indirectly) forward references
to symbols not defined yet.

Tip: When adding a symbol, check its dependencies in the menuconfig
('ninja menuconfig', then / to jump to the symbol). The menuconfig also
shows how the file with the symbol got included, so if you see
duplicated dependencies, it's easy to hunt down where they come from.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-03-09 09:48:25 -05:00
Filip Brozovic fb3d9744cc lvgl: lvgl_color_1: add support for horizontally tiled displays
Enable displays which do not have SCREEN_INFO_MONO_VTILED set to work
with LittlevGL

Signed-off-by: Filip Brozovic <fbrozovic@gmail.com>
2019-03-07 07:18:50 -05:00
Patrik Flykt e8f6ea2c8c lib/os: Remove case ranges from printk
Remove case ranges from printk in order to clean up GNUisms
and make the code standards compliant.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-06 17:44:04 -05:00
Anas Nashif 3caea8c81e libc: minimal: add prototype of rand()
Add prototype of rand() that can be defined in tests.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-03-04 17:32:08 -08:00
Andrew Boie 7707060959 userspace: get rid of app section placeholders
We used to leave byte-long placeholder symbols to ensure
that empty application memory sections did not cause
build errors that were very difficult to understand.

Now we use some relatively portable inline assembly to
generate a symbol, but don't take up any extra space.

The malloc and libc partitions are now only instantiated
if there is some data to put in them.

Fixes: #13923

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-04 08:05:16 -08:00
Tim Sørensen (TIMS) 630af8a65f misc: assert_post_action: Added __weak keyword.
Added __weak keyword to to support overriding assert_post_action().
This allows system designers to change/augment the assert behaviour,
i.e. add logging to persistant storage of program counter, line
number etc, and/or change reboot behaviour.

Signed-off-by: Tim Sørensen (TIMS) <tims@oticon.com>
2019-03-02 12:26:21 -05:00
Charles E. Youse 3522e05f76 posix/pthreads: fix pthread_barrier_wait() behavior to match Posix
Exactly one caller of pthread_barrier_wait() should receive a return
value of PTHREAD_BARRIER_SERIAL_WAIT; all others should receive zero
(or an error code). Added a test to match.

Fixes: #9953

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-03-02 03:40:06 +01:00
Flavio Ceolin 1556fce845 libc: ctype: Fix operations between signed and unsigned types
MISRA-C says that char type should not be used in arithmetically as the
data doesn't represent numbers.

MISRA-C rules 10.1 and 10.2

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-01 09:22:24 +01:00
Andy Ross 85d895c60e lib/os: Remove recursion from mempool and rbtree
MISRA rules (see #11425) forbid recursive algorithms.  In the case of
rb_walk(), it's not actually used anywhere but a test right now, so we
can simply disable the API when CONFIG_MISRA_SANE is defined.  Mempool
had a (IMHO, fairly clever) tail recursive loop in bfree_recombine()
which can be trivially transformed into an only slightly uglier
iterative version.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-28 10:06:35 -08:00