blob: 5e81034cc9690c297a68759c9c610bcf13fd703d [file] [log] [blame] [view]
David Ghandehari9e5b5872016-07-28 09:50:04 -07001# Starboard
2
3Starboard is Cobalt's porting layer and OS abstraction. It attempts to encompass
4all the platform-specific functionality that Cobalt actually uses, and nothing
5that it does not.
6
7
8## Current State
9
David Ghandehari8c5039b2016-08-17 19:39:30 -070010Desktop Linux Cobalt is fully implemented on top of Starboard, and version 1 of
11the Starboard API is mostly locked down.
David Ghandehari9e5b5872016-07-28 09:50:04 -070012
13
14## Interesting Source Locations
15
16All source locations are specified relative to `src/starboard/` (this directory).
17
18 * `.` - This is the root directory for the Starboard project, and contains all
19 the public headers that Starboard defines.
20 * `examples/` - Example code demonstrating various aspects of Starboard API
21 usage.
22 * `linux/` - The home of the Linux Starboard implementation. This contains a
23 `starboard_platform.gyp` file that defines a library with all the source
24 files needed to provide a complete Starboard Linux implementation. Source
25 files that are specific to Linux are in this directory, whereas shared
26 implementations are pulled from the shared directory.
27 * `nplb/` - "No Platform Left Behind," Starboard's platform verification test
28 suite.
29 * `shared/` - The home of all code that can be shared between Starboard
30 implementations. Subdirectories delimit code that can be shared between
31 platforms that share some facet of their OS API.
32
33
34## Building with Starboard
35
36Follow the Cobalt instructions, except when invoking gyp:
37
38 $ cobalt/build/gyp_cobalt -C debug linux-x64x11
39
40and when invoking ninja:
41
42 $ ninja -C out/linux-x64x11_debug cobalt
43
44
45## Quick Guide to Starting a Port
46
47### I. Enumerate and Name Your Platform Configurations
48
49Before starting a Cobalt/Starboard port, first you will need to define the
50canonical names for your set of platform configurations. These will be used when
51organizing the code for your platforms.
52
53What determines what goes into one platform configuration versus another? A
54platform configuration has a one-to-one mapping to a production binary. So, if
55you will need to produce a new binary, you are going to need a new platform
56configuration for that.
57
58The recommended naming convention for a `<platform-configuration>` is:
59
60 <family-name>-<binary-variant>
61
62Where `<family-name>` is a name specific to the family of products you are
63porting to Starboard and `<binary-variant>` is one or more tokens that uniquely
64describe the specifics of the binary you want that configuration to produce.
65
66For example, let's say your company is named BobCo. BobCo employs multiple
67different device architectures so it will need to define multiple platform
68configurations.
69
70All the BobCo devices are called BobBox, so it's a reasonable choice as a
71product `<family-name>`. But they have both big- and little-endian MIPS
72chips. So they might define two platform configurations:
73
74 1. `bobbox-mipseb` - For big-endian MIPS devices.
75 1. `bobbox-mipsel` - For little-endian MIPS devices.
76
77
78### II. Choose a Location in the Source Tree for Your Starboard Port
79
80To be perfectly compatible with the Cobalt source tree layout, any code that is
81written by a party that isn't the Cobalt team should be in the
82`src/third_party/` directory. The choice is up to you, but we recommend that you
83follow this practice, even if, as we expect to be common, you do not plan on
84sharing your Starboard implementation with anyone.
85
86Primarily, following this convention ensures that no future changes to Cobalt or
87Starboard will conflict with your source code additions. Starboard is intended
88to be a junction where new Cobalt versions or Starboard implementations can be
89replaced without significant (and hopefully, any) code changes.
90
91We recommend that you place your code here in the source tree:
92
93 src/third_party/starboard/<family-name>/
94
95With subdirectories:
96
97 * `shared/` - For code shared between architectures within a product family.
98 * `<binary-variant>/` - For any code that is specific to a specific binary
99 variant. Each one of these must at least have `configuration_public.h`,
100 `atomic_public.h`, `thread_types_public.h`, `gyp_configuration.py`,
101 `gyp_configuration.gypi`, and `starboard_platform.gyp` files.
102
103In the BobCo's BobBox example, we would see something like:
104
105 * `src/third_party/starboard/bobbox/`
106 * `shared/`
107 * `mipseb/`
108 * `atomic_public.h`
109 * `configuration_public.h`
110 * `gyp_configuration.gypi`
111 * `gyp_configuration.py`
112 * `starboard_platform.gyp`
113 * `thread_types_public.h`
114 * `mipsel/`
115 * `atomic_public.h`
116 * `configuration_public.h`
117 * `gyp_configuration.gypi`
118 * `gyp_configuration.py`
119 * `starboard_platform.gyp`
120 * `thread_types_public.h`
121
122And so on.
123
124
125### III. Base Your Port on a Reference Port
126
127You can start off by copying files from a reference port to your port's
128location. Currently these reference ports include:
129
130 * `src/starboard/stub`
131 * `src/starboard/linux`
132 * `src/starboard/raspi`
133
134The `starboard_platform.gyp` contains absolute paths, so the paths will still be
135valid if you copy it to a new directory. You can then incrementally replace
136files with new implementations as necessary.
137
David Ghandehari8c5039b2016-08-17 19:39:30 -0700138The cleanest, simplest starting point is from the Stub reference
139implementation. Nothing will work, but you should be able to compile and link it
140with your toolchain. You can then replace stub implementations with
141implementations from `src/starboard/shared` or your own custom implementations
142module-by-module, until you have gone through all modules.
David Ghandehari9e5b5872016-07-28 09:50:04 -0700143
David Ghandehari8c5039b2016-08-17 19:39:30 -0700144You may also choose to copy either the Desktop Linux or Raspberry Pi ports and
145work backwards fixing things that don't compile or work on your platform.
146
147For example, for `bobbox-mipsel`, you might do:
148
149 mkdir -p src/third_party/starboard/bobbox
150 cp -R src/starboard/stub src/third_party/starboard/bobbox/mipsel
David Ghandehari9e5b5872016-07-28 09:50:04 -0700151
152Modify the files in `<binary-variant>/` as appropriate (you will probably be
153coming back to these files a lot).
154
155Update `<binary-variant>/starboard_platform.gyp` to point at all the source
156files that you want to build as your new Starboard implementation. The
157`'<(DEPTH)'` expression in GYP expands to enough `../`s to take you to the
158`src/` directory of your source tree. Otherwise, files are assumed to be
159relative to the directory the `.gyp` or `.gypi` file is in.
160
David Ghandehari9e5b5872016-07-28 09:50:04 -0700161In order to use a new platform configuration in a build, you need to ensure that
162you have a `gyp_configuration.py`, `gyp_configuration.gypi`, and
Andrew Topa953d4e2016-11-22 22:38:45 -0800163`starboard_platform.gyp` in their own directory for each binary variant, plus
David Ghandehari9e5b5872016-07-28 09:50:04 -0700164the header files `configuration_public.h`, `atomic_public.h`, and
165`thread_types_public.h`. `gyp_cobalt` will scan your directories for these
166files, and then calculate a port name based on the directories between
167`src/third_party/starboard` and your `gyp_configuration.*` files. (e.g. for
168`src/third_party/starboard/bobbox/mipseb/gyp_configuration.py`, it would choose
David Ghandehari8c5039b2016-08-17 19:39:30 -0700169the platform configuration name `bobbox-mipseb`.)
David Ghandehari9e5b5872016-07-28 09:50:04 -0700170
David Ghandehari8c5039b2016-08-17 19:39:30 -0700171
172### IV. A New Port, Step-by-Step
173
174 1. Recursively copy `src/starboard/stub` to
175 `src/third_party/starboard/<family-name>/<binary-variant>`. You may also
176 consider copying from another reference platform, like `raspi-1` or
177 `linux-x64x11`.
178 1. In `gyp_configuration.py`
179 1. In the `CreatePlatformConfig()` function, pass your
180 `<platform-configuration>` as the parameter to the PlatformConfig
181 constructor, like `return PlatformConfig('bobbox-mipseb')`.
182 1. In `GetVariables`
183 1. Set `'clang': 1` if your toolchain is clang.
184 1. Delete other variables in that function that are not needed for
185 your platform.
186 1. In `GetEnvironmentVariables`, set the dictionary values to point to the
187 toolchain analogs for the toolchain for your platform.
188 1. In `gyp_configuration.gypi`
189 1. Update the names of the configurations and the default_configuration to
190 be `<platform-configuation>_<build-type>` for your platform
191 configuration name, where `<build-type>` is one of `debug`, `devel`,
192 `qa`, `gold`.
David Ghandehari9e5b5872016-07-28 09:50:04 -0700193 1. Update your platform variables.
194 1. Set `'target_arch'` to your architecture: `'arm'`, `'ppc'`,
195 `'x64'`, `'x86'`, `'mips'`
196 1. Set `'target_os': 'linux'` if your platform is Linux-based.
197 1. Set `'gl_type': 'system_gles2'` if you are using the system EGL +
198 GLES2 implementation.
199 1. Set `'in_app_dial'` to `1` or `0`. This enables or disables the
200 DIAL server that runs inside Cobalt, only when Coblat is
201 running. You do not want in-app DIAL if you already have
202 system-wide DIAL support.
203 1. Update your toolchain command-line flags and libraries. Make sure you
204 don't assume a particular workstation layout, as it is likely to be
205 different for someone else.
206 1. Update the global defines in `'target_defaults'.'defines'`, if
207 necessary.
David Ghandehari8c5039b2016-08-17 19:39:30 -0700208 1. Go through `configuration_public.h` and adjust all the configuration values
209 as appropriate for your platform.
210 1. Update `starboard_platform.gyp` to point at all the source files you want
211 to build as part of your new Starboard implementation (as mentioned above).
212 1. Update `atomic_public.h` and `thread_types_public.h` as necessary to point
213 at the appropriate shared or custom implementations.
David Ghandehari9e5b5872016-07-28 09:50:04 -0700214
215
216You should now be able to run gyp with your new port. From your `src/` directory:
217
218 $ cobalt/build/gyp_cobalt -C debug bobbox-mipseb
219 $ ninja -C out/bobbox-mipseb_debug nplb
220
221This will attempt to build the "No Platform Left Behind" test suite with your
222new Starboard implementation, and you are ready to start porting!
223
224
225## Suggested Implementation Order
226
227When bringing up a new Starboard platform, it is suggested that you try to get
228the NPLB tests passing module-by-module. Because of dependencies between
229modules, you will find it easier to get some modules passing sooner than other
230modules.
231
232Here's a recommended module implementation order in which to get things going
233(still significantly subject to change based on feedback):
234
235 1. Configuration
236 1. main(), Application, & Event Pump (i.e. the call into SbEventHandle)
237 1. Memory
238 1. Byte Swap
239 1. Time
240 1. String/Character/Double
241 1. Log
242 1. File
243 1. Directory
244 1. System
245 1. Atomic
246 1. Thread & Thread Types
247 1. Mutex
248 1. Condition Variable
249 1. Once
250 1. Socket
251 1. SocketWaiter
252 1. Window
253 1. Input
254 1. Blitter (if applicable)
255 1. Audio Sink
256 1. Media & Player
257 1. DRM
258 1. TimeZone
259 1. User
260 1. Storage