This document contains agent context for EC development.
This repository contains the Zephyr EC (embedded controller) firmware for Chromium OS devices. The EC handles low-level tasks such as power sequencing, battery charging, keyboard control, thermal management, power delivery, etc.
Starting roughly in July of 2021, Chromebooks switched from the original Google Chrome EC to an application based on the Zephyr Project RTOS. The following terms are used to describe these two implementations:
Legacy EC development has moved to the ec-legacy branch, also at chromiumos/src/platform/ec-legacy.
This repository is focused on Zephyr EC; any legacy-only code is pending removal. The Zephyr RTOS project is mirrored at chromiumos/src/third_party/zephyrproject/zephyr.
See local docs/ folder for detailed documentation on specific topics.
@context/ec_terms.md
cbmem command on DUT host.help for commands. Use dut-control ec_uart_pty to find the EC's UART path.tast.firmware.EcStress).cros_sdk (chroot): The ChromiumOS build environment. Build and test commands must be run inside this chroot. Use cros_sdk --working-dir . <cmd> from the host to run commands inside.dut-control: Command-line tool to interact with the Servo. It allows you to control the DUT (e.g., dut-control cold_reset:on), read GPIOs, etc. Use dut-control -i to list all available commands.ectool: Host utility to send commands to the EC from userspace (run from the DUT host).flash_ec: Utility script (util/flash_ec) to flash EC firmware via Servo.futility: Used to manage GBB flags (e.g., to disable Software Sync for development) (run inside cros_sdk or on the DUT).repo: The repository management tool built on top of Git, used to manage the massive ChromeOS source tree.twister: Zephyr's standard test runner tool, used to run unit and integration tests for the Zephyr EC.zmake: The build tool for Zephyr EC projects (run inside cros_sdk).Zephyr EC images rely on multiple Chromium repositories to build Zephyr EC images.
chromiumos/src/third_party/zephyrproject/zephyr - Google's local mirror of the main Zephyr RTOS source located on Github.chromiumos/src/platform/ec - local repository containing the Zephyr EC application (this repository).All paths below are relative to the Chrome EC base directory chromiumos/src/platform/ec.
common/ - Upper-level code shared across boards and the EC implementations. This includes the following features:
driver/ - Low-level drivers for on-board peripherals controlled by the EC. This does not include any drivers for modules integrated directly into the EC chipset (such as GPIO controllers, I2C, controllers, keyboard controller). On-board peripheral drivers include:
include/ - Header files for the common/ and driver/ code
build/ - The build output directory. This directory should be excluded when searching (e.g. grep --exclude-dir=build).
util/ - The EC utilities, including the ectool command-line tool.
The following legacy EC directories have been removed or are no longer used by the Zephyr EC:
baseboard/board/chip/core/The following provides an overview of the sub-directories found under chromiumos/src/platform/ec/zephyr/.
app/ - The Zephyr EC application entry point. The Zephyr kernel calls ec_app_main() routine after initializing all kernel services and chip-level drivers,boards/ - Contains the EC chip-level support. This directory and the organization is required by the Zephyr build system. This should not be confused with the legacy EC boards/ directory, as it does not contain any Chromebook specific board code.cmake/ - Configuration files for the CMake build system.drivers/ - Drivers conforming to the Zephyr device model to implement Chrome EC specific features. Google plans to eventually move these drivers upstream.dts/ - Devicetree description files for Google's Zephyr drivers that are not yet available upstream.emul/ - Emulator source code that has not yet been moved upstream.include/ - Header files for files found in the zephyr/ sub-directory.linker/ - Linker directive files used to construct the Zephyr EC binaries.program/ - Program-specific configurations for each program supported by Zephyr.shim/ - Source code that adapts the legacy EC APIs to the equivalent Zephyr OS API.subsys/ - Staging area for subsystem code that will be moved upstream.test/ - Host based emulation tests.zmake/ - Source code for the zmake/ meta tool.To build the EC for a single project, run zmake build <project> in the chroot:
For example, to build the EC for skyrim, run:
cros_sdk --working-dir . -- zmake build skyrim
The output binary will then be located at build/zephyr/skyrim/output/ec.bin.
Additional output files:
build/zephyr/skyrim/output/zephyr.ro.elf - read-only ELF for debuggingbuild/zephyr/skyrim/output/zephyr.rw.elf - read-write ELF for debuggingbuild/zephyr/skyrim/build-rw/zephyr/.config - Kconfig options selectedbuild/zephyr/skyrim/build-rw/zephyr/include/generated/devicetree_unfixed.hbuild/zephyr/skyrim/build-rw/zephyr/zephyr.dts - devicetree that is usedbuild/zephyr/skyrim/build-rw/zephyr/zephyr.map - map of imageZephyr EC unit tests are based on ztest and run using the twister tool. See docs/zephyr/ztest.md for more information.
platform/ec$ ./twister -T path/to/my/tests
platform/ec$ ./twister -s <test dir>/<my.test.scenario>
For example:
platform/ec$ ./twister -s drivers/drivers.default
drivers/ is the directory under zephyr/test/ that contains the requested test, and drivers.default is the specific test scenario specified in that directory's testcase.yaml file.
./twister -p native_sim -p unit_testing --coverage
./twister --help
repo outside chroot. repo start <branch> and repo upload . --cbr. Gerrit is used for code review.cros format <file> to format code.BUG=b:<id> and TEST=<description>. Keep each line under 80 characters. Change-Id must be preserved. See previous commits for examples.cros-ec-development extension instead.