building.rst 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ===================================
  3. Building support for a media device
  4. ===================================
  5. The first step is to download the Kernel's source code, either via a
  6. distribution-specific source file or via the Kernel's main git tree\ [1]_.
  7. Please notice, however, that, if:
  8. - you're a braveheart and want to experiment with new stuff;
  9. - if you want to report a bug;
  10. - if you're developing new patches
  11. you should use the main media development tree ``master`` branch:
  12. https://git.linuxtv.org/media.git/
  13. In this case, you may find some useful information at the
  14. `LinuxTv wiki pages <https://linuxtv.org/wiki>`_:
  15. https://linuxtv.org/wiki/index.php/How_to_Obtain,_Build_and_Install_V4L-DVB_Device_Drivers
  16. .. [1] The upstream Linux Kernel development tree is located at
  17. https://git.kernel.org/pub/scm/li nux/kernel/git/torvalds/linux.git/
  18. Configuring the Linux Kernel
  19. ============================
  20. You can access a menu of Kernel building options with::
  21. $ make menuconfig
  22. Then, select all desired options and exit it, saving the configuration.
  23. The changed configuration will be at the ``.config`` file. It would
  24. look like::
  25. ...
  26. # CONFIG_RC_CORE is not set
  27. # CONFIG_CEC_CORE is not set
  28. CONFIG_MEDIA_SUPPORT=m
  29. CONFIG_MEDIA_SUPPORT_FILTER=y
  30. ...
  31. The media subsystem is controlled by those menu configuration options::
  32. Device Drivers --->
  33. <M> Remote Controller support --->
  34. [ ] HDMI CEC RC integration
  35. [ ] Enable CEC error injection support
  36. [*] HDMI CEC drivers --->
  37. <*> Multimedia support --->
  38. The ``Remote Controller support`` option enables the core support for
  39. remote controllers\ [2]_.
  40. The ``HDMI CEC RC integration`` option enables integration of HDMI CEC
  41. with Linux, allowing to receive data via HDMI CEC as if it were produced
  42. by a remote controller directly connected to the machine.
  43. The ``HDMI CEC drivers`` option allow selecting platform and USB drivers
  44. that receives and/or transmits CEC codes via HDMI interfaces\ [3]_.
  45. The last option (``Multimedia support``) enables support for cameras,
  46. audio/video grabbers and TV.
  47. The media subsystem support can either be built together with the main
  48. Kernel or as a module. For most use cases, it is preferred to have it
  49. built as modules.
  50. .. note::
  51. Instead of using a menu, the Kernel provides a script with allows
  52. enabling configuration options directly. To enable media support
  53. and remote controller support using Kernel modules, you could use::
  54. $ scripts/config -m RC_CORE
  55. $ scripts/config -m MEDIA_SUPPORT
  56. .. [2] ``Remote Controller support`` should also be enabled if you
  57. want to use some TV card drivers that may depend on the remote
  58. controller core support.
  59. .. [3] Please notice that the DRM subsystem also have drivers for GPUs
  60. that use the media HDMI CEC support.
  61. Those GPU-specific drivers are selected via the ``Graphics support``
  62. menu, under ``Device Drivers``.
  63. When a GPU driver supports HDMI CEC, it will automatically
  64. enable the CEC core support at the media subsystem.
  65. Media dependencies
  66. ------------------
  67. It should be noticed that enabling the above from a clean config is
  68. usually not enough. The media subsystem depends on several other Linux
  69. core support in order to work.
  70. For example, most media devices use a serial communication bus in
  71. order to talk with some peripherals. Such bus is called I²C
  72. (Inter-Integrated Circuit). In order to be able to build support
  73. for such hardware, the I²C bus support should be enabled, either via
  74. menu or with::
  75. ./scripts/config -m I2C
  76. Another example: the remote controller core requires support for
  77. input devices, with can be enabled with::
  78. ./scripts/config -m INPUT
  79. Other core functionality may also be needed (like PCI and/or USB support),
  80. depending on the specific driver(s) you would like to enable.
  81. Enabling Remote Controller Support
  82. ----------------------------------
  83. The remote controller menu allows selecting drivers for specific devices.
  84. It's menu looks like this::
  85. --- Remote Controller support
  86. <M> Compile Remote Controller keymap modules
  87. [*] LIRC user interface
  88. [*] Support for eBPF programs attached to lirc devices
  89. [*] Remote controller decoders --->
  90. [*] Remote Controller devices --->
  91. The ``Compile Remote Controller keymap modules`` option creates key maps for
  92. several popular remote controllers.
  93. The ``LIRC user interface`` option adds enhanced functionality when using the
  94. ``lirc`` program, by enabling an API that allows userspace to receive raw data
  95. from remote controllers.
  96. The ``Support for eBPF programs attached to lirc devices`` option allows
  97. the usage of special programs (called eBPF) that would allow applications
  98. to add extra remote controller decoding functionality to the Linux Kernel.
  99. The ``Remote controller decoders`` option allows selecting the
  100. protocols that will be recognized by the Linux Kernel. Except if you
  101. want to disable some specific decoder, it is suggested to keep all
  102. sub-options enabled.
  103. The ``Remote Controller devices`` allows you to select the drivers
  104. that would be needed to support your device.
  105. The same configuration can also be set via the ``script/config``
  106. script. So, for instance, in order to support the ITE remote controller
  107. driver (found on Intel NUCs and on some ASUS x86 desktops), you could do::
  108. $ scripts/config -e INPUT
  109. $ scripts/config -e ACPI
  110. $ scripts/config -e MODULES
  111. $ scripts/config -m RC_CORE
  112. $ scripts/config -e RC_DEVICES
  113. $ scripts/config -e RC_DECODERS
  114. $ scripts/config -m IR_RC5_DECODER
  115. $ scripts/config -m IR_ITE_CIR
  116. Enabling HDMI CEC Support
  117. -------------------------
  118. The HDMI CEC support is set automatically when a driver requires it. So,
  119. all you need to do is to enable support either for a graphics card
  120. that needs it or by one of the existing HDMI drivers.
  121. The HDMI-specific drivers are available at the ``HDMI CEC drivers``
  122. menu\ [4]_::
  123. --- HDMI CEC drivers
  124. < > ChromeOS EC CEC driver
  125. < > Amlogic Meson AO CEC driver
  126. < > Amlogic Meson G12A AO CEC driver
  127. < > Generic GPIO-based CEC driver
  128. < > Samsung S5P CEC driver
  129. < > STMicroelectronics STiH4xx HDMI CEC driver
  130. < > STMicroelectronics STM32 HDMI CEC driver
  131. < > Tegra HDMI CEC driver
  132. < > SECO Boards HDMI CEC driver
  133. [ ] SECO Boards IR RC5 support
  134. < > Pulse Eight HDMI CEC
  135. < > RainShadow Tech HDMI CEC
  136. .. [4] The above contents is just an example. The actual options for
  137. HDMI devices depends on the system's architecture and may vary
  138. on new Kernels.
  139. Enabling Media Support
  140. ----------------------
  141. The Media menu has a lot more options than the remote controller menu.
  142. Once selected, you should see the following options::
  143. --- Media support
  144. [ ] Filter media drivers
  145. [*] Autoselect ancillary drivers
  146. Media device types --->
  147. Media core support --->
  148. Video4Linux options --->
  149. Media controller options --->
  150. Digital TV options --->
  151. HDMI CEC options --->
  152. Media drivers --->
  153. Media ancillary drivers --->
  154. Except if you know exactly what you're doing, or if you want to build
  155. a driver for a SoC platform, it is strongly recommended to keep the
  156. ``Autoselect ancillary drivers`` option turned on, as it will auto-select
  157. the needed I²C ancillary drivers.
  158. There are now two ways to select media device drivers, as described
  159. below.
  160. ``Filter media drivers`` menu
  161. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  162. This menu is meant to easy setup for PC and Laptop hardware. It works
  163. by letting the user to specify what kind of media drivers are desired,
  164. with those options::
  165. [ ] Cameras and video grabbers
  166. [ ] Analog TV
  167. [ ] Digital TV
  168. [ ] AM/FM radio receivers/transmitters
  169. [ ] Software defined radio
  170. [ ] Platform-specific devices
  171. [ ] Test drivers
  172. So, if you want to add support to a camera or video grabber only,
  173. select just the first option. Multiple options are allowed.
  174. Once the options on this menu are selected, the building system will
  175. auto-select the needed core drivers in order to support the selected
  176. functionality.
  177. .. note::
  178. Most TV cards are hybrid: they support both Analog TV and Digital TV.
  179. If you have an hybrid card, you may need to enable both ``Analog TV``
  180. and ``Digital TV`` at the menu.
  181. When using this option, the defaults for the media support core
  182. functionality are usually good enough to provide the basic functionality
  183. for the driver. Yet, you could manually enable some desired extra (optional)
  184. functionality using the settings under each of the following
  185. ``Media support`` sub-menus::
  186. Media core support --->
  187. Video4Linux options --->
  188. Media controller options --->
  189. Digital TV options --->
  190. HDMI CEC options --->
  191. Once you select the desired filters, the drivers that matches the filtering
  192. criteria will be available at the ``Media support->Media drivers`` sub-menu.
  193. ``Media Core Support`` menu without filtering
  194. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  195. If you disable the ``Filter media drivers`` menu, all drivers available
  196. for your system whose dependencies are met should be shown at the
  197. ``Media drivers`` menu.
  198. Please notice, however, that you should first ensure that the
  199. ``Media Core Support`` menu has all the core functionality your drivers
  200. would need, as otherwise the corresponding device drivers won't be shown.
  201. Example
  202. -------
  203. In order to enable modular support for one of the boards listed on
  204. :doc:`this table <cx231xx-cardlist>`, with modular media core modules, the
  205. ``.config`` file should contain those lines::
  206. CONFIG_MODULES=y
  207. CONFIG_USB=y
  208. CONFIG_I2C=y
  209. CONFIG_INPUT=y
  210. CONFIG_RC_CORE=m
  211. CONFIG_MEDIA_SUPPORT=m
  212. CONFIG_MEDIA_SUPPORT_FILTER=y
  213. CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  214. CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  215. CONFIG_MEDIA_USB_SUPPORT=y
  216. CONFIG_VIDEO_CX231XX=y
  217. CONFIG_VIDEO_CX231XX_DVB=y
  218. Building and installing a new Kernel
  219. ====================================
  220. Once the ``.config`` file has everything needed, all it takes to build
  221. is to run the ``make`` command::
  222. $ make
  223. And then install the new Kernel and its modules::
  224. $ sudo make modules_install
  225. $ sudo make install
  226. Building just the new media drivers and core
  227. ============================================
  228. Running a new development Kernel from the development tree is usually risky,
  229. because it may have experimental changes that may have bugs. So, there are
  230. some ways to build just the new drivers, using alternative trees.
  231. There is the `Linux Kernel backports project
  232. <https://backports.wiki.kernel.org/index.php/Main_Page>`_, with contains
  233. newer drivers meant to be compiled against stable Kernels.
  234. The LinuxTV developers, with are responsible for maintaining the media
  235. subsystem also maintains a backport tree, with just the media drivers
  236. daily updated from the newest kernel. Such tree is available at:
  237. https://git.linuxtv.org/media_build.git/
  238. It should be noticed that, while it should be relatively safe to use the
  239. ``media_build`` tree for testing purposes, there are not warranties that
  240. it would work (or even build) on a random Kernel. This tree is maintained
  241. using a "best-efforts" principle, as time permits us to fix issues there.
  242. If you notice anything wrong on it, feel free to submit patches at the
  243. Linux media subsystem's mailing list: media@vger.kernel.org. Please
  244. add ``[PATCH media-build]`` at the e-mail's subject if you submit a new
  245. patch for the media-build.
  246. Before using it, you should run::
  247. $ ./build
  248. .. note::
  249. 1) you may need to run it twice if the ``media-build`` tree gets
  250. updated;
  251. 2) you may need to do a ``make distclean`` if you had built it
  252. in the past for a different Kernel version than the one you're
  253. currently using;
  254. 3) by default, it will use the same config options for media as
  255. the ones defined on the Kernel you're running.
  256. In order to select different drivers or different config options,
  257. use::
  258. $ make menuconfig
  259. Then, you can build and install the new drivers::
  260. $ make && sudo make install
  261. This will override the previous media drivers that your Kernel were
  262. using.