summaryrefslogtreecommitdiff
path: root/common/system.c
Commit message (Collapse)AuthorAgeFilesLines
* HC: check response buffer size before copying dataLi Feng2023-03-041-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | ISH has allocated 128 bytes for HECI response message; 112 bytes can be used to store HC response data. But EC_CMD_GET_VERSION v1 response data has 132 bytes. Copying data without checking buffer size causes buffer overflow. And we observed an issue that HECI client handle is changed by this. The fix is to add size check and return EC_RES_RESPONSE_TOO_BIG on error. CL:4302834 increases ISH buffer size as well; so that host can get version information. BUG=b:271502099 BRANCH=none TEST=on Rex platform with ISH enabled, monitor HECI client handle value is the same all the time. No more "Timed out for response to host message". Change-Id: Ibee2fb6a54d3c7d1d60d90a8f6b20bc89066ff5a Signed-off-by: Li Feng <li1.feng@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4305920 Reviewed-by: Tanu Malhotra <tanu.malhotra@intel.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* Replace CONFIG_DMA with CONFIG_DMA_CROS in EC codebasePatryk Duda2023-03-011-2/+2
| | | | | | | | | | | | | | | | The config from EC collides with the same config from Zephyr. BUG=b:239712345 BRANCH=none TEST=make runhosttests buildall Change-Id: Ic6e63ea6dd9e745e82feb2af04b77069c2d78af1 Signed-off-by: Patryk Duda <pdk@semihalf.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4295699 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Tom Hughes <tomhughes@chromium.org> Commit-Queue: Patryk Duda <patrykd@google.com> Tested-by: Patryk Duda <patrykd@google.com>
* system: Add EC_REBOOT_FLAG_CLEAR_AP_IDLEDaisuke Nojiri2023-01-041-24/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds EC_REBOOT_FLAG_CLEAR_AP_IDLE. It can be combined with any ec_reboot_cmd. EC_REBOOT_HIBERNATE_CLEAR_AP_OFF is replaced with EC_REBOOT_HIERNATE and EC_REBOOT_FLAG_CLEAR_AP_IDLE. ectool continues to support EC_REBOOT_HIBERNATE_CLEAR_AP_OFF for old ECs. 11:39:47.588 [64.559799 Saved AP_IDLE flag] 11:39:47.591 [64.560597 PD:S3->S5] 11:39:47.595 [64.561030 PCHG: pchg_shutdown] 11:39:47.595 Unhandled DPM Request 800000 received 11:39:47.601 Reboot at shutdown: 9 11:39:47.601 [64.605089 Clearing AP_IDLE] BUG=b:261119366 BRANCH=None TEST=buildall TEST=Verified with a local coreboot build. See the log above. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: Iffc7a7ad9946f2914829ca839ef9fc6226c8d1ee Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4116341 Reviewed-by: Derek Huang <derekhuang@google.com> Tested-by: Derek Huang <derekhuang@google.com> Commit-Queue: Derek Huang <derekhuang@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* ec: Support logging system boot time infoRajesh Kumar2022-12-071-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This CL add support logging system boot time and hostcommand to get boot time info. EC logs elapsed time (in micro second) info since boot for different signal events,that can be used to calculate system boot time in cold boot and warm boot scenarios. Below are the events when EC logs time info ARAIL EC turns on A-RAIL RSMRST EC releases RSMRST# ESPIRST ESPIRST received PLTRST_LOW PLTRST# asserted PLTRST_HIGH PLTRST# deasserted EC_CUR_TIME EC current time cnt increments on every warm reboot and reset to 0 on cold reboot BUG=b:249163956 BRANCH=none TEST='ectool boottime' AP console command is used to fetch data 'reboot' on AP console to trigger warm reboot 'apshutdown' on EC console to trigger cold reboot Signed-off-by: Rajesh Kumar <rajesh3.kumar@intel.com> Change-Id: I47abe3f8a0b7ab43f2af11bf8387c006ba383020 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4081566 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Tested-by: Li-Yu Yu <aaronyu@google.com> Reviewed-by: Boris Mittelberg <bmbm@google.com>
* Revert "ec: Support logging system boot time info"Piotr Pawliczek2022-12-031-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit c8325ba18b9f4d5b1f3f3bc739e83d8f591308cf. Reason for revert: broke at least 9 cq builds (https://ci.chromium.org/ui/p/chromeos/builders/cq/cq-orchestrator/b8795833246203447793/overview) Original change's description: > ec: Support logging system boot time info > > This CL add support logging system boot time and hostcommand to get > boot time info. > EC logs elapsed time (in micro second) info since boot for different > signal events,that can be used to calculate system boot time in cold > boot and warm boot scenarios. > > Below are the events when EC logs time info > > ARAIL EC turns on A-RAIL > RSMRST EC releases RSMRST# > ESPIRST ESPIRST received > PLTRST_LOW PLTRST# asserted > PLTRST_HIGH PLTRST# deasserted > EC_CUR_TIME EC current time > cnt increments on every warm reboot and reset to 0 on > cold reboot > > BUG=b:249163956 > BRANCH=none > TEST='ectool boottime' AP console command is used to fetch data > 'reboot' on AP console to trigger warm reboot > 'apshutdown' on EC console to trigger cold reboot > > Signed-off-by: Rajesh Kumar <rajesh3.kumar@intel.com> > Change-Id: I15fedbde252e0452270ef0e3fd4391bf624169f1 > Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3794612 > Reviewed-by: Boris Mittelberg <bmbm@google.com> > Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Bug: b:249163956 Change-Id: Ie83026c4a3a38c3dd24522901233f06e03430a54 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4077335 Reviewed-by: Jonathon Murphy <jpmurphy@google.com> Commit-Queue: Piotr Pawliczek <pawliczek@chromium.org> Tested-by: Piotr Pawliczek <pawliczek@chromium.org>
* ec: Support logging system boot time infoRajesh Kumar2022-12-021-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This CL add support logging system boot time and hostcommand to get boot time info. EC logs elapsed time (in micro second) info since boot for different signal events,that can be used to calculate system boot time in cold boot and warm boot scenarios. Below are the events when EC logs time info ARAIL EC turns on A-RAIL RSMRST EC releases RSMRST# ESPIRST ESPIRST received PLTRST_LOW PLTRST# asserted PLTRST_HIGH PLTRST# deasserted EC_CUR_TIME EC current time cnt increments on every warm reboot and reset to 0 on cold reboot BUG=b:249163956 BRANCH=none TEST='ectool boottime' AP console command is used to fetch data 'reboot' on AP console to trigger warm reboot 'apshutdown' on EC console to trigger cold reboot Signed-off-by: Rajesh Kumar <rajesh3.kumar@intel.com> Change-Id: I15fedbde252e0452270ef0e3fd4391bf624169f1 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3794612 Reviewed-by: Boris Mittelberg <bmbm@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* common: Sort header filesJeremy Bettis2022-11-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | Sort all includes in common 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: I70c2ed7bb2ce50c968f3e2dbdc274de3a455129a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4049889 Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Tomasz Michalec <tmichalec@google.com> Reviewed-by: Tom Hughes <tomhughes@chromium.org>
* system: Ensure space for panic and jump dataRob Barnes2022-11-171-2/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | Ensure space is available for end of ram data. End of ram data must be located at the very end of noinit ram. This currently includes panic_data followed by jump_data. This is being enforced with linker asserts and build asserts rather than allocating the space directly so RAM utiliztion reports are still relevant. Introduce PLATFORM_EC_PRESERVED_END_OF_RAM_SIZE config option and default it to 1KB. This can be adjusted on boards that are constrained. BUG=b:246778588,b:246798928 BRANCH=None TEST=./twister -c -s zephyr/test/jump_tags/jump_tags.default && make run-kb_8042 Change-Id: I444bbe3a583396b4f9b104bb6999e78ae3ff6f2f Signed-off-by: Rob Barnes <robbarnes@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3896272 Reviewed-by: Aaron Massey <aaronmassey@google.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* test: cbi_gpio_read() unhappy pathsAaron Massey2022-10-281-1/+1
| | | | | | | | | | | | | | | Add tests that provide coverage for all errors potentially found when invoking cbi_gpio_read(). BRANCH=none BUG=b:256017954 TEST=twister -i -s zephyr/test/drivers/drivers.common_cbi_gpio Signed-off-by: Aaron Massey <aaronmassey@google.com> Change-Id: I237f136a90372e5661b862d4dce4e54dc26bf914 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3988171 Reviewed-by: Yuval Peress <peress@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* tree: Enable warning for fallthrough in switch statementsTom Hughes2022-10-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | The EC code has generally been good about adding comments about intentional fallthrough in switch statements, but there were a few cases without comments (e.g., https://crrev.com/c/3949622). Enabling -Wimplicit-fallthrough generates a compiler warning if the fallthrough is not annotated with __attribute__((fallthrough)). For convenience, we add a "__fallthrough" macro for this attribute. See https://clang.llvm.org/docs/AttributeReference.html#fallthrough and https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html. BRANCH=none BUG=b:253644823 TEST=make buildall LOW_COVERAGE_REASON=legacy code Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I9f4d6049f4507a25ce706675d159b70e28b4b825 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3957420 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* zephyr: Add more qcom testsJeremy Bettis2022-10-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Add new cases for booting from power button where power good times out and when the battery is too low to boot. Add new case for the suspend timing out. Add case for resume from suspend. Allow mocking system_can_boot_ap() because the alternative is to add 10 emulators to get an emulated battery level. Exclude 4 lines that are an impossible error case. BRANCH=None BUG=None TEST=twister Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: Icbc7ac579c8f6d2b7e5535a63eb2eca705b9bd06 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3962308 Tested-by: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* tree: Remove CONFIG_SOFTWARE_PANICTom Hughes2022-10-121-2/+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>
* test: Cover all sysjump console command linesAaron Massey2022-09-261-4/+4
| | | | | | | | | | | | | | | | Test all reachable lines in the in sysjump console command. Mocked out functions that seem too complicated to fully validate in native posix at the moment, such as jump_to_image(); BRANCH=none BUG=b:248106876 TEST=./twister --clobber -i -s zephyr/test/drivers/drivers.system Signed-off-by: Aaron Massey <aaronmassey@google.com> Change-Id: I0c39cc33e70f0a215eb9af92889a66c81b7b5259 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3914142 Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com> Reviewed-by: Sam Hurst <shurst@google.com>
* zephyr: tests: Test timer_init() in common/timer.cTristan Honscheid2022-09-231-1/+2
| | | | | | | | | | | | | | | Test the timer initialization function. Add some mocks for the board-level functions and the jump tag API. BRANCH=None BUG=b:247608485 TEST=./twister Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: I7edeca26e93f18c467618691967299f411507166 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3910977 Reviewed-by: Tomasz Michalec <tmichalec@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* Update license boilerplate text in source code filesMike Frysinger2022-09-121-1/+1
| | | | | | | | | | | | | | | 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>
* zephyr: tests: Test handling of special key combos in `keyboard_scan.c`Tristan Honscheid2022-09-091-1/+2
| | | | | | | | | | | | | | | Test that VOL_UP + ALT + {R|H} cause AP reboot and hibernate, respectively. BRANCH=None BUG=b:244606945 TEST=./twister Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: Ic5d927fe830acbd9f6f33a0e436d6ed7c4301fce Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3872728 Reviewed-by: Yuval Peress <peress@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* test: Verify sysinfo console_cmdAaron Massey2022-09-081-0/+1
| | | | | | | | | | | | | | | Verify the sysinfo console command may be invocated and that it prints system information, especially whether the system is locked or not. BRANCH=none BUG=b:245605079 TEST=twister -s zephyr/test/drivers/drivers.default Signed-off-by: Aaron Massey <aaronmassey@google.com> Change-Id: I0b32248c0f23906e7ef75d513a8b77663746ef6f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3880669 Reviewed-by: Tristan Honscheid <honscheid@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* tree-wide: const-ify argv for console commandsCaveh Jalali2022-09-011-11/+11
| | | | | | | | | | | | | | | | | | | | | | | 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>
* zephyr: test: add tests for reboot host commandFabio Baltieri2022-08-221-0/+9
| | | | | | | | | | | | | | | | | | Test various combinations of the EC_CMD_REBOOT_EC host command. This is only missing EC_REBOOT_JUMP_RO and EC_REBOOT_JUMP_RW, which needs more work, to be made testable, but this seems like a good point to cut a commit. BRANCH=none BUG=b:236074981 TEST=./twister -v -T zephyr/test/system_common Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: Ie2b53a0799bb64322646728608d3c3bfd6d3fce4 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3838932 Reviewed-by: Yuval Peress <peress@google.com> Reviewed-by: Simon Glass <sjg@chromium.org> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
* tree: Change non-standard "%pP" printf format to "%p"Tom Hughes2022-07-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | This is the last non-standard format overloading "%p", so we can change it to the standard "%p" format. Using standard format specifiers makes it easier to switch between the "builtin" EC standard library and the C standard library provided by the toolchain (or Zephyr). BRANCH=none BUG=b:238433667, b:234181908 TEST=On icetower v0.1 with servo_micro and J-Trace attached: Before change: > rw 536870912 read 0x20000000 = 0x45dbfce2 After change: > rw 536870912 read 0x20000000 = 0x45dbfce2 Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Id5680ab07af5352d463df42daadff1619c06c9af Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3756180 Reviewed-by: Eric Yilun Lin <yllin@google.com>
* common/system.c: Format with clang-formatJack Rosenthal2022-06-291-100/+73
| | | | | | | | | | | BUG=b:236386294 BRANCH=none TEST=none Change-Id: If70078c11c4fdb72c5da5dd5214c283601ea1465 Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3729735 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
* chipset: introduce CONFIG_AP_POWER_CONTROLPeter Marheine2022-06-151-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | Because the new Zephyr power sequencing support is gated on a different config option than HAS_TASK_CHIPSET which code has historically assumed implies there is an AP present, it is now easy to introduce bugs when code that applies in both configurations uses the old option test. This change decouples the presence of an AP from HAS_TASK_CHIPSET, introducing a new CONFIG_AP_POWER_CONTROL symbol that is derived from the power sequencing config options. All existing applicable users of HAS_TASK_CHIPSET are changed to use the new symbol, fixing several callers which would not behave correctly under Zephyr with the new power sequencing code. The duplicate stub implementations of functions provided by Zephyr's chipset_api are removed, because they already appear in the header that declares those functions. BUG=b:233681784 TEST=make buildall, zmake testall BRANCH=none Signed-off-by: Peter Marheine <pmarheine@chromium.org> Change-Id: I282da30839ca52fcc88c6f9dea2bd00d4811b976 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3670735 Reviewed-by: Keith Short <keithshort@chromium.org>
* zephyr: Remove ec_version.h dependency on common/system.cTristan Honscheid2022-06-131-1/+0
| | | | | | | | | | | | | | | | | | | | | | common/system.c includes ec_version.h to access its definition of CROS_FWID_MISSING_STR. However, this is just a constant placeholder for cases when an actual version string is not available. It does not need to placed into the auto-generated ec_version.h header. * Remove the code that adds the CROS_FWID_MISSING_STR definition in zmake * Place the #define macro into cros_version.h, which is included by common/system.c already. * Update zmake unit tests BRANCH=None BUG=None TEST=zmake test test-drivers Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: I8bb8406823e7860162157c1baaa21440608f3eea Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3656257 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
* zephyr: panic: Capture the panic informationAndrew McRae2022-05-171-10/+2
| | | | | | | | | | | | | | | | Re-enable capturing the crash information from Zephyr and placing it in the panic structure at the end of RAM. For the host test environment, use a statically allocated panic data structure. BUG=b:231951177 TEST=zmake build nereid; test crash.ECCrash passes BRANCH=none Signed-off-by: Andrew McRae <amcrae@google.com> Change-Id: Iaf5230da79fbbbc2ffb0ea49555fad096d8dade0 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3634901 Reviewed-by: Keith Short <keithshort@chromium.org>
* hibernate: allow AP_PWRSEQ to indicate AP power statePeter Marheine2022-04-011-2/+3
| | | | | | | | | | | | | | | | | Firmwares using the new Zephyr ap_pwrseq subsystem don't enable HAS_TASK_CHIPSET, but use CONFIG_AP_PWRSEQ for the same function. Testing both ensures that systems using the new subsystem won't incorrectly attempt to hibernate when connected to power. BUG=b:226325993 TEST=Nereid now aborts hibernating when connected to external power with the "skip hibernate" message. BRANCH=none Signed-off-by: Peter Marheine <pmarheine@chromium.org> Change-Id: If1347cf9ffc4dd7a2e2e4369f8090110e65787b6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3561602 Reviewed-by: Andrew McRae <amcrae@google.com>
* zephyr: Add mock for system_jumped_late() functionTristan Honscheid2022-03-281-1/+1
| | | | | | | | | | | | | | | | | | Certain drivers behave differently when the system has performed a late jump. For example, the SN5S330 skips certain initialization steps if its init function runs a second time under a late-jump situation. To allow testing these different branches in unit tests, add around this function. By default, its return value is `0`, indicating no late jump. BRANCH=None BUG=b:225245353 TEST=zmake -D configure --test test-drivers Signed-off-by: Tristan Honscheid <honscheid@google.com> Change-Id: I2dc2132db3363606f0896d9c817e271ff3912190 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3552704 Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
* zephyr: Fix broken tests when coverage is enabledJeremy Bettis2022-02-171-1/+1
| | | | | | | | | | | | | | | | | | | | | While zmake testall was passing, zmake coverage was not. Probably because of branch coverage calculation, if an if statement includes both a const portion and a non-const portion, the const portion must be first, or it won't get optimized out. BRANCH=None BUG=b:219862697 TEST=zmake -j8 coverage build/zcoverage Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: I97c9aeab737702541b94b7867e02f943beb559c2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3470261 Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org> Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Al Semjonovs <asemjonovs@google.com> Commit-Queue: Al Semjonovs <asemjonovs@google.com>
* zephyr: Include common/system.c in posix alsoJeremy Bettis2022-02-151-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | Change arch posix to also include common/system.c This required removing some mocked functions from ztest_system.c, adding others, and making some of them test_mockable for tests that already provided them. There was one test scenario that had to be removed, as it's not clear how to simulate late jump to rw with the real system.c code. Added a TODO to come back and fix that test. BRANCH=None BUG=b:214256453,b:219520539 TEST=zmake testall Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: I59be918f95b3e1048c87b6cd504ae48627fd84c8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3451273 Tested-by: Jeremy Bettis <jbettis@chromium.org> Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
* atomic: fix printing atomic_t typeDawid Niedzwiecki2022-01-061-1/+1
| | | | | | | | | | | | | | | | | | | 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-1/+1
| | | | | | | | | | | | | | | | | | | | | 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>
* system: change sleep_mask to atomic_t typeDawid Niedzwiecki2021-11-291-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | The sleep_mask is used only with atomic_* functions or for reading, so change to variable type to atomic_t. Do the same with idle_disabled. It shouldn't change the generated code. The only noticed change is for mchp chip. The compiler uses .w asm extension for some instructions in __idle function in clock.c file. 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 BRANCH=main Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: I85d05bb911af973f030cf46d3f534c374ef76936 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3300320 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
* tree: Make all host commands staticTom Hughes2021-10-151-2/+2
| | | | | | | | | | | | | | Almost all of the host commands were already static. This change makes all of them static for consistency. BRANCH=none BUG=b:172020503 TEST=make buildall -j Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I8330e85e6d64a039f08d7620eed1fe897f436567 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3221786 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* tree: Remove CONFIG_RO_HEAD_ROOM and CONFIG_RW_HEAD_ROOMTom Hughes2021-10-061-5/+0
| | | | | | | | | | | | | | | | | CONFIG_RO_HEAD_ROOM and CONFIG_RW_HEAD_ROOM are always defined as 0, so remove the values and associated code in order to simplify the code and improve readability. BRANCH=none BUG=b:172020503 TEST=./util/compare_build.sh -b all => MATCH Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: Ie11d23befda674cc15dda9a2d66b9c43ea22d49e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3205489 Reviewed-by: Ting Shen <phoenixshen@chromium.org> Reviewed-by: Mary Ruthven <mruthven@chromium.org>
* ec_commands: Add ec_response_get_version_v1Rob Barnes2021-09-201-10/+18
| | | | | | | | | | | | | | | | | | | | | | | | | A field (cros_fwid_rw) was added to ec_response_get_version and the version was updated to v1. Some system components that still use v0 of the version host command fail because the size of the response does not match the updated ec_response_get_version struct. Restore ec_response_get_version to match v0. Create a new ec_response_get_version_v1 structure with the added v1 fields. This allows legacy code to continue using ec_response_get_version, which matches the expected response size for the v0 command. BUG=b:188073399,b:200075921 TEST=EC console 'version' works Legacy 'ectool version' works with old an new EC firmware. New 'ectool version' works with old and new EC firmware. BRANCH=None Change-Id: I51a052a550c2460f2604da8e04fc43c36acba4d5 Signed-off-by: Rob Barnes <robbarnes@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3169100 Reviewed-by: caveh jalali <caveh@chromium.org> Reviewed-by: Patryk Duda <patrykd@google.com> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* system: Add CrOS FWID to version outputRob Barnes2021-09-141-66/+103
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | EC version does not follow the the AP and OS version. This causes confusion during development. This change augments the EC version output to include the CrOS FWID when available. The CrOS FWID will be missing when the CrOS EC is built outside of cros_sdk. When CrOS FWID is missing 'CROS_FWID_MISSING' will be used. Zephyr/zmake support will be added later, CROS_FWID32 is set to 'CROS_FWID_MISSING' in zephyr builds until then. BUG=b:188073399 TEST=version 21-05-20 16:43:18.627 Chip: Nuvoton NPCX993F A.00160101 21-05-20 16:43:18.631 Board: 1 21-05-20 16:43:18.631 RO: guybrush_v2.0.8770+f47439f75 21-05-20 16:43:18.634 guybrush_13983.0.21_05_20 21-05-20 16:43:18.639 RW_A: * guybrush_v2.0.8770+f47439f75 21-05-20 16:43:18.641 * guybrush_13983.0.21_05_20 21-05-20 16:43:18.644 RW_B: guybrush_v2.0.8770+f47439f75 21-05-20 16:43:18.644 guybrush_13983.0.21_05_20 21-05-20 16:43:18.647 Build: guybrush_v2.0.8770+f47439f75 21-05-20 16:43:18.651 guybrush_13983.0.21_05_20 2021-05-20 21-05-20 16:43:18.657 16:31:19 robbarnes@robbarnes0 ectool version RO version: guybrush_v2.0.8770+f47439f75 RO cros fwid: guybrush_13983.0.21_05_20 RW version: guybrush_v2.0.8770+f47439f75 RW cros fwid: guybrush_13983.0.21_05_20 Firmware copy: RO Build info: guybrush_v2.0.8770+f47439f75 guybrush_13983.0.21_05_20 2021-05-20 16:31:19 robbarnes@robbarnes0 Tool version: 1.1.9999-f47439f @robbarnes0 BRANCH=None Signed-off-by: Rob Barnes <robbarnes@google.com> Change-Id: Ief0a0c6e9d35edc72ac2d4780ee203be41d7305f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2894145 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* system: add hibernate flagTim Lin2021-09-031-0/+2
| | | | | | | | | | | | | | | | Add hibernate flag. Before system reset, it should be distinguished as hard reset or hibernate reset and saved in BBRAM. BUG=none BRANCH=none TEST=none Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com> Change-Id: I0e06f3d1bea89ead1795cc07677e22e841643a97 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3139528 Reviewed-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
* system: fix system_get_scratchpad APIYuval Peress2021-08-201-1/+12
| | | | | | | | | | | | | | | The current API for system_get_scratchpad mixes the status and the value being read. Update the signature to allow both. BRANCH=none BUG=b:195481980 TEST=make testall && zmake testall Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I3a5f5ad523d507c53a5d474806f58afafb82e70c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3074828 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* common: system: always define host_command_get_board_versionDenis Brockus2021-07-291-2/+0
| | | | | | | | | | | | | | | | | | | There are platforms that have board defined get_board_version and they should be allowed to have host_command_get_board_version even if CONFIG_BOARD_VERSION_* are not defined. BUG=none BRANCH=none TEST=make buildall TEST=zmake configure -b $PROJ_HAYATO Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: I6e2765b40c7cbada82a8ace305899f2e319157c3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3058354 Tested-by: Denis Brockus <dbrockus@chromium.org> Auto-Submit: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
* cbi: Add CONFIG_EEPROM_CBI_WPAseda Aboagye2021-07-291-1/+1
| | | | | | | | | | | | | | | | | | | | | This commit adds the config option, CONFIG_EEPROM_CBI_WP. It is to be defined when the EC directly controls the CBI EEPROM WP signal. The EC will set the WP according to the result of `system_is_locked()`. Note that once the WP is set, the EC must be reset via EC_RST_ODL in order for the WP to become unset. This is enabled by the accompanying hardware. BUG=b:181769483 BRANCH=None TEST=`make -j buildall` Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: If490594ab4dd24af98119b01299215b997913b66 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3046412 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Auto-Submit: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
* system: don't hibernate if AC is presentRicardo Quesada2021-07-261-0/+15
| | | | | | | | | | | | | | | | | | | | | | | This CL prevents hibernation if AC adapter is connected. This is to prevent AP from rebooting. This might happen because if EC is hibernated when AC is connected, it might wake up immediately in response to AC being connected, resulting in AP reboot. BUG=b:192259035 TEST=delbin EC console: run "hibernate" w/ AC: didn't hibernate. Press Alt+Volume Up+H w/o AC: it hibernated. Press Alt+Volume Up+H w AC: it didn't hibernate. BRANCH=none Signed-off-by: Ricardo Quesada <ricardoq@google.com> Change-Id: I07dee088e5b6ed7d0b3901049323d93ef4d0b9c9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3042989 Commit-Queue: Ricardo Quesada <ricardoq@chromium.org> Tested-by: Ricardo Quesada <ricardoq@chromium.org> Auto-Submit: Ricardo Quesada <ricardoq@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* system: Generalize system_get_board_version()Philip Chen2021-07-121-5/+15
| | | | | | | | | | | | | | | | | | Extend system_get_board_version() to support not only AP-sourced SKU ID but also EC-sourced SKU ID, whose getter function can be customized per board. BRANCH=None BUG=b:186264627 TEST=make buildall -j TEST=zmake testall Change-Id: I764868d6472fb66480a43d028e5a79933b10117d Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3017602 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org>
* system: Clean up system_get_board_version()Philip Chen2021-07-091-19/+28
| | | | | | | | | | | | | | | | | | | Refactor system_get_board_version() a bit so that we can remove CONFIG_BOARD_VERSION_CUSTOM and CONFIG_BOARD_VERSION from config.h. BRANCH=None BUG=b:186264627 TEST=make buildall -j TEST=zmake testall Cq-Depend: chromium:3015243 Change-Id: Id5ab809493c297b7d330ea13dcd6934ec00042a6 Signed-off-by: Philip Chen <philipchen@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3004112 Commit-Queue: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
* System: Add SYSTEM_IN_MANUAL_RECOVERY flagDaisuke Nojiri2021-07-051-6/+23
| | | | | | | | | | | | | | | | | | This patch adds SYSTEM_IN_MANUAL_RECOVERY, which indicates the system is in recovery mode. It's set when EC_HOST_EVENT_KEYBOARD_RECOVERY is set and cleared when the system shuts down (not when the host event flag is cleared). BUG=b:188242794 BRANCH=None TEST=Verify sysinfo command prints 'Recovery: yes' in recovery screen. TEST=Verify sysinfo command prints 'Recovery: no' after shutting down from recovery screen. Change-Id: I357e25fa4072cb4549dbe2c6bd476b0a93ccbb38 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3001190
* system: Rename reset_flags used in system_encode_save_flagsDaisuke Nojiri2021-07-011-7/+7
| | | | | | | | | | | | | | | | | There is a variable named reset_flags, which is shared by all code in system.c. system_encode_save_flags gives its parameter the same name. This patch renames the local variable to remove the confusion. There is no functionality change. BUG=None BRANCH=None TEST=buildall Change-Id: I9838d8d4c77e3a266731a840c70a77ddf1cefb25 Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2998512 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
* EFS2: Clear EC_RESET_FLAG_EFS when jumping back to RODaisuke Nojiri2021-06-281-1/+6
| | | | | | | | | | | | | | | | | Currently, EC_RESET_FLAG_EFS isn't cleared once it's set until the next reset. This causes an RO copy to re-run init functions because system_jumped_late returns false. This patch makes EC_RESET_FLAG_EFS cleared before sysjump to RO. BUG=b:192022501 BRANCH=none TEST=buildall Change-Id: Ib151f2f619d1c59f46706a6cd43b05c26d67c74d Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2992548 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
* zephyr: fix jdata pointerDawid Niedzwiecki2021-06-151-2/+10
| | | | | | | | | | | | | | | | | Zephyr stores the panic date not at the end of RAM, thus the pointer to the jump data has to be calculated in a different way. With the change, the function system_usable_ram_end returns a correct value which is used to calculate the SharedMem size. BUG=b:178011288 BRANCH=none TEST=run firmware_ECSharedMem test on Lazor Signed-off-by: Dawid Niedzwiecki <dn@semihalf.com> Change-Id: If777261a5582071822a998e796973ec5b8cb3cac Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2960174 Reviewed-by: Yuval Peress <peress@chromium.org>
* zephyr: shim: add mpu enable and disable supportFabio Baltieri2021-06-141-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add support for allowing the EC code to control the MPU setup. ECOS code used to handle configuration as well as MPU enable/disable. Zephyr has its own way of handling MPU configuration, so that part of the EC code is compiled out, instead make sure that the fixed MPU regions (that cover code & data) are disabled before the EC code starts, and then enable them when mpu_enable() is called Zephyr APIs do not expose any memory protection funciontality outside of the arch specific code, so this sets the MPU regiers directly. That's not very elegant, but it's done in a sample application as well [1], so it should be an acceptable approach. Disabling the MPU unit entirely could also be an option, but only doing the fixed regions has the advantage of leaving the stack protection and null pointer detection regions enabled. [1] https://github.com/zephyrproject-rtos/zephyr/blob/main/samples/application_development/code_relocation/src/main.c BRANCH=none BUG=b:180039888 TEST=actually tried to write in the static region, verified it fauls after sysjump disable Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: I020c347e5f1b929500d4cf1c4c400dcd67e78dfa Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2950168 Reviewed-by: Yuval Peress <peress@chromium.org>
* include/flash: rename the APIsTim Lin2021-06-091-8/+8
| | | | | | | | | | | | | | | | The names conflict when enabling both Zephyr's flash driver and CONFIG_FLASH_CROS option. Rename all the APIs in include/flash.h BUG=b:187192628 BRANCH=none TEST=make buildall -j4 Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com> Change-Id: If1fd0ea28fa9f5cec1c1daa8f72f63eb7a0e6500 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2931749 Commit-Queue: Keith Short <keithshort@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
* zephyr: Don't reinitialize gpios on a warm rebootSam Hurst2021-06-031-11/+16
| | | | | | | | | | | | | | Don't reinitialize gpios on a warm reboot BRANCH=none BUG=b:187337449,b:186458444 TEST=Verified that the system booted properly Signed-off-by: Sam Hurst <shurst@google.com> Change-Id: Ie11bdde9fa0124c0bf21cdc9baa3a98a85bbdad2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2904549 Reviewed-by: Wai-Hong Tam <waihong@google.com> Commit-Queue: Keith Short <keithshort@chromium.org>
* config: rename CONFIG_FLASH to CONFIG_FLASH_CROSJeremy Bettis2021-04-271-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit 4ac1d81e1430dbfbfba1376a23ab19dfa845d7ef. The config name collides with the same config name in zephyr. Also, renames zephyr Kconfig CONFIG_PLATFORM_EC_FLASH to CONFIG_PLATFORM_EC_FLASH_CROS as the corresponding change at Kconfig side. BUG=chromium:1202406,b:180980668 TEST=make -j16 runhosttests buildall && zmake testall && \ /mnt/host/source/src/platform/ec/zephyr/firmware_builder.py --metrics \ /tmp/tmplt8ty8ci test ; echo $? BRANCH=none Signed-off-by: Jeremy Bettis <jbettis@google.com> Change-Id: I5b5e58b30d936b5232e049827f458d9a2ed06340 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2855320 Commit-Queue: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org> Tested-by: Jeremy Bettis <jbettis@chromium.org> Auto-Submit: Jeremy Bettis <jbettis@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org>