1# Add a New System to OpenBMC
2
3**Document Purpose:** How to add a new system to the OpenBMC distribution
4
5**Audience:** Programmer familiar with OpenBMC
6
7**Prerequisites:** Completed Development Environment Setup [Document][1]
8
9## Overview
10
11This document will describe the following:
12
13* Review background about Yocto and BitBake
14* Creating a new system layer
15* Populating this new layer
16* Building the new system and testing in QEMU
17
18## Background
19
20The OpenBMC distribution is based on [Yocto](https://www.yoctoproject.org/).
21Yocto is a project that allows developers to create custom Linux distributions.
22OpenBMC uses Yocto to create their embedded Linux distribution to run on
23a variety of devices.
24
25Yocto has a concept of hierarchical layers. When you build a Yocto-based
26distribution, you define a set of layers for that distribution. OpenBMC uses
27many common layers from Yocto as well as some of its own layers. The layers
28defined within OpenBMC can be found with the meta-* directories in OpenBMC
29[GitHub](https://github.com/openbmc/openbmc).
30
31Yocto layers are a combination of different files that define packages to
32incorporate in that layer. One of the key file types used in these layers is
33[BitBake](https://github.com/openembedded/bitbake/blob/master/README) recipes.
34
35BitBake is a fully functional language in itself. For this lesson, we will
36focus on only the aspects of BitBake required to understand the process of
37adding a new system.
38
39## Start the Initial BitBake
40
41For this work, you will need to have allocated at least 100GB of space to your
42development environment and as much memory and CPU as possible. The initial
43build of an OpenBMC distribution can take hours. Once that first build is done
44though, future builds will use cached data from the first build, speeding the
45process up by orders of magnitude.
46
47So before we do anything else, let's get that first build going.
48
49Follow the direction on the OpenBMC GitHub [page](https://github.com/openbmc/openbmc/blob/master/README.md#2-download-the-source)
50for the Romulus system (steps 2-4).
51
52## Create a New System
53
54While the BitBake operation is going above, let's start creating our new system.
55Similar to previous lessons, we'll be using Romulus as our reference. Our new
56system will be called romulus-prime.
57
58From your openbmc repository you cloned above, the Romulus layer is defined
59within `meta-ibm/meta-romulus/`.  The Romulus layer is defined within the
60`conf` subdirectory. Under `conf` you will see a layout like this:
61
62```
63meta-ibm/meta-romulus/conf/
64├── bblayers.conf.sample
65├── conf-notes.txt
66├── layer.conf
67├── local.conf.sample
68└── machine
69    └── romulus.conf
70```
71
72To create our new romulus-prime system we are going to start out by copying
73our romulus layer.
74```
75cp -R meta-ibm/meta-romulus meta-ibm/meta-romulus-prime
76```
77
78Let's review and modify each file needed in our new layer
79
801. meta-ibm/meta-romulus-prime/conf/bblayers.conf.sample
81
82   This file defines the layers to pull into the meta-romulus-prime
83   distribution. You can see in it a variety of Yocto layers (meta, meta-poky,
84   meta-openembedded/meta-oe, ...). It also has OpenBMC layers like
85   meta-phosphor, meta-openpower, meta-ibm, and meta-ibm/meta-romulus.
86
87   The only change you need in this file is to change the two instances of
88   meta-romulus to meta-romulus-prime. This will ensure your new layer is used
89   when building your new system.
90
912. meta-ibm/meta-romulus-prime/conf/conf-notes.txt
92
93   This file simply states the default target the user will build when working
94   with your new layer. This remains the same as it is common for all OpenBMC
95   systems.
96
973. meta-ibm/meta-romulus-prime/conf/layer.conf
98
99   The main purpose of this file is to tell BitBake where to look for recipes
100   (\*.bb files). Recipe files end with a `.bb` extension and are what contain
101   all of the packaging logic for the different layers. `.bbappend` files are
102   also recipe files but provide a way to append onto `.bb` files.
103   `.bbappend` files are commonly used to add or remove something from a
104   corresponding `.bb` file in a different layer.
105
106   The only change you need in here is to find/replace the "romulus-layer" to
107   "romulus-prime-layer"
108
1094. meta-ibm/meta-romulus-prime/conf/local.conf.sample
110
111   This file is where all local configuration settings go for your layer. The
112   documentation in it is well done and it's worth a read.
113
114   The only change required in here is to change the `MACHINE` to
115   `romulus-prime`.
116
1175. meta-ibm/meta-romulus-prime/conf/machine/romulus.conf
118
119   This file describes the specifics for your machine. You define the kernel
120   device tree to use, any overrides to specific features you will be pulling
121   in, and other system specific pointers. This file is a good reference for
122   the different things you need to change when creating a new system (kernel
123   device tree, MRW, LED settings, inventory access, ...)
124
125   The first thing you need to do is rename the file to `romulus-prime.conf`.
126
127   **Note** If our new system really was just a variant of Romulus,
128   with the same hardware configuration, then we could have just created a
129   new machine in the Romulus layer. Any customizations for that system
130   could be included in the corresponding .conf file for that new machine. For
131   the purposes of this exercise we are assuming our romulus-prime system has
132   at least a few hardware changes requiring us to create this new layer.
133
134## Build New System
135
136This will not initially compile but it's good to verify a few things from the
137initial setup are done correctly.
138
139Do not start this step until the build we started at the beginning of this
140lesson has completed.
141
1421. Modify the conf for your current build
143
144   Within the shell you did the initial "bitbake" operation you need to reset
145   the conf file for your build. You can manually copy in the new files or just
146   remove it and let BitBake do it for you:
147   ```
148   cd ..
149   rm -r ./build/conf
150   export TEMPLATECONF=meta-ibm/meta-romulus-prime/conf
151   . openbmc-env
152   ```
153
154   Run your "bitbake" command.
155
1562. Nothing RPROVIDES 'romulus-prime-config'
157
158   This will be your first error after running "bitbake obmc-phosphor-image"
159   against your new system.
160
161   The openbmc/skeleton repository was used for initial prototyping of OpenBMC.
162   Within this repository is a [configs](https://github.com/openbmc/skeleton/tree/master/configs) directory.
163
164   The majority of this config data is no longer used but until it is all
165   completely removed, you need to provide it.
166
167   Since this repository and file are on there way out, we'll simply do a quick
168   workaround for this issue.
169
170   Create a config files as follows:
171   ```
172   cp meta-ibm/meta-romulus-prime/recipes-phosphor/workbook/romulus-config.bb meta-ibm/meta-romulus-prime/recipes-phosphor/workbook/romulus-prime-config.bb
173
174   vi meta-ibm/meta-romulus-prime/recipes-phosphor/workbook/romulus-prime-config.bb
175
176   SUMMARY = "Romulus board wiring"
177   DESCRIPTION = "Board wiring information for the Romulus OpenPOWER system."
178   PR = "r1"
179
180   inherit config-in-skeleton
181
182   #Use Romulus config
183   do_make_setup() {
184           cp ${S}/Romulus.py \
185                   ${S}/obmc_system_config.py
186           cat <<EOF > ${S}/setup.py
187   from distutils.core import setup
188
189   setup(name='${BPN}',
190       version='${PR}',
191       py_modules=['obmc_system_config'],
192       )
193   EOF
194   }
195
196   ```
197
198   Re-run your "bitbake" command.
199
2003. Fetcher failure for URL: file://romulus.cfg
201
202   This is the config file required by the kernel. It's where you can put some
203   additional kernel config parameters. For our purposes here, just modify
204   romulus-prime to use the romulus.cfg file. We just need to add the `-prime`
205   to the prepend path.
206   ```
207   vi ./meta-ibm/meta-romulus-prime/recipes-kernel/linux/linux-aspeed_%.bbappend
208
209   FILESEXTRAPATHS_prepend_romulus-prime := "${THISDIR}/${PN}:"
210   SRC_URI += "file://romulus.cfg"
211   ```
212
213   Re-run your "bitbake" command.
214
2154. No rule to make target arch/arm/boot/dts/aspeed-bmc-opp-romulus-prime.dtb
216
217   The .dtb file is a device tree blob file. It is generated during the Linux
218   kernel build based on its corresponding .dts file. When you introduce a
219   new OpenBMC system, you need to send these kernel updates upstream. The
220   linked email [thread](https://lists.ozlabs.org/pipermail/openbmc/2018-September/013260.html)
221   is an example of this process. Upstreaming to the kernel is a lesson in
222   itself. For this lesson, we will simply use the Romulus kernel config files.
223   ```
224   vi ./meta-ibm/meta-romulus-prime/conf/machine/romulus-prime.conf
225   # Replace the ${MACHINE} variable in the KERNEL_DEVICETREE
226
227   # Use romulus device tree
228   KERNEL_DEVICETREE = "${KMACHINE}-bmc-opp-romulus.dtb"
229   ```
230
231   Re-run your "bitbake" command.
232
233## Boot New System
234
235And you've finally built your new system's image! There are more
236customizations to be done but let's first verify what you have boots.
237
238Your new image will be in the following location from where you ran your
239"bitbake" command:
240```
241./tmp/deploy/images/romulus-prime/obmc-phosphor-image-romulus-prime.static.mtd
242```
243Copy this image to where you've set up your QEMU session and re-run the
244command to start QEMU (`qemu-system-arm` command from
245[dev-environment.md][1]), giving your new file as input.
246
247Once booted, you should see the following for the login:
248```
249romulus-prime login:
250```
251
252There you go! You've done the basics of creating, booting, and building a new
253system. This is by no means a complete system but you now have the base for
254the customizations you'll need to do for your new system.
255
256## Further Customizations
257
258There are a lot of other areas to customize when creating a new system.
259We'll dig into more detail with these (IPMI, HWMON, LED) in future
260development guides.
261
262Although not in the same format as these guides, [Porting_Guide](https://github.com/mine260309/openbmc-intro/blob/master/Porting_Guide.md)
263provides a lot of very useful information as well on adding a new system.
264
265[1]: https://github.com/openbmc/docs/blob/master/development/dev-environment.md
266