Skip to content

Commit 7da15e7

Browse files
Jett RinkCommit Bot
Jett Rink
authored and
Commit Bot
committed
doc: add zephyr shim design
We are turning platform/ec code into a zephyr module that we can then shim into a zephyr build. We are going to do this while we are transitioning to the zephyr codebase. BRANCH=none BUG=none TEST=none Signed-off-by: Jett Rink <[email protected]> Change-Id: I68fb215296e872c68fef1cb5cd92902f3f8ee8e2 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2438807 Commit-Queue: Jack Rosenthal <[email protected]> Reviewed-by: Jack Rosenthal <[email protected]>
1 parent 9123256 commit 7da15e7

File tree

1 file changed

+168
-0
lines changed

1 file changed

+168
-0
lines changed

docs/zephyr_shim.md

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
[TOC]
2+
3+
# Objective
4+
5+
Allow a subset of the platform/ec code to be built as part of the Zephyr-based
6+
EC without needing to land code into upstream zephyr, or our zephyr-chrome
7+
repository.
8+
9+
# Background
10+
11+
Now that Google has joined [Zephyr OS](https://www.zephyrproject.org/), the EC
12+
team is moving toward it instead of platform/ec code on embedded controllers for
13+
future Chrome OS devices. See the
14+
[originally proposed idea](https://goto.google.com/cros-ec-rtos) and a more
15+
specific [Zephyr process doc](https://goto.google.com/zephyr-structure) of what
16+
future development on Zephyr will look like.
17+
18+
Simply put, we want to move to Zephyr OS to use an open-source embedded OS that
19+
has a vibrant community. The embedded OS scene for the industry is very
20+
fragmented, with various parties using their own custom solution. We see the
21+
strong open-source community at Zephyr as potentially helping to consolidate
22+
efforts in the embedded controller space. It will also benefit our partners
23+
(both chip vendors and OEMs) since they should only have to support one embedded
24+
OS (i.e., Zephyr) for both their Chrome OS and Windows based devices.
25+
26+
Migrating to use Zephyr fully is going to take a few years. We do not want to
27+
diverge from the active development happening on platform/ec code. We
28+
potentially want to ship a product using Zephyr before the migration is
29+
complete.
30+
31+
# Design ideas
32+
33+
In order to reuse `platform/ec` development , we shim "active" `platform/ec`
34+
code as a
35+
[Zephyr Module](https://docs.zephyrproject.org/latest/guides/modules.html). This
36+
requires us to add some Zephyr specific code in a `zephyr` directory in the
37+
`platform/ec` codebase. Once we release a Zephyr-based EC, then we can turn down
38+
platform/ec for future development and work on migrating the platform/ec-module
39+
code out of the module directory and into a first-class Zephyr code format -- in
40+
the local
41+
[Chrome Zephyr repo](https://chromium.googlesource.com/chromiumos/platform/zephyr-chrome/+/refs/heads/master)
42+
and ultimately [upstream](https://github.com/zephyrproject-rtos/zephyr).
43+
44+
For platform/ec code that is stable and not under active development, the Zephyr
45+
team may port that code to Zephyr, thus skipping the shimming process.
46+
47+
## Subsystems of interest
48+
49+
### With Shim
50+
51+
We shim the following subsystems (non-exhaustive).
52+
53+
* USB-C: TCPC, PPC, MUX, TCPMv2
54+
* Charge Manager
55+
* SoC Power Sequencing
56+
* Sensors, if Intel’s HID-based solution is delayed in getting to Zephyr
57+
upstream
58+
59+
### Little-to-No Shim
60+
61+
We adopt upstream Zephyr or skip the shimming process (non-exhaustive).
62+
63+
* CBI and dependent EEPROM code
64+
* The format is stable. We pull in the list of CBI tags from platform/ec
65+
though
66+
* EFS2, Vboot, RO/RW split
67+
* Adjusting flash layout would be difficult to shim, and the concept is
68+
very stable.
69+
* We may shim some core EFS2 logic
70+
* Host command framework
71+
* Sensors, if Intel’s HID-based solution getts to Zephyr upstream and passes
72+
CTS
73+
* Keyboard and keycode scanning support
74+
* We may shim the newer Vivaldi feature.
75+
* Console support
76+
* We allow individual console commands via DECLARE\_CONSOLE\_COMMAND to be
77+
shimmed to Zephyr. These convert commands to work with Zephyr's shell
78+
subsystem.
79+
* I2C
80+
81+
## New content in platform/ec
82+
83+
Add the `src/platform/ec/zephyr` folder with:
84+
85+
* [Module integration files](https://docs.zephyrproject.org/latest/guides/modules.html#build-system-integration),
86+
e.g., module.yml, CMakeLists.txt, and KConfig.
87+
* **module.yml** is the required entry point (must be located at
88+
_zephyr/module.yml_ in the repository) for Zephyr modules, and declares
89+
the location of Kconfig and CMakeLists.txt files used by the Zephyr
90+
build system.
91+
* **CMakeLists.txt** replicates build logic for the files being shimmed,
92+
outside of the platform/ec Makefile.
93+
* **Kconfig** will declare any CONFIG\_\* options which are important to
94+
expose from platform/ec code to the Zephyr build.
95+
* Shim code to translate platform/ec code into Zephyr code
96+
* For example, redefine platform/ec’s
97+
[`DECLARE_HOST_COMMAND`](https://source.chromium.org/chromiumos/chromiumos/codesearch/+/master:src/platform/ec/include/host_command.h;l=256;drc=514923bc59f5a3435dbb7cbf348735ed41889ffe)
98+
to map to Zephyr's upstream
99+
[`EC_HOST_CMD_HANDLER`](https://github.com/zephyrproject-rtos/zephyr/blob/d7468bf836b75c29980441f294a61eae6bf4bc75/include/ec_host_cmd.h#L73)
100+
macro. This allows us to compile select platform/ec files in the Zephyr
101+
build.
102+
103+
## Namespace Collisions
104+
105+
One significant issue of mixing Zephyr headers with our existing EC code is that
106+
we currently have many names colliding with the Zephyr code. For example,
107+
Zephyr's atomic functions also are named `atomic_add`, `atomic_or`, ...,
108+
however, have a different API from our EC's atomic functions. This is critical,
109+
since atomic operations are often used in `static inline` functions placed in
110+
header files.
111+
112+
In some cases, we are able to hack around these collisions by creating macros
113+
and functions which are compatible with both Zephyr and our EC's usages. For
114+
example, we can create a modified `IS_ENABLED` which accepts both defined to
115+
nothing usages (CrOS EC `config.h` style), and defined to `1` usages (Zephyr
116+
Kconfig style).
117+
118+
However, long term, we may find this to be a continual cause of issues, and
119+
creating hacks for every colliding macro or function may be unsustainable. We
120+
propose _gradually_ introducing a namespace prefix to the `platform/ec`
121+
codebase, for example `crec_`. We can begin at the critical areas of namespace
122+
collision (e.g., atomics) and continue to improve the naming convention with
123+
time.
124+
125+
## New CQ check
126+
127+
As long as code from platform/ec is part of the zephyr
128+
[ebuild](http://cs/chromeos_public/src/third_party/chromiumos-overlay/chromeos-base/chromeos-zephyr-2_3/chromeos-zephyr-2_3-9999.ebuild),
129+
then we need to run the Zephyr CQ checks on any platform/ec CLs in addition to
130+
the normal platform/ec CQ checks. This ensures that platform/ec changes aren’t
131+
breaking the Zephyr builds and requiring the Zephyr team to debug recent
132+
changes.
133+
134+
For local builds, we can run `emerge-betty chromeos-zephyr-2_3` or `zmake`
135+
utility to check that an EC CL has not broken anything on the Zephyr side.
136+
137+
We will work with the CI team to enable this.
138+
139+
# Alternatives Considered
140+
141+
## Translate code and mirror into the zephyr-chrome repository
142+
143+
We could potentially write a script which, via a series of find/replace
144+
operations, translates a platform/ec module to use Zephyr functions, macros, and
145+
paradigms. On a frequent basis, we would translate all modules of interest in
146+
the platform/ec repository and land an "uprev" change in the zephyr-chrome
147+
repository.
148+
149+
The main disadvantage of this technique is that we can't get any CQ coverage
150+
when platform/ec CLs land that the modules will continue to work in Zephyr.
151+
Additionally, the translator script would be delicate and probably require
152+
frequent maintenance.
153+
154+
However, this technique does have some benefits. With modules directly
155+
translated to code in the Zephyr paradigm, the process of upstreaming a shimmed
156+
module to ZephyrOS would be significantly easier. Additionally, it would require
157+
no shim code in platform/ec.
158+
159+
## Don't do any code sharing
160+
161+
One option is to avoid shimming in any platform/ec code and allow the Zephyr
162+
team to re-implement features in upstream zephyr, or our local zephyr-chrome
163+
repository.
164+
165+
Disregarding the infeasible amount of work required to complete this option, the
166+
platform/ec repository has a far faster development pace as there are many more
167+
contributors, and the Zephyr features would quickly lose parity during the time
168+
frame that we are launching both Zephyr-based and platform/ec-based devices.

0 commit comments

Comments
 (0)