# OEM 定制

ArduPilot为OEM提供了几种方法,以提供其产品上符合其特定系统配置的固件:

- 具备特定默认参数以匹配包含的系统组件,如gimbals,或整个系统的外围设备,如即时飞行机体的能力. 这使得用户在遇到参数被意外更改的问题时,可以使用Mission Planner或MAVProxy"重置为默认",并且最多只需重新校准罗盘/IMU/和RC即可准备飞行.
- 能够为特殊功能提供ROM中的Lua脚本,而终端用户无需在SD卡上加载. 更多信息, 请访问ArduPilot 的 Lua 脚本**这里**.
- 更改显示给用户的固件字符串的能力 。
- 能够将图片和信息文件包含在可用的免费闪存空间中.
- 能够改变参数并将其标记为只读的,以便用户不能使用这些参数。**APJ 工具**.(截至4.5版固件,此已无法使用)
- 能力[安装 LUA 脚本以审查参数](https://github.com/ArduPilot/ardupilot/blob/master/libraries/AP_Scripting/applets/param-lockdown.md)在允许通过 MAVLink 设置它们之前。

## Customization Steps

This section assumes that the OEM has set up the build environment (**building-the-code**) and cloned the ArduPilot GitHub repo locally (**where-to-get-the-code**), to build its customized version of the firmware.

1. Create a branch with the version of firmware you wish to base the customization upon. This will usually be the current stable version. To do this for ArduPlane Stable, for example, assuming you are already in the ArduPilot directory on your PC:
    
    > ```
    > 
    > git fetch https://github.com/ArduPilot/ardupilot.git <version>
    >                     where <version> is the tag for the stable version for the
    >                     desired vehicle: ArduPlane-stable, ArduCopter-stable,
    >                     APMrover2-stable,etc.
    > 
    > git checkout -b <your branch name> FETCH_HEAD
    > git submodule update --init --recursive
    > ```
2. In the `libraries/AP_HAL_ChibiOS/hwdef` directory, create a new subdirectory for your customized board definitions. In this example, the directory will be named `OEM_CubeOrange` to create a derivative for that board.
3. Create a new `hwdef.dat` file in this format. In this case, our ready-to-fly plane will be using a CubeOrange autopilot and only requires a single line:
    
    > ```
    > 
    > include ../CubeOrange/hwdef.dat
    > ```
4. The firmware name can be customized by adding one line to the `hwdef.dat` file.
    
    > ```
    > 
    > define AP_CUSTOM_FIRMWARE_STRING "MyMagicFrame"
    > ```
    > 
    > <div class="callout info">**说明**：
    > 
    > Custom frame type strings can be created through Lua the scripting method `<span class="pre">motors:set_frame_string("Custom</span> frame name")`.
    > 
    > </div>
5. Now in that same directory, copy the base board's `<span class="pre">hwdef-bl.dat</span>` bootloader file, and then include a file named `defaults.parm`. This file will be the parameter overrides of the standard defaults to match your system's configuration. Things like output function assignments, auxiliary RC switches, flight and tuning parameters, etc.

<div class="callout info" id="bkmrk-%E8%AF%B4%E6%98%8E%EF%BC%9Aa-parameter-can-b">**说明**：

a parameter can be made readonly (ie user cannot change its value) by marking it `@READONLY` in the file

</div><div class="callout warning" id="bkmrk-%E8%AD%A6%E5%91%8A%EF%BC%9Athe-defaults.parm">**警告**：

The `defaults.parm` file should be as small as possible. Some boards only allow 1024 bytes total for this file. Every ASCII byte in the file counts against this limit (except for comment lines). Use integer values where possible. Below is a simple example. Serial port protocols,baud rate,and options defaults can be set directly in the hwdef, as well as NTF\_LED\_TYPES, and battery monitor defaults, and should be done there instead of a defaults file.

```

# setup for NTF LEDs on output5
SERVO5_FUNCTION 120
NTF_LED_TYPES 256
```

</div>1. You can also embed **Lua scripts** in the ROM of the chip that will automatically run. Since Lua is currently only run on autopilots with a lot of flash space, they are only restricted in total aggregate size to available free flash memory. Put the scripts in a sub-directory called `scripts`, i.e. `libraries/AP_HAL_ChibiOS/hwdef/OEM_CubeOrange/scripts`. Files must end in `.lua`.

Alternatively, you can specify the LUA applet or driver at compile by using the "--embed-&lt;filename&gt; command, for example:

> ```
> 
> ./waf plane --embed-LTE_modem
> ```
> 
> <div class="callout warning">**警告**：
> 
> The user may also run Lua scripts off the SD card, so care should be taken in naming the embedded script file names to not conflict with potential user file names. It is recommended that the file names of embedded Lua scripts be provided in the product documentation for the user.
> 
> </div>

1. You can also embed small pieces of documentation in the ROM of the chip that are readable when examining the @ROMFS folder via MAVFtp. These can be pictures or small informational documents. These must fit within the free flash space of the autopilot. These files can be located in sub-directories in `libraries/AP_HAL_ChibiOS/hwdef/OEM_CubeOrange` (e.g. `libraries/AP_HAL_ChibiOS/hwdef/OEM_CubeOrange/AircraftManual`).
2. Now build as normal with OEM-CubeOrange as the board name in the configuration. The default parameters, Lua scripts, and the custom firmware name will be embedded appropriately.

## Alternative To Customizing hwdef.dat

Instead of creating a separate branch and modifying the hwdef file, you can also insert Lua scripts or even informational files into the ROMFS of the build. Simply go to the top level of your ArduPilot git checkout and create a sub-folder named "ROMFS\_custom" in the root of the source tree. Place your LUA scripts in a sub-folder in this directory, named "scripts" (i.e. the path `ardupilot/ROMFS_custom/scripts`). You can have other sub-folders for informational files and these will be included and viewable when examining the @ROMFS folder with MAVFtp.

\[copywiki destination="plane,copter,rover,sub,dev"\]

*【本页后半部分仍为英文原文摘录，补译中。】*

---

*译自 ArduPilot Copter「OEM Customization」· [查看原文](https://ardupilot.org/copter/docs/common-oem-customizations.html) · CC BY-SA 3.0*