summaryrefslogtreecommitdiff
path: root/core/cortex-m
Commit message (Collapse)AuthorAgeFilesLines
* tree: Replace "unsigned" with "unsigned int"Andrea Grandi2023-01-041-1/+1
| | | | | | | | | | | | | | | | | Fix checkpatch error: > Prefer 'unsigned int' to bare use of 'unsigned' BUG=b:262047616 TEST=./util/compare_build.sh -b all -j 120 => MATCH BRANCH=none Change-Id: Ibf82332a1e1ea0a0a03d3993336e24883e495e05 Signed-off-by: Andrea Grandi <agrandi@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4126483 Reviewed-by: Tom Hughes <tomhughes@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* panic: Publish EC_HOST_EVENT_PANIC on panicRob Barnes2022-12-201-0/+3
| | | | | | | | | | | | | | | | | | | Publish EC_HOST_EVENT_PANIC when a panic occurs. The kernel may use this event to clean up before the system is reset (e.g. sync the drive). This will be a no-op if the kernel doesn't handle it. BUG=b:258195448 BRANCH=None TEST=Observe event in kernel. Pass panic_event unit test. Change-Id: I34b9847778bf17dd113e81158bbbdf999ad2ca33 Signed-off-by: Rob Barnes <robbarnes@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4063818 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* hooks: Add HOOK_BODY_DETECT_CHANGELeila Lin2022-12-131-0/+6
| | | | | | | | | | | | | | | | | | | Add HOOK_BODY_DETECT_CHANGE hook when CONFIG_BODY_DETECTION is enabled to notify body detection's state is changing. BRANCH=none BUG=b:232946420 TEST=zmake build winterhold and confirm that the notification of the hook has been received. Change-Id: Ied9afeef41ee14d7f2de1b423d94600d076bb975 Signed-off-by: Leila Lin <leilacy_lin@compal.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4054308 Tested-by: LeilaCY Lin <leilacy_lin@compal.corp-partner.google.com.test-google-a.com> Reviewed-by: Elthan Huang <elthan_huang@compal.corp-partner.google.com> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: LeilaCY Lin <leilacy_lin@compal.corp-partner.google.com.test-google-a.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* core/cortex-m: Call constructors of global objectsTom Hughes2022-12-102-0/+10
| | | | | | | | | | | | | | | BRANCH=none BUG=b:261636413 TEST=./test/run_device_tests.py -b dartmonkey -t global_initialization => PASS Cq-Depend: chromium:4083816 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Ia7e9069a6a030c81cb0697346baa9a08861e56cb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4081571 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Bobby Casey <bobbycasey@google.com>
* system: Implement system safe modeRob Barnes2022-12-063-0/+74
| | | | | | | | | | | | | | | | | | | | | | Basic implementation of system safe mode recovery. System safe mode is a recovery mode that may be started after a fault/panic. It allows the AP to collect info about the fault and system state before the system resets This CL includes support for Zephyr EC and legacy CrOS EC BUG=b:249128225 BRANCH=None TEST=./twister -s external/platform/ec/zephyr/test/rw_safe_mode/rw_safe_mode.default Manually tested on skyrim Change-Id: I15139bb082011485b54e4ca7813839940bf5401a Signed-off-by: Rob Barnes <robbarnes@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4029604 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* test: Sort header filesJeremy Bettis2022-11-301-0/+3
| | | | | | | | | | | | | | | | | | | | | Sort all includes in test with the clang-format rules used by the zephyr project. BRANCH=None BUG=b:247100970 TEST=zmake build -a TEST=./twister --clobber -v -i TEST=make -j72 buildall_only runtests TEST=zmake compare-builds -a Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: Iae52f99a3a8b5623c1c92722c325ca92816fa856 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4052760 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Aaron Massey <aaronmassey@google.com> Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org>
* core: Sort header filesJeremy Bettis2022-11-225-5/+8
| | | | | | | | | | | | | | | | | | | | | Sort all headers in core with the clang-format rules used by the zephyr project. BRANCH=None BUG=b:247100970 TEST=zmake build -a TEST=./twister --clobber -v -i TEST=make -j$(nproc) buildall_only runtests TEST=zmake compare-builds Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: Ie1dafb879dca3fcb9254025da8a70b5cd169481d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4047095 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Al Semjonovs <asemjonovs@google.com> Reviewed-by: Al Semjonovs <asemjonovs@google.com>
* cortex-m mpu: illegal shift fixstabilize-15245.B-mainBoris Mittelberg2022-11-152-2/+15
| | | | | | | | | | | | | | | | Shifting left by 32 is undefined behavior. An AND operation with mask of 0xffffffff is meaningless, so just avoid it. BUG=b:64477774 BRANCH=none TEST=none Signed-off-by: Boris Mittelberg <bmbm@google.com> Change-Id: Ibcb3359f453345caee01936c074a9c0ae5aff7dc Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4021135 Tested-by: Peter Marheine <pmarheine@chromium.org> Reviewed-by: Peter Marheine <pmarheine@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* core/cortex-m: Add .init_array to .ro_dataTom Hughes2022-11-011-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When trying to build a unit test that links against googletest, we get the following errors: ld.lld: error: section '.image.RO' will not fit in region 'FLASH': overflowed by 811597840 bytes ld.lld: error: section '.image.RO.key' will not fit in region 'FLASH': overflowed by 811597840 bytes ld.lld: error: section '.image.RO.key' will not fit in region 'FLASH': overflowed by 811598672 bytes ld.lld: error: section '.image.ROLLBACK' will not fit in region 'FLASH': overflowed by 811598672 bytes ld.lld: error: section '.image.ROLLBACK' will not fit in region 'FLASH': overflowed by 811598716 bytes Looking at the sections in the ELF file, we see that .init_array is being put at a really large address: armv7m-cros-eabi-objdump -h \ ./build/dartmonkey/fpsensor_hw/RW/fpsensor_hw.RW.elf Sections: Idx Name Size VMA LMA File off Algn 10 .init_array 0000000c 38800000 38800000 000b0000 2**2 CONTENTS, ALLOC, LOAD, DATA 11 .init_array.100 00000004 3880000c 3880000c 000b000c 2**2 .init_array consists of read-only data (const data array of self-relative pointers to functions), so it can go in the .ro_data section. See https://developer.arm.com/documentation/dui0475/c/the-arm-c-and-c---libraries/c---initialization--construction-and-destruction for details. BRANCH=none BUG=b:234181908, b:254530679 TEST=make BOARD=dartmonkey test-fpsensor_hw -j TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: If6566763452e3f5f87767b0f4999d6db8e6c1572 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3971946 Reviewed-by: Andrea Grandi <agrandi@google.com>
* include/compiler.h: Add generic macro for disabling compiler warningsTom Hughes2022-10-131-12/+5
| | | | | | | | | | | | | | These macros are easier to read and use than the underlying pragmas. BRANCH=none BUG=b:172020503 TEST=make buildall Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I2f67cbb3f83230b7e1a6a4512471bbd2bec0498f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3872552 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* tree: Remove CONFIG_SOFTWARE_PANICTom Hughes2022-10-123-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | It's always enabled in the core/<core>/core_config.h files. The following script demonstrates that it's enabled in all boards: for board in `make print-boards`; do make print-configs board="${board}" | grep -q CONFIG_SOFTWARE_PANIC if [ $? -ne 0 ]; then echo "${board} failed" exit 1 fi done BRANCH=none BUG=none TEST=make buildall Cq-Depend: chromium:3943248 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: If683b244f17b48bedf3699f2b24e83b5ad6e849e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3933255 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* core/cortex-m: Disable C++ exceptionsTom Hughes2022-10-101-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | __exidx_start and __exidx_end indicate the start and end of the exception index table, which is described in more detail in "Exception Handling ABI for ARM Architecture": https://github.com/ARM-software/abi-aa/blob/60a8eb8c55e999d74dac5e368fc9d7e36e38dda4/ehabi32/ehabi32.rst#54the-object-producer-interface __exidx_start and __exidx_end are referenced in libunwind, so they need to be defined. If __exidx_start and __exidx_end are equal, libunwind will interpret the exception index table as empty, which means the exception can not be caught, and std::terminate() is called, which is what we want. The test in https://crrev.com/c/3932262 verifies this behavior. See https://github.com/llvm/llvm-project/blob/b3c5da73b71908c59b12ef0feadfde56bad222b5/libunwind/src/AddressSpace.hpp#L515-L522 BRANCH=none BUG=b:234181908 TEST=make buildall Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I8551ca94fce16ec34770f9204282af14667e7c43 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3857943 Reviewed-by: Andrea Grandi <agrandi@google.com>
* Update license boilerplate text in source code filesMike Frysinger2022-09-1224-24/+24
| | | | | | | | | | | | | | | Normally we don't do this, but enough changes have accumulated that we're doing a tree-wide one-off update of the name & style. BRANCH=none BUG=chromium:1098010 TEST=`repo upload` works Change-Id: Icd3a1723c20595356af83d190b2c6a9078b3013b Signed-off-by: Mike Frysinger <vapier@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3891203 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* tree-wide: const-ify argv for console commandsCaveh Jalali2022-09-012-4/+4
| | | | | | | | | | | | | | | | | | | | | | | This updates the API for console commands from "int cmd(int argc, char **argv)" to "int cmd(int argc, const char **argv)" which is more accurate and in line with common convention. BRANCH=none BUG=b:244387210 TEST="make buildall" passes TEST="zmake build -a" passes TEST="util/compare_build.sh -b all" passes TEST="./twister -v -T zephyr/test" passes Cq-Depend: chrome-internal:4960125 Cq-Depend: chrome-internal:4959932 Change-Id: I57de9f35b85b8f3c7119df36aefb2abf25d2625f Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3863941 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org>
* util: remove unused includesYuval Peress2022-08-052-0/+2
| | | | | | | | | | | | | | | | Remove these includes as they're not needed in this header. Instead, the includes should go where they're actually being used. BRANCH=none BUG=b:240574048 TEST=make buildall -j TEST=zmake build -a Signed-off-by: Yuval Peress <peress@google.com> Change-Id: I64b10af3216654b2a20caa1cabd267661a0bca39 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3791980 Reviewed-by: Tristan Honscheid <honscheid@google.com> Commit-Queue: Tristan Honscheid <honscheid@google.com>
* core: Add "end" to linker scriptsTom Hughes2022-07-181-0/+6
| | | | | | | | | | | | | | | _sbrk in newlib (embedded C standard library implementation) expects the "end" symbol to point to the start of free memory. BRANCH=none BUG=b:234181908 TEST=./util/compare_build.sh -j 120 => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I9f206e2ed5f050d92b579e0b65b05be40f929093 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3766504 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* tree: Fix -Wstrict-prototypes warningTom Hughes2022-07-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | The latest clang complains about missing 'void' in function definition if it's specified in the declaration: core/cortex-m/vecttable.c:23:21: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes] void default_handler() ^ void BRANCH=none BUG=b:230345382, b:172020503 TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I5a3d95203cc6cbb59676f4a66876a4a6f2946e31 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3750108 Reviewed-by: Ting Shen <phoenixshen@chromium.org>
* core/cortex-m/cpu.c: Format with clang-formatJack Rosenthal2022-07-011-1/+2
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: I6a506bffda1dd6c0174b327fa6b612f3df20ad66 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729816 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* core/cortex-m/include/fpu.h: Format with clang-formatJack Rosenthal2022-07-011-12/+4
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: I1ae03f882c46824c1e55a5f04022e8787bc6327a Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729819 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* core/cortex-m/irq_handler.h: Format with clang-formatJack Rosenthal2022-07-011-17/+17
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: I219906a9e12057dc850b19a34ec32d53c10e943a Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729821 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* core/cortex-m/fpu.c: Format with clang-formatJack Rosenthal2022-07-011-4/+3
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: I37ab831aa135bdf434b636f83e180abc74f60fff Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729818 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* core/cortex-m/task.c: Format with clang-formatJack Rosenthal2022-07-011-82/+70
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: Ib2186f2f662542398c1a48a6052f47e15792b6c8 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729826 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* core/cortex-m/vecttable.c: Format with clang-formatJack Rosenthal2022-07-011-286/+69
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: I5d27a14ec3d01581df669496af767c9e5d654fde Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729827 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* core/cortex-m/atomic.h: Format with clang-formatJack Rosenthal2022-07-011-1/+1
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: I1f16b4098e165a09f17e2fe2041eb4282ba56108 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729815 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* core/cortex-m/mpu.c: Format with clang-formatJack Rosenthal2022-07-011-35/+26
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: Ia2f95d269b42a5dac2639c3a25606808843a50f1 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729823 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* cortex-m: Don't execute WFI instruction if debuggingBobby Casey2022-07-012-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | Allowing the processor to sleep causes the debugger to stop working. BRANCH=none BUG=b:180144572 TEST=Monitor power per go/cros-fpmcu-source-code-docs#dragonclaw-v0_2 TEST=Icetower (pp3300_dx_mcu_mw) with no debugger connected Idle: ~44 mW Low Power Mode: ~5.5 mW TEST=Icetower (pp3300_dx_mcu_mw) with debugger connected Idle: ~75 mW Low Power Mode: ~70 mW TEST=Dragonclaw (pp3300_dx_mcu_mw) with no debugger connected Idle: ~22 mW Low Power Mode: ~1.5 mW TEST=Dragonclaw (pp3300_dx_mcu_mw) with debugger connected Idle: ~64 mW Low Power Mode: ~19 mW Signed-off-by: Bobby Casey <bobbycasey@google.com> Change-Id: I48d58395b168dc3bb0932348cd8f5ce088fc0ac9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2713754 Commit-Queue: Tom Hughes <tomhughes@chromium.org> Tested-by: Tom Hughes <tomhughes@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
* core/cortex-m/panic.c: Format with clang-formatJack Rosenthal2022-06-301-35/+34
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: I2ee2c076a6c87b8919373d40de44bb2e03fd91ae Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729825 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* core/cortex-m/include/mpu.h: Format with clang-formatJack Rosenthal2022-06-281-32/+32
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: I057fcaa6f6be1404855c0f3b864b7bb1e0273ff6 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729820 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* core/cortex-m/cpu.h: Format with clang-formatJack Rosenthal2022-06-281-66/+65
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: I3007abd5c6bec9caadd8e09fd9bde60d73b8d54e Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729817 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* core/cortex-m/llsr.c: Format with clang-formatJack Rosenthal2022-06-281-11/+8
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: I561629bff28f8024968b05dac0c6fef69e161973 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729822 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* core/cortex-m/panic-internal.h: Format with clang-formatJack Rosenthal2022-06-271-1/+1
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: Iffcf85741854be63a67acc063cc030cdeb30a298 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729824 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* hook: Add HOOK_POWER_SUPPLY_CHANGEDaisuke Nojiri2022-06-221-0/+4
| | | | | | | | | | | | | | | | | This patch adds HOOK_POWER_SUPPLY_CHANGE. It triggers when there is a change in the active charge port. BUG=None BRANCH=None TEST=buildall TEST=zephyr/firmware_builder.py --metrics /tmp/tmpb1k9vctu --code-coverage build Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I77fda265c323e4101c8cc95ed15be714b8989c85 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3716790 Commit-Queue: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
* Makefile: Make sure CROSS_COMPILE is set correctlyTom Hughes2022-06-212-13/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When testing a change to set the default compiler to clang for dartmonkey, I encountered an error when building with "make proj-bloonchipper": ccache: error: execv of /opt/coreboot-sdk/bin/arm-eabi-clang failed: No such file or directory In this case the CC variable (defined in Makefile.toolchain as "CC=$(CCACHE) $(CROSS_COMPILE)$(cc-name))" had CROSS_COMPILE set to "/opt/coreboot-sdk/bin/arm-eabi-" (gcc toolchain) and cc-name set to "clang", which is not correct. The problem was that the Makefile has simply expanded variables (https://www.gnu.org/software/make/manual/html_node/Flavors.html#Flavors) that reference CC before the core/$(CORE)/build.mk is included (e.g., "_tsk_lst_ro" that uses CPP, which is defined as "CPP=$(CC) -E"). This change pulls the toolchain configuration out of core/$(CORE)/build.mk into a separate core/$(CORE)/toolchain.mk file that is included earlier in the top-level Makefile, which ensures that CC is defined before it is used by the simply expanded variables. BRANCH=none BUG=b:172020503, b:234181908 TEST=make proj-bloonchipper -j TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Ia41d2de61ee786df044d484c146d6970de183562 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3706036 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* Makefile: Set core-specific LLVM toolchainTom Hughes2022-06-151-2/+10
| | | | | | | | | | | | | | | There are separate toolchains for ARMv6-M (cortex-m0) and ARMv7-M (cortex-m). BRANCH=none BUG=b:172020503, b:234181908 TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Icc131934a7b721ef3732d1b0e3f26bd4906239d2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3693041 Reviewed-by: Diana Z <dzigterman@chromium.org>
* tree: Files should end with single newlineTom Hughes2022-06-152-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | One of the checks that runs as part of "repo upload" looks for a single newline at the end of each file. I'm getting warnings about this when I touch files that do not follow this, even though I didn't add the extra newlines. This commit fixes additional files not included in https://crrev.com/c/3229797 by running the following: for f in $(find . -name '*.mk'); do printf '%s\n' "$(cat ${f})" > ${f}; done for f in $(find . -name '*.S'); do printf '%s\n' "$(cat ${f})" > ${f} done BRANCH=none BUG=b:172020503, b:234181908 TEST=./util/compare_build.sh -b all -j 120 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Ib4e4d0e74bf3b00a0b2c81505fef65e2c1b7401f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3705766 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* core/cortex-m[0]: Remove C++ exception unwind stubsTom Hughes2022-06-151-9/+0
| | | | | | | | | | | | | | | | | | | | | | These symbols should only be needed for unwinding C++ exceptions: https://sourceware.org/binutils/docs/as/ARM-Unwinding-Tutorial.html It's unclear why these are here since we're not compiling with C++ at this point. The code was introduced in commit e24fa592d2a215d8ae67917c1d89e68cdf847a03, which doesn't provide any details. Once we start compiling C++, these definitions cause problems since they conflict with the real symbols in libunwind. BRANCH=none BUG=b:234181908 TEST=make buildall Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I085ba56a822cae4b02991a9e5395aba60ec8bad7 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3701131 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* core/cortex-m: Set FPU to autoTom Hughes2022-06-151-1/+13
| | | | | | | | | | | | | | | | | | | | | | | Use "-mfpu=auto" so that the compiler will choose the correct FPU settings based on the settings of -mcpu and -march: https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html. According to the above doc "-mfpu=auto" is the default and shouldn't be required, but compilation using gcc fails without the flag. clang does not support the "-mfpu=auto" flag, but will choose the correct floating point unit based on the -mcpu flag: https://lists.llvm.org/pipermail/llvm-dev/2018-September/126468.html BRANCH=none BUG=b:145677491, b:234181908 TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I3c255ee53e31763d29dfb2086fcebf3d8290dc56 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3699793 Reviewed-by: Andrea Grandi <agrandi@google.com>
* task: change task_set_event return type to voidFabio Baltieri2022-06-021-3/+1
| | | | | | | | | | | | | | | No implementation does nothing other than return 0 on task_set_event(), change the return type to void so that the API is clear. BRANCH=none BUG=none TEST=cq dry run Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: I88b20f53aa6dffa291ce78f4776888b21985f57f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3683769 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
* core/cortex-m[0]: Use architecture-specific compiler rtTom Hughes2022-04-191-1/+1
| | | | | | | | | | | | | | | | | | The previously referenced compiler-rt library was only built for ARMv7-M. The toolchain has been updated to provide both an ARMv7-M and ARMv6-M version. BRANCH=none BUG=b:172020503, b:205342596 TEST=CC=clang make BOARD=discovery-stm32f072 TEST=CC=clang make BOARD=dartmonkey TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I70ac495b43449bc40bb149b0f84d113cafb49f10 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3283419 Reviewed-by: Keith Short <keithshort@chromium.org>
* cortex-m/irq_handler: Replace inline asm with CTom Hughes2022-04-111-10/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When building with clang and LTO is enabled, clang optimizes out "routine" (the interrupt handler) and fails to link. gcc does not optimize out the routine. Rewriting IRQ_HANDLER in C makes it compile with both compilers, though it uses two more instructions. Before this change the generated assembly for an interrupt handler on dartmonkey: arm-none-eabi-objdump -d ./build/dartmonkey/RW/ec.RW.elf 081027a8 <irq_37_handler>: 81027a8: 4670 mov r0, lr 81027aa: b501 push {r0, lr} 81027ac: f7ff ffea bl 8102784 <uart_interrupt> 81027b0: e8bd 4001 ldmia.w sp!, {r0, lr} 81027b4: f009 bbc4 b.w 810bf40 <task_resched_if_needed> After this change the generated assembly for an interrupt handler on dartmonkey: arm-none-eabi-objdump -d ./build/dartmonkey/RW/ec.RW.elf 081027e0 <irq_37_handler>: 81027e0: b507 push {r0, r1, r2, lr} 81027e2: f8cd e004 str.w lr, [sp, #4] 81027e6: f7ff ffe9 bl 81027bc <uart_interrupt> 81027ea: 9801 ldr r0, [sp, #4] 81027ec: b003 add sp, #12 81027ee: f85d eb04 ldr.w lr, [sp], #4 81027f2: f009 bbc5 b.w 810bf80 <task_resched_if_needed> BRANCH=none BUG=b:172020503 TEST=make buildall TEST=./test/run_device_tests.py --board dartmonkey => PASS Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I7029556afc4a760e81885d8f84b7d787f48c4036 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3566661 Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
* cortex-m/vecttable: Fix IRQ vectors listPatryk Duda2022-04-061-15/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Basing on [1], [2], [3], [4] all Cortex-M processors that runs EC have 240 external interrupts and 15 exceptions which results in total number of 255 exception vectors. Fix vector table by removing redundant external interrupt definitions. [1] Cortex-M7 Processor Technical Reference Manual -> Nested Vectored Interrupt Controller -> NVIC functional description https://developer.arm.com/documentation/ddi0489/latest [2] Cortex-M4 Processor Technical Reference Manual -> Nested Vectored Interrupt Controller -> NVIC functional description https://developer.arm.com/documentation/100166/latest [3] Cortex-M Comparison Table https://developer.arm.com/documentation/102787/latest [4] Cortex-M4 Devices Generic User Guide p. 2-22 2-23 https://developer.arm.com/documentation/dui0553/latest/ BUG=b:215593629 BRANCH=none TEST=make -j buildall TEST=./test/run_device_tests -b dartmonkey TEST=./test/run_device_tests -b bloonchipper Signed-off-by: Patryk Duda <pdk@semihalf.com> Change-Id: I3b06f290f9a3b2d22b9b2d947d21e4967929bc13 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3572081 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Patryk Duda <patrykd@google.com>
* tree: Replace __attribute__((used)) with __keepTom Hughes2022-03-292-2/+2
| | | | | | | | | | | | | | The two are equivalent, so use __keep everywhere for consistency. BRANCH=none BUG=b:172020503 TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Ie2d15e8fa00dbe35a190060c80f15f4ba720e3a6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3556497 Reviewed-by: Eric Yilun Lin <yllin@google.com>
* atomic: add atomic_and functionDawid Niedzwiecki2022-03-091-0/+5
| | | | | | | | | | | | | | | | | Add atomic_and functions for all cores. The functions will be used for more complex atomic operations for bits manipulating that will be merged in a following CL. BRANCH=none BUG=b:208435177 TEST=make buildall Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I659ee8214206750fbe8af4df21672d8cbfc59278 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3500418 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Dawid Niedzwiecki <dawidn@google.com>
* cortex-m: Introduce FPU interrupt handlerPatryk Duda2022-02-033-0/+128
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When performing some illegal operation or when result can't be represented using floats, the FPU will assert an interrupt which should be handled. After this change, the EC will inform about type of FPU exception and address where it ocurred. To reduce overhead, the FPU handler will only copy necessary information, schedule fpu_warn() function and clear FPU flags. Message is printed from fpu_warn() which is deferred function (it's called from HOOK task context). Please note that: - FPU interrupt is not asserted immediately after problem occurred, but with noticeable delay, so PC and LR might not be correct. - FPU interrupt will be never triggered on STM32H7 (see errata ES0392 Rev 8, 2.1.2 Cortex-M7 FPU interrupt not present on NVIC line 81). BUG=b:215606535 BRANCH=none TEST=./test/run_device_tests.py --board bloonchipper --tests cortexm_fpu TEST=./test/run_device_tests.py --board dartmonkey --tests cortexm_fpu Signed-off-by: Patryk Duda <pdk@semihalf.com> Change-Id: Ib6f6c974082affc35302a822f0beea176e204206 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3412259 Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bobby Casey <bobbycasey@google.com> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Commit-Queue: Patryk Duda <patrykd@google.com>
* clock-stm32f4: Handle timer overflow in IDLE taskPatryk Duda2022-01-211-0/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | STM32F4 microcontroller has 32 bit timer which is used by EC to measure system uptime (in microseconds) and wake tasks if necessary. In EC timestamp is defined as two 32 bit values, which combined together give full 64 bit value. Lower 32 bits are read directly from timer. Higher 32 bits are kept in clksrc_high variable. The variable is updated in process_timers() function which is called in interrupt context (it's not an interrupt handler, but it's called by the driver). The function also sets event timestamp which is supposed to generate interrupt if timer register matches event timestamp. When EC switches to IDLE task, interrupts are disabled in order to prevent task preemption in uncontrolled manner. It is possible that after interrupts are disabled timer overflow could occur and clksrc_high variable remains old. Other problem is that event timestamp which is read using __hw_clock_event_get() and points to timestamp in previous "epoch". Its value is about 2^32 - HOOK_TICK_INTERVAL (500 ms). After overflow, t0.le.lo is very low and t0.le.hi remains unincremented. As a result next_delay variable (which tells for how long RTC alarm is set) is very high (even above 1 hour). Another important fact is that t0 timestamp is wrong and it is used to calculate value which will be loaded into the timer after wake. This can potentially lead to very long wait before running tasks. This fix checks if timestamp overflow occurs between disabling interrupt and getting "t0" value. If it happens, interrupts are enabled (to handle timer overflow) and IDLE enter procedure is repeated. BUG=b:200828093 BRANCH=none TEST=make -j buildall TEST=Run EC on bloonchipper and enable deep sleep. Check if device crashes. TEST=Measure dragonclaw v0.2 power consumption in deep sleep using following commands: dut-control fpmcu_slp_s0:on dut-control -t 60 pp3300_dx_mcu_mv pp3300_dx_fp_mv \ pp1800_dx_fp_mv pp3300_dx_mcu_mw pp3300_dx_fp_mw \ pp1800_dx_fp_mw Make sure that power consumption doesn't increase. Signed-off-by: Patryk Duda <pdk@semihalf.com> Change-Id: I8c3bb51a0ef9d94ef384b8fca5a175945ba67604 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3347659 Reviewed-by: Bobby Casey <bobbycasey@google.com> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
* atomic: fix printing atomic_t typeDawid Niedzwiecki2022-01-061-4/+4
| | | | | | | | | | | | | | | | | | | After changing the atomic_t type from long to int the print format was changed to %l, but the CrosEC print function doesn't support the 'l' format if long is 4 bytes wide. Cast the atomic_t to int and print it as a normal int variable. BUG=b:207082842 TEST=make buildall && zmake testall && make sure the 'taskinfo' work BRANCH=main Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I8643d8b843720e3583a29d83fc143d8e103e79c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3359425 Tested-by: Patryk Duda <pdk@semihalf.com> Reviewed-by: Patryk Duda <patrykd@google.com> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Commit-Queue: Patryk Duda <patrykd@google.com>
* atomic: change atomic_t to longDawid Niedzwiecki2021-12-171-4/+4
| | | | | | | | | | | | | | | | | | | | | Change the atomic_t type from int to long. For all chips used for EC, this change shouldn't impact the generated code, except for the string needed fot the print function. For the host build keep int, because EC codebase assumes that the atomic_t type is 4-byte wide. The change caused by a change in Zephyr upstream (atomic_t from int to long). BUG=b:207082842 Cq-Depend: chromium:3330355 TEST=make buildall && zmake testall BRANCH=main Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: Id4b6f8b60e73bdef741a530e3ed614b67b48720f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3330201 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Commit-Queue: Dawid Niedzwiecki <dawidn@google.com>
* core/cortex-m[0]: Replace numeric index with readable nameTom Hughes2021-12-111-21/+27
| | | | | | | | | | | | | | | The code is easier to read with human readable names instead of numeric values. BRANCH=none BUG=b:172020503, b:207001076 TEST=./util/compare_build.sh -b all -j 120 => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Ie7474729dcb43edb9b6a728b9b944b55d76a1f0f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3299273 Reviewed-by: Diana Z <dzigterman@chromium.org>
* task: use atomic_t for some variablesDawid Niedzwiecki2021-12-071-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | Use the atomic_t variable type for tasks_ready, tasks_enabled and waiters in struct mutex. The generated asm code is different around the line: char is_ready = ((uint32_t)tasks_ready & BIT(i)) ? 'R' : ' '; for all cores, so cast tasks_ready to an unsigned variable to make sure is works as intended regardless of architecture. The change will be useful for incoming commits related to modifying atomic_t caused by a change in Zephyr upstream (atomic_t from int to long). BUG=b:207082842 TEST=make buildall && zmake testall BRANCH=main Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I0a55c71947401e4137b30fc62adba84d867f56f8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3301710 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Dawid Niedzwiecki <dawidn@google.com>
* task: change task events bitmask to atomic_tDawid Niedzwiecki2021-11-291-2/+2
| | | | | | | | | | | | | | | | | | | | The events bitmask is used only with atomic_* functions or for reading, so change to variable type to atomic_t. It shouldn't change the generated code. It will be useful for incoming commits related to modifying atomic_t caused by a change in Zephyr upstream (atomic_t from int to long). BUG=b:207082842 TEST=make buildall && zmake testall && build_compare.sh -b all BRANCH=main Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: Ia0ff4a20f9ed6c3728b1bd8b6cab3b32ebfcc36b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3300321 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>