Commit graph

99049 commits

Author SHA1 Message Date
Andrew Boie
65da531aed x86: fix exception stack pointer reporting
If the faulting context is in user mode, then we are
not on the same stack due to HW-level stack switching
on privilege elevation, and the faulting ESP is on
the stack itself.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-15 09:48:37 -05:00
Andrew Boie
21337019b0 x86: get oops reason code more robustly
The code did not consider privilege level stack switches.
We have the original stack pointer in the NANO_ESF,
just use that.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-15 09:48:37 -05:00
Andrew Boie
4ae33f0b55 tests: fatal: refactor and add user mode tests
We weren't testing whether stack overflows in user mode
were correctly reported.

A more aggressive stack overflow logic is enabled if
HW-based stack overflow detection is enabled.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-15 09:48:37 -05:00
Andrew Boie
747dcbc8f2 x86: improve stack overflow detection
We now have a dedicated function to test whether
a memory region is withing the boundary of the
faulting context's stack buffer.

We use this to determine whether a page or double fault
was due to ESP being outside the bounds of the stack,
as well as when unwinding stack frames to print debug
output.

Fixes two issues:
- Stack overflows in user mode being incorrectly reported
  as just page fault exceptions
- Exceptions that occur when unwinding corrupted stacks

The type of fault which triggered the stack overflow
logic (double or page fault) is now always shown.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-15 09:48:37 -05:00
Rajavardhan Gundi
95e8a582b4 drivers: flash: spi_nor.c: Correct the calculation of SECTORS_COUNT
The patch 44758977f8 made a change where
SECTORS_COUNT was not calculated properly. This patch corrects it.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2019-02-14 22:18:25 -05:00
Daniel Glöckner
26d3576e0f ext: hal: atmel: sam: really fix GMAC priority queues related registers
Commit 0a7b45d55f ("ext: hal: atmel: sam: fix GMAC priority queues
related registers") tried to correct register offsets, but failed to do
so in the structure that is used by our driver to access the registers.

Fixes: #12945

Signed-off-by: Daniel Glöckner <dg@emlix.com>
2019-02-14 22:17:53 -05:00
Carlos Stuart
75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Aurelien Jarno
413ede4b89 driver: eth: gmac: remove ring_buf usage in the RX path
The ring_buf implementation is basically used as an array of net_buf
pointers in the RX path. The tail and head indexes are taken from the
RX descriptors and not from the ring_buf. That's why for example the
fact that head is never initialized doesn't cause problem. Only len is
used in free_rx_bufs(), but anyway this function is plainly broken as
it always free the first net_buf and doesn't set it back to NULL.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-02-14 22:15:29 -05:00
Aurelien Jarno
cc1d1478ac driver: eth: gmac: wait until the packet is sent before returning
Scale down the TX path of the GMAC driver by waiting for a packet to be
fully sent before returning from the send function. This has a small
performance impact, but has a few advantages:
- It allows the Ethernet code to modify the packet afterward, fixing PTP
  support on this board (see PR #12563).
- It returns an error to the IP stack in case of a transmit failure.
- It doesn't require net_buf to be thread safe.

This change can be reverted by changing GMAC_MULTIPLE_TX_PACKETS from 0
to 1.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-02-14 22:15:29 -05:00
Daniel Leung
1d55411a96 boards/intel_s1000_crb: fix Python string format
Fix the support script to actually use Python string formatting,
instead of C-style printf().

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-02-14 19:51:45 -05:00
Andrzej Głąbek
41e09725bb boards: nrf: Enable HW PWMs on nrf52832_mdk and nrf52840_mdk
This is a follow-up to commit e2b38e02bf.
Default PWM instances are enabled in Kconfig and DTS (with channel 0
set to LED0 pin) for these boards so that it is possible to build basic
samples blink_led and fade_led for them without extra modifications.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2019-02-14 18:50:00 -06:00
Andy Ross
86380483da kernel/work_q: Fix block-in-spinlock bug
Work queues are implemented in terms of k_queue objects which provide
their own synchronization.  In particular insertion is potentially
blocking and always acts as a reschedule point, which means that it
must not be called with spinlocks held.

Release the lock first, and do a little cleanup of the resulting
k_delayed_work_submit_to_queue() logic.

Fixes #13411

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-14 19:45:20 -05:00
Marc Herbert
82df254512 doc/getting_started: mention ZEPHYR_TOOLCHAIN_VARIANT=host briefly
Skipping the setup of a toolchain is especially nice for brand new users
who just want to give qemu_x86[_64] or native_posix a quick try, gives a
great first impression.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-02-14 19:43:25 -05:00
Alberto Escolar Piedras
65451db6b9 tracing: POSIX arch: Trace switch to main thread
Add tracing of the switch to the main thread

Relatest to #13357

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2019-02-14 15:41:19 -05:00
Alberto Escolar Piedras
eb6534ffa6 tracing: POSIX arch: Remove redundant trace call
The thread switching tracing calls are done by the kernel,
and not by the archs. So, remove the redundant trace call.

Related to #13357

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2019-02-14 15:41:19 -05:00
Alberto Escolar Piedras
143552550f tracing: Add missing isr_exit() for posix arch boards
For the native_posix board, and for the nrf52_bsim boards,
the sys_trace_irs_exit() call was missing. Add it.

Relates to #13357

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2019-02-14 15:41:19 -05:00
Andrew Boie
62d866385e x86: fix crash in _arch_buffer_validate
The code wasn't checking if the memory address to check
corresponded to a non-present page directory pointer
table entry.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Andrew Boie
9af5089dee build: remove meltdown warning
Now addressed by KPTI.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Andrew Boie
2cfeba8507 x86: implement interrupt stack trampoline
Upon hard/soft irq or exception entry/exit, handle transitions
off or onto the trampoline stack, which is the only stack that
can be used on the kernel side when the shadow page table
is active. We swap page tables when on this stack.

Adjustments to page tables are now as follows:

- Any adjustments for stack memory access now are always done
  to the user page tables

- Any adjustments for memory domains are now always done to
  the user page tables

- With KPTI, resetting a page now clears the present bit

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Andrew Boie
eea0f93a83 x86: generate user mode page tables
If kernel page table isolation is enabled, we generate a second
set of page tables. These tables, except for the shared page, have
all non-user pages marked as non-present.

The MMU generation script has been refactored:

- Debugging output has been make significantly simpler and less
  verbose

- Useless globals removed or adjusted

- MMU region list is validated as it is read

- Some tuples unpacked into individual variables to make the
  code easier to read.

- Useless command line option for output binary endian-ness
  remobved

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Andrew Boie
f093285345 x86: modify MMU APIs for multiple page tables
Current set of APIs and macros assumed that only one set
of page tables would ever be in use.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Andrew Boie
db6acbfb95 x86: set up shared kernel page
KPTI requires that there exist one kernel page marked
'present', because switching between the kernel and the
shadow page tables is not done automatically and certain
other CPU data structures must always be in a present page.

Move IDT, GDT, all TSS to this page, and set up a small
trampoline stack as a safe landing area when doing
privilege level transitions.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Andrew Boie
89a127bc8e x86: add Kconfig for KPTI
This will be enabled by default for any x86 that isn't
noted as being immune to this CPU bug.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Ulf Magnusson
732fa65956 scripts/dts: Rename dict_merge() to merge_properties()
It's special-cased for merging bindings and not a general dictionary
merging function.

Also simplify the documentation a bit.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-14 10:49:44 -06:00
Ulf Magnusson
14de997f25 scripts/dts: dict_merge(): Rename dct/merge_dct to to_dict/from_dict
Makes it easier to remember what's being merged into what. "merge_dct"
is ambiguous.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-14 10:49:44 -06:00
Ulf Magnusson
298b4431b9 scripts/dts: Do title/version/description special-casing in dict_merge()
Simpler to do it there than in merge_included_bindings().

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-14 10:49:44 -06:00
Ulf Magnusson
f0eeb11fc0 scripts/dts: Add helper for reporting !include-related errors
Makes the message end up on stderr along with the exception, and removes
some code.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-14 10:49:44 -06:00
Ulf Magnusson
35b3d440c1 scripts/dts: Replace the Bindings class with plain functions
The Bindings class was only used to implement '!include foo.yaml'
(easier to see after some things were moved out of it). Use plain
functions instead, which might be a bit more transparent and gives
simpler code.

Also remove the recursive '!include' detection for now, which is broken
in that the same .yaml being included twice will always trigger it, even
for non-circular cases.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-14 10:49:44 -06:00
Ulf Magnusson
4a99dbcf9e scripts/dts: Simplify and remove dead code in Bindings._extract_file()
As written, this function could take e.g. '!include bar', find 'foo-bar'
(due to the endswith()), and include it. This is undocumented and
doesn't seem to be used, so I'm guessing that it isn't intentional.

Removing that bug/feature also makes the code much simpler.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-14 10:49:44 -06:00
Ulf Magnusson
32e6565fd7 scripts/dts: Merge Bindings.binding() into load_bindings()
load_bindings() is trivial, and it allows some stuff to simplified, like
the check for no bindings being found, and the assignments to the
extract.globals.{bindings,bus_bindings,bindings_compat}.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-14 10:49:44 -06:00
Ulf Magnusson
706809e9b0 scripts/dts: Turn Bindings._included into a global
This is (probably) a temporary change just to be able to move some stuff
out of the Bindings class.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-14 10:49:44 -06:00
Ulf Magnusson
a1f1969331 scripts/dts: Separate out finding binding (.yaml) files
As a step in moving some functions out of the Bindings class.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-14 10:49:44 -06:00
Ulf Magnusson
d859f4f937 scripts/dts: Move initialization logic into load_bindings()
Makes main() more readable.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-14 10:49:44 -06:00
Ulf Magnusson
e17af82190 scripts/dts: Rename load_yaml_descriptions() to load_bindings()
More explicit, and consistent with other code.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-02-14 10:49:44 -06:00
Kumar Gala
1f1282afa4 scripts/dts/extract_dts_includes: Limit conf file to DT prefix defines
Only write out to the .conf file if the define starts with "DT_".  The
the conf file should only be used by sanitycheck, west, and
kconfigfunctions at this time.  In the future we should remove it, so
lets limit what's it exposing at this time.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-14 10:45:25 -06:00
Kumar Gala
1f68831197 samples: Use DT_ prefix define for DT filters
Update the filters that are extracting info from DT to use a define that
has a DT_ prefix so its clear that its coming from DT_.  Also this lets
us remove any non-DT prefixed defines in the conf db.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-14 10:45:25 -06:00
François Delawarde
74f9901b8d debug: Place Kconfig tracing options in debug submenu
Fix Kconfig options placed incorrectly in top level menu.

Signed-off-by: François Delawarde <fnde@oticon.com>
2019-02-14 10:29:06 -05:00
Jakub Rzeszutko
46a02322ec shell: allow commands to suspend shell thread
It was possible to deadlock the shell when command
suspended shell's thread and next another thread wanted
to print something on the shell.

To avoid that shell releases mutex before entering command
handler. Due to this change some  adapations to shell
internal print functions have been applied.

This change addresses following usecase:
1. A command handler needs to call a (system) function which
communicate results via a callback, and this callback is expected
to print these results. The callback is called by the system from
another thread.
2. To achieve that, the handler needs to pass `struct shell *`
to callbacks, but also some other data specific to callback.
Thus, handles allocates some structure will those fields on
the stack.
3. The handler schedules this callback to be called.
4. As a reference to stack structure is passed to the callback,
the handler can't return immediately (or stack data will go out
of scope and will be overwritten).
5. So, the handler blocks waiting for callback to finish.

Previously, this scenario led to deadlock when the callback
trying or print to shell. With these changes, it just works,
as long as main handler and callback serialize there access
to the shell structure (i.e. when callback prints, the main
handler is blocked waiting for its completion).

Signed-off-by: Jakub Rzeszutko <jakub.rzeszutko@nordicsemi.no>
2019-02-14 13:40:28 +01:00
Tomasz Gorochowik
0604c30a1b net: gptp: Fix pkt allocation with debugs enabled
Commit 44964c735e ("net/gptp: Switch GPTP to new net_pkt API") changed
the callback used for allocation (from net_pkt_get_reserve_tx to
net_pkt_alloc_with_buffer), but for compilation with
CONFIG_NET_DEBUG_NET_PKT_ALLOC enabled, both callbacks are used
(the first pointer was just overwritten, causing MPU FAULT).

This commit removes the extra callback and fixes the fault.

Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-02-14 05:15:25 -06:00
Kumar Gala
b814af827d scripts/dts/extract: Fix how we determine DT_FLASH_AREA_<X>_DEV
DT_FLASH_AREA_<X>_DEV should be the label of the flash controller.  For
flashes that are "jedec,spi-nor" the flash itself is considered the
controller.  For "soc-nv-flash" the parent of the flash is assumed to be
the controller.

Rework the logic in how we determined DT_FLASH_AREA_<X>_DEV to handle
both cases.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-14 05:13:35 -06:00
Johann Fischer
70776028f5 drivers: apds9960: fix ALS in non-trigger mode
Generate interrupt on every ALS cycle in non-trigger mode
and enable ALS saturation interrupt.

resolves: #11989

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2019-02-13 22:10:21 -06:00
Erwan Gouriou
516899c82b boards: nucleo_l4r5zi: Add flash & debug support
Following introduction of zephyr sdk0.10 and openocd branch
from from 20190130, stm32l4+ SoC support is now available and
flash and debug operations are available on nucleo_l4r5zi board.

Fixes 12094

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-02-13 22:05:49 -06:00
Michael Scott
844c2ad716 net: lwm2m: fix NULL deref in plain_text_read_number()
Per Coverity report, we are assigning the value1 and value2
s64_t pointers a value of 0.  Later when we go to use value1
and value2, they are of course ... NULL.

Fix the typos in the initial assignment of 0 to the
references of value1 and value2.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12300
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12296

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 21:02:53 -05:00
Michael Scott
f6b221699c net: lwm2m: fix out-of-bounds access in put_s8()
Per Coverity report, oma_tlv_put() does pointer arithmetic accessing
the data as an array of u8_t.  In put_bool() we get a singleton
pointer from the evaluation of: "value != 0 ? 1 : 0" which is
passed to put_s8() which in turn passes it to oma_tlv_put().

To avoid misinterpretation, let's create a temporary s8_t variable
to pass into oma_tlv_put instead.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12312

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 21:02:53 -05:00
Michael Scott
95f21d59b7 net: lwm2m: remove checks for long int > MAX_INT
Per Coverity report, the evaluation of long int v > MAX_INT is
always false and considered a CONSTANT_EXPRESS_RESULT issue.

Removed these checks from:
atof32()
lwm2m_write_attr_handler()

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12317
Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/12320

Signed-off-by: Michael Scott <mike@foundries.io>
2019-02-13 21:02:53 -05:00
Krzysztof Chruscinski
c73dc42a82 tests: drivers: counter: Test cleanup
Minor cleanup in counter test.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-13 18:15:56 -05:00
Krzysztof Chruscinski
849726b3e4 tests: drivers: counter: Fix single_shot_alarm_top and multiple_alarms
Tests were failing because:

1. `alarm_cnt` was not reset before the test.
2. one test was failing because it was expecting that setting
`top_value` for channel_alarm is too high value but in fact
it is accepted and `top_value+1` is too much.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-13 18:15:56 -05:00
Maureen Helm
0540b1a699 soc: nxp_imx: Move code/data location configs to soc level
The imx rt family of socs has several options for linking code and data
into internal or external memories, and up until now we have handled
these options at the board level. This has resulted in several Kconfig
symbols being defined in multiple places and triggering warnings in
documentation builds:

warning: the default selection CODE_ITCM (defined at boards/arm/mimxrt1050_evk/Kconfig:13, boards/arm/mimxrt1060_evk/Kconfig:13) of <choice> (defined at boards/arm/mimxrt1050_evk/Kconfig:9) is not contained in the choice
warning: the choice symbol CODE_ITCM (defined at boards/arm/mimxrt1050_evk/Kconfig:13, boards/arm/mimxrt1060_evk/Kconfig:13) is defined with a prompt outside the choice
warning: the choice symbol CODE_HYPERFLASH (defined at boards/arm/mimxrt1050_evk/Kconfig:16, boards/arm/mimxrt1060_evk/Kconfig:16) is defined with a prompt outside the choice
warning: the choice symbol CODE_QSPI (defined at boards/arm/mimxrt1050_evk/Kconfig:19, boards/arm/mimxrt1060_evk/Kconfig:19) is defined with a prompt outside the choice
warning: the choice symbol CODE_ITCM (defined at boards/arm/mimxrt1050_evk/Kconfig:13, boards/arm/mimxrt1060_evk/Kconfig:13) is defined with a prompt outside the choice
warning: the choice symbol CODE_HYPERFLASH (defined at boards/arm/mimxrt1050_evk/Kconfig:16, boards/arm/mimxrt1060_evk/Kconfig:16) is defined with a prompt outside the choice
warning: the choice symbol CODE_QSPI (defined at boards/arm/mimxrt1050_evk/Kconfig:19, boards/arm/mimxrt1060_evk/Kconfig:19) is defined with a prompt outside the choice

The number of warnings increased as we added more imx rt boards. Fix the
warnings by moving code and data location configs from the board level
to the soc level.

The default memories for all imx rt boards are unchanged. The
mimxrt10{20,50,60}_evk boards still default to hyperflash/qspi for code
and sdram for data. The mimxrt1064_evk board still defaults to ITCM for
code and DTCM for data because jlink does not yet support programming
internal flash.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2019-02-13 17:52:20 -05:00
Krzysztof Chruscinski
4fac1f4204 shell: Add support to log_panic in RTT backend
Shell RTT backend was using RTT call which was using
lock (mutex). In case of panic, that lead to failure
if panic occured in the interrupt context where mutex
is not permitted.

Implementation changed to use write without log in
blocking mode.

Additionally, added static assert to check if raw RTT
log backend is not enabled on channel 0 which is used
by shell RTT backend.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
2019-02-13 17:25:59 -05:00
Kumar Gala
02670ed2d7 spi: spi_mcux_lpspi: Convert to use DT_ prefixed defines
The spi mcux_lpspi driver has been using non DT_ prefixed defines for
DT generated defines.  Switch to use DT_ prefixed ones as we want to
deprecated the non DT_ prefixed defines.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-13 16:59:02 -05:00