Gonk 在 Firefox OS stack 中可看作是 kernel 层级的组件，在 Gecko 和 底层硬件中间充当接口的作用。Gonk 对底层的硬件进行控制，并且将硬件信息及操控接口暴露给 Gecko中的 Web APIs。Gonk 可以看作是一个 黑盒， 在屏幕后面做了所有复杂细节的工作用于在硬件层级上对 mobile device 进行控制。
Gonk 只是一个简单的 Linux 发行版本，其中包括了 Android 的一些组件（如 GPS 和 Camera）以及由 Mozilla 扩展的常用的开源工程，如 libusb, bluez, 进而将所有的层级集成到 Firefox OS 架构中。这种设计方式对 OEM 将软件组件从其他 Android 实现上移植过来是非常方便的。
Gonk 是一个设备接口层，可看作是 硬件和 Gecko 之间的适配器。 Gonk is a relatively simple Linux distribution that can be treated as a Gecko Port paired with Gecko porting layers — so Gonk is a porting target of Gecko, just like there's a port of Gecko to OS X, Windows, and Android.
Note: Since different mobile devices may have different chipsets and other hardware specs, devices may contain different Gonk distributions.
由于 Firefox OS 工程对 Gonk 的完整控制，我们可以向 Gecko 中暴露一些在其他操作系统中无法实现的接口。例如， Gecko 已经可以直接对 full telephone stack 直接进行发给男问，并在 Gonk 中显示出 frame buffer。
Each mobile phone model has a specialized combination of Gonk components based on the system libraries, device drivers, and firmware required to operate the device. These components are determined by the OEM in collaboration with chipset manufacturers and ODMs. The following figure shows an example Gonk implementation:
This example shows the following main components (which represent only a subset of the possible components in any given Gonk implementation):
- Linux Kernel: Uses libraries from Android (GPS, camera, etc.) and other open source projects (Linux, libusb, bluez, and so on).
- Radio Interface Layer (RIL): Interacts with the modem hardware (telephony) in the phone. Consists of two components:
- rild daemon: Talks to the modem firmware.
- rilProxy: Proxies messages between rild and the b2g process
- mediaserver process: 控制 audio 和 video 的播放。Gecko 与 media server 通过 Android RPC 机制进行通信。
- netd process: 与 network 接口 (Wifi) 硬件直接交互的 Network dameon
- Bluetooth, etc.: Bluetooth and other service-level daemons provide access to hardware capabilities.
Gonk 也会启动，管理以及关闭 b2g process， b2g process 属于 Firefox OS 的 Gecko 层。The b2g process acts as a client to service-level daemons in Gonk that interact directly with the hardware and expose to Gecko the underlying hardware functionality of the phone. Gecko talks with these daemons via inter-process communication (IPC). These components collaboratively exchange commands and protocols to request and provide services.
Note: For more information on Gonk architecture, see the Firefox OS architecture guide.
Because Firefox OS is based on the Android kernel, existing device drivers, firmware, service daemons, and other components can be ported to work with Firefox OS, usually with minimal effort. If a custom component (for example, a custom RIL or new daemon) is needed, or if a modification must be made to an ODM’s reference design, then additional integration and testing effort might be required.
In b2g, clients communicate with service-level daemons via inter-process communication (IPC). The client initiates a socket connection to the service-level daemon, submits the request (using the server’s request protocol) over that connection, receives the response, and closes the connection. OEMs are responsible for designing and implementing this inter-process communication between clients and servers.
Note: For more information about how the porting process works, see Porting Firefox OS.
Every Gonk implementation is the result of collaboration among Mozilla, OEMs, and associated manufacturers (ODMs, chipset manufacturers).
Mozilla provides source repositories and support files for Gonk in its Firefox OS distributions. The source repositories include the base Linux kernel (with only slight changes) and hooks into Gecko.
OEMs are responsible for building, compiling, testing, certifying, and distributing the Firefox OS system image for a given device model. For the Gonk portion of the system image, OEMs are responsible for the bulk of the effort in order to ensure the seamless integration between Web API calls and phone hardware functionality. The type and scope of effort required is highly dependent on the specific chipsets and other hardware components used on the phone.
OEMs collaborate with chipset manufacturers and ODMs to provide all of the device-specific components that are needed to run the mobile device. For example, a manufacturer of the Wi-Fi components would provide the chipset and affiliated software. Components might include:
- Drivers — For supported phone functionality, such as modem (data and voice), Wi-fi, Bluetooth, display, camera, audio, and so on.
- Firmware — Some hardware (the network interface card, for example) might load firmware off the flash drive.
- Service-level daemons — For invoking and managing the operation of various hardware components. This can include support libraries and startup scripts.
OEMs must ensure that hardware capabilities in the mobile device are correctly and completely exposed to the Web APIs implemented in Gecko. This involves:
- building or adapting (in Gonk) service-level daemons, along with any associated drivers or firmware, to manage the hardware functionality
- setting up (in b2g) all the methods needed to communicate with the service-level daemons
The main B2G repo on Github contains officially supported Gonk ports for a variety of devices, so you can treat it as Gonk’s repository. The list of supported devices is available in
The b2g process (along with other things), defined in Gonk, can be found at mozilla-b2g/gonk-misc. Modifications to b2g source code are made here.
Note: In the Gecko source there’s a
b2g/ folder that contains the Gonk Port of Gecko: this consists of a Linux kernel, HAL, and other OEM-specific libraries.
Gonk 层每天的工作主要集中在 porting system 到不同的板子上，并且确保 Gecko 在不同的设备上能够正常工作。