build.tex 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. One of the biggest challenges to getting started with embedded devices is that you
  2. cannot just install a copy of Linux and expect to be able to compile a firmware.
  3. Even if you did remember to install a compiler and every development tool offered,
  4. you still would not have the basic set of tools needed to produce a firmware image.
  5. The embedded device represents an entirely new hardware platform, which is
  6. most of the time incompatible with the hardware on your development machine, so in a process called
  7. cross compiling you need to produce a new compiler capable of generating code for
  8. your embedded platform, and then use it to compile a basic Linux distribution to
  9. run on your device.
  10. The process of creating a cross compiler can be tricky, it is not something that is
  11. regularly attempted and so there is a certain amount of mystery and black magic
  12. associated with it. In many cases when you are dealing with embedded devices you will
  13. be provided with a binary copy of a compiler and basic libraries rather than
  14. instructions for creating your own -- it is a time saving step but at the same time
  15. often means you will be using a rather dated set of tools. Likewise, it is also common
  16. to be provided with a patched copy of the Linux kernel from the board or chip vendor,
  17. but this is also dated and it can be difficult to spot exactly what has been
  18. modified to make the kernel run on the embedded platform.
  19. \subsection{Building an image}
  20. OpenWrt takes a different approach to building a firmware; downloading, patching
  21. and compiling everything from scratch, including the cross compiler. To put it
  22. in simpler terms, OpenWrt does not contain any executables or even sources, it is an
  23. automated system for downloading the sources, patching them to work with the given
  24. platform and compiling them correctly for that platform. What this means is that
  25. just by changing the template, you can change any step in the process.
  26. As an example, if a new kernel is released, a simple change to one of the Makefiles
  27. will download the latest kernel, patch it to run on the embedded platform and produce
  28. a new firmware image -- there is no work to be done trying to track down an unmodified
  29. copy of the existing kernel to see what changes had been made, the patches are
  30. already provided and the process ends up almost completely transparent. This does not
  31. just apply to the kernel, but to anything included with OpenWrt -- It is this one
  32. simple understated concept which is what allows OpenWrt to stay on the bleeding edge
  33. with the latest compilers, latest kernels and latest applications.
  34. So let's take a look at OpenWrt and see how this all works.
  35. \subsubsection{Download OpenWrt}
  36. OpenWrt can be downloaded via subversion using the following command:
  37. \begin{Verbatim}
  38. $ svn checkout svn://svn.openwrt.org/openwrt/trunk openwrt-trunk
  39. \end{Verbatim}
  40. Additionally, there is a trac interface on \href{https://dev.openwrt.org/}{https://dev.openwrt.org/}
  41. which can be used to monitor svn commits and browse the source repository.
  42. \subsubsection{The directory structure}
  43. There are four key directories in the base:
  44. \begin{itemize}
  45. \item \texttt{tools}
  46. \item \texttt{toolchain}
  47. \item \texttt{package}
  48. \item \texttt{target}
  49. \end{itemize}
  50. \texttt{tools} and \texttt{toolchain} refer to common tools which will be
  51. used to build the firmware image, the compiler, and the C library.
  52. The result of this is three new directories, \texttt{build\_dir/host}, which is a temporary
  53. directory for building the target independent tools, \texttt{build\_dir/toolchain-\textit{<arch>}*}
  54. which is used for building the toolchain for a specific architecture, and
  55. \texttt{staging\_dir/toolchain-\textit{<arch>}*} where the resulting toolchain is installed.
  56. You will not need to do anything with the toolchain directory unless you intend to
  57. add a new version of one of the components above.
  58. \begin{itemize}
  59. \item \texttt{build\_dir/host}
  60. \item \texttt{build\_dir/toolchain-\textit{<arch>}*}
  61. \end{itemize}
  62. \texttt{package} is for exactly that -- packages. In an OpenWrt firmware, almost everything
  63. is an \texttt{.ipk}, a software package which can be added to the firmware to provide new
  64. features or removed to save space. Note that packages are also maintained outside of the main
  65. trunk and can be obtained from subversion using the package feeds system:
  66. \begin{Verbatim}
  67. $ ./scripts/feeds update
  68. \end{Verbatim}
  69. Those packages can be used to extend the functionality of the build system and need to be
  70. symlinked into the main trunk. Once you do that, the packages will show up in the menu for
  71. configuration. You would do something like this:
  72. \begin{Verbatim}
  73. $ ./scripts/feeds search nmap
  74. Search results in feed 'packages':
  75. nmap Network exploration and/or security auditing utility
  76. $ ./scripts/feeds install nmap
  77. \end{Verbatim}
  78. To include all packages, issue the following command:
  79. \begin{Verbatim}
  80. $ make package/symlinks
  81. \end{Verbatim}
  82. \texttt{target} refers to the embedded platform, this contains items which are specific to
  83. a specific embedded platform. Of particular interest here is the "\texttt{target/linux}"
  84. directory which is broken down by platform \textit{<arch>} and contains the patches to the
  85. kernel, profile config, for a particular platform. There's also the "\texttt{target/image}" directory
  86. which describes how to package a firmware for a specific platform.
  87. Both the target and package steps will use the directory "\texttt{build\_dir/\textit{<arch>}}"
  88. as a temporary directory for compiling. Additionally, anything downloaded by the toolchain,
  89. target or package steps will be placed in the "\texttt{dl}" directory.
  90. \begin{itemize}
  91. \item \texttt{build\_dir/\textit{<arch>}}
  92. \item \texttt{dl}
  93. \end{itemize}
  94. \subsubsection{Building OpenWrt}
  95. While the OpenWrt build environment was intended mostly for developers, it also has to be
  96. simple enough that an inexperienced end user can easily build his or her own customized firmware.
  97. Running the command "\texttt{make menuconfig}" will bring up OpenWrt's configuration menu
  98. screen, through this menu you can select which platform you're targeting, which versions of
  99. the toolchain you want to use to build and what packages you want to install into the
  100. firmware image. Note that it will also check to make sure you have the basic dependencies for it
  101. to run correctly. If that fails, you will need to install some more tools in your local environment
  102. before you can begin.
  103. Similar to the linux kernel config, almost every option has three choices,
  104. \texttt{y/m/n} which are represented as follows:
  105. \begin{itemize}
  106. \item{\texttt{<*>} (pressing y)} \\
  107. This will be included in the firmware image
  108. \item{\texttt{<M>} (pressing m)} \\
  109. This will be compiled but not included (for later install)
  110. \item{\texttt{< >} (pressing n)} \\
  111. This will not be compiled
  112. \end{itemize}
  113. After you've finished with the menu configuration, exit and when prompted, save your
  114. configuration changes.
  115. If you want, you can also modify the kernel config for the selected target system.
  116. simply run "\texttt{make kernel\_menuconfig}" and the build system will unpack the kernel sources
  117. (if necessary), run menuconfig inside of the kernel tree, and then copy the kernel config
  118. to \texttt{target/linux/\textit{<platform>}/config} so that it is preserved over
  119. "\texttt{make clean}" calls.
  120. To begin compiling the firmware, type "\texttt{make}". By default
  121. OpenWrt will only display a high level overview of the compile process and not each individual
  122. command.
  123. \subsubsection{Example:}
  124. \begin{Verbatim}
  125. make[2] toolchain/install
  126. make[3] -C toolchain install
  127. make[2] target/compile
  128. make[3] -C target compile
  129. make[4] -C target/utils prepare
  130. [...]
  131. \end{Verbatim}
  132. This makes it easier to monitor which step it's actually compiling and reduces the amount
  133. of noise caused by the compile output. To see the full output, run the command
  134. "\texttt{make V=99}".
  135. During the build process, buildroot will download all sources to the "\texttt{dl}"
  136. directory and will start patching and compiling them in the "\texttt{build\_dir/\textit{<arch>}}"
  137. directory. When finished, the resulting firmware will be in the "\texttt{bin}" directory
  138. and packages will be in the "\texttt{bin/packages}" directory.
  139. \subsection{Creating packages}
  140. One of the things that we've attempted to do with OpenWrt's template system is make it
  141. incredibly easy to port software to OpenWrt. If you look at a typical package directory
  142. in OpenWrt you'll find several things:
  143. \begin{itemize}
  144. \item \texttt{package/\textit{<name>}/Makefile}
  145. \item \texttt{package/\textit{<name>}/patches}
  146. \item \texttt{package/\textit{<name>}/files}
  147. \end{itemize}
  148. The patches directory is optional and typically contains bug fixes or optimizations to
  149. reduce the size of the executable. The package makefile is the important item, provides
  150. the steps actually needed to download and compile the package.
  151. The files directory is also optional and typicall contains package specific startup scripts or default configuration files that can be used out of the box with OpenWrt.
  152. Looking at one of the package makefiles, you'd hardly recognize it as a makefile.
  153. Through what can only be described as blatant disregard and abuse of the traditional
  154. make format, the makefile has been transformed into an object oriented template which
  155. simplifies the entire ordeal.
  156. Here for example, is \texttt{package/bridge/Makefile}:
  157. \begin{Verbatim}[frame=single,numbers=left]
  158. include $(TOPDIR)/rules.mk
  159. PKG_NAME:=bridge
  160. PKG_VERSION:=1.0.6
  161. PKG_RELEASE:=1
  162. PKG_SOURCE:=bridge-utils-$(PKG_VERSION).tar.gz
  163. PKG_SOURCE_URL:=@SF/bridge
  164. PKG_MD5SUM:=9b7dc52656f5cbec846a7ba3299f73bd
  165. PKG_CAT:=zcat
  166. PKG_BUILD_DIR:=$(BUILD_DIR)/bridge-utils-$(PKG_VERSION)
  167. include $(INCLUDE_DIR)/package.mk
  168. define Package/bridge
  169. SECTION:=net
  170. CATEGORY:=Base system
  171. TITLE:=Ethernet bridging configuration utility
  172. URL:=http://bridge.sourceforge.net/
  173. endef
  174. define Package/bridge/description
  175. Manage ethernet bridging:
  176. a way to connect networks together to form a larger network.
  177. endef
  178. define Build/Configure
  179. $(call Build/Configure/Default, \
  180. --with-linux-headers="$(LINUX_DIR)" \
  181. )
  182. endef
  183. define Package/bridge/install
  184. $(INSTALL_DIR) $(1)/usr/sbin
  185. $(INSTALL_BIN) $(PKG_BUILD_DIR)/brctl/brctl $(1)/usr/sbin/
  186. endef
  187. $(eval $(call BuildPackage,bridge))
  188. \end{Verbatim}
  189. As you can see, there's not much work to be done; everything is hidden in other makefiles
  190. and abstracted to the point where you only need to specify a few variables.
  191. \begin{itemize}
  192. \item \texttt{PKG\_NAME} \\
  193. The name of the package, as seen via menuconfig and ipkg
  194. \item \texttt{PKG\_VERSION} \\
  195. The upstream version number that we are downloading
  196. \item \texttt{PKG\_RELEASE} \\
  197. The version of this package Makefile
  198. \item \texttt{PKG\_SOURCE} \\
  199. The filename of the original sources
  200. \item \texttt{PKG\_SOURCE\_URL} \\
  201. Where to download the sources from (no trailing slash), you can add multiple download sources by separating them with a \textbackslash{} and a carriage return.
  202. \item \texttt{PKG\_MD5SUM} \\
  203. A checksum to validate the download
  204. \item \texttt{PKG\_CAT} \\
  205. How to decompress the sources (zcat, bzcat, unzip)
  206. \item \texttt{PKG\_BUILD\_DIR} \\
  207. Where to compile the package
  208. \end{itemize}
  209. The \texttt{PKG\_*} variables define where to download the package from;
  210. \texttt{@SF} is a special keyword for downloading packages from sourceforge. There is also
  211. another keyword of \texttt{@GNU} for grabbing GNU source releases. If any of the above mentioned download source fails, the OpenWrt mirrors will be used as source.
  212. The md5sum (if present) is used to verify the package was downloaded correctly and
  213. \texttt{PKG\_BUILD\_DIR} defines where to find the package after the sources are
  214. uncompressed into \texttt{\$(BUILD\_DIR)}.
  215. At the bottom of the file is where the real magic happens, "BuildPackage" is a macro
  216. set up by the earlier include statements. BuildPackage only takes one argument directly --
  217. the name of the package to be built, in this case "\texttt{bridge}". All other information
  218. is taken from the define blocks. This is a way of providing a level of verbosity, it's
  219. inherently clear what the contents of the \texttt{description} template in
  220. \texttt{Package/bridge} is, which wouldn't be the case if we passed this information
  221. directly as the Nth argument to \texttt{BuildPackage}.
  222. \texttt{BuildPackage} uses the following defines:
  223. \textbf{\texttt{Package/\textit{<name>}}:} \\
  224. \texttt{\textit{<name>}} matches the argument passed to buildroot, this describes
  225. the package the menuconfig and ipkg entries. Within \texttt{Package/\textit{<name>}}
  226. you can define the following variables:
  227. \begin{itemize}
  228. \item \texttt{SECTION} \\
  229. The section of package (currently unused)
  230. \item \texttt{CATEGORY} \\
  231. Which menu it appears in menuconfig: Network, Sound, Utilities, Multimedia ...
  232. \item \texttt{TITLE} \\
  233. A short description of the package
  234. \item \texttt{URL} \\
  235. Where to find the original software
  236. \item \texttt{MAINTAINER} (optional) \\
  237. Who to contact concerning the package
  238. \item \texttt{DEPENDS} (optional) \\
  239. Which packages must be built/installed before this package. To reference a dependency defined in the
  240. same Makefile, use \textit{<dependency name>}. If defined as an external package, use
  241. \textit{+<dependency name>}. For a kernel version dependency use: \textit{@LINUX\_2\_<minor version>}
  242. \item \texttt{BUILDONLY} (optional) \\
  243. Set this option to 1 if you do NOT want your package to appear in menuconfig.
  244. This is useful for packages which are only used as build dependencies.
  245. \end{itemize}
  246. \textbf{\texttt{Package/\textit{<name>}/conffiles} (optional):} \\
  247. A list of config files installed by this package, one file per line.
  248. \textbf{\texttt{Build/Prepare} (optional):} \\
  249. A set of commands to unpack and patch the sources. You may safely leave this
  250. undefined.
  251. \textbf{\texttt{Build/Configure} (optional):} \\
  252. You can leave this undefined if the source doesn't use configure or has a
  253. normal config script, otherwise you can put your own commands here or use
  254. "\texttt{\$(call Build/Configure/Default,\textit{<first list of arguments, second list>})}" as above to
  255. pass in additional arguments for a standard configure script. The first list of arguments will be passed
  256. to the configure script like that: \texttt{--arg 1} \texttt{--arg 2}. The second list contains arguments that should be
  257. defined before running the configure script such as autoconf or compiler specific variables.
  258. To make it easier to modify the configure command line, you can either extend or completely override the following variables:
  259. \begin{itemize}
  260. \item \texttt{CONFIGURE\_ARGS} \\
  261. Contains all command line arguments (format: \texttt{--arg 1} \texttt{--arg 2})
  262. \item \texttt{CONFIGURE\_VARS} \\
  263. Contains all environment variables that are passed to ./configure (format: \texttt{NAME="value"})
  264. \end{itemize}
  265. \textbf{\texttt{Build/Compile} (optional):} \\
  266. How to compile the source; in most cases you should leave this undefined.
  267. As with \texttt{Build/Configure} there are two variables that allow you to override
  268. the make command line environment variables and flags:
  269. \begin{itemize}
  270. \item \texttt{MAKE\_FLAGS} \\
  271. Contains all command line arguments (typically variable overrides like \texttt{NAME="value"}
  272. \item \texttt{MAKE\_VARS} \\
  273. Contains all environment variables that are passed to the make command
  274. \end{itemize}
  275. \textbf{\texttt{Build/InstallDev} (optional):} \\
  276. If your package provides a library that needs to be made available to other packages,
  277. you can use the \texttt{Build/InstallDev} template to copy it into the staging directory
  278. which is used to collect all files that other packages might depend on at build time.
  279. When it is called by the build system, two parameters are passed to it. \texttt{\$(1)} points to
  280. the regular staging dir, typically \texttt{staging\_dir/\textit{ARCH}}, while \texttt{\$(2)} points
  281. to \texttt{staging\_dir/host}. The host staging dir is only used for binaries, which are
  282. to be executed or linked against on the host and its \texttt{bin/} subdirectory is included
  283. in the \texttt{PATH} which is passed down to the build system processes.
  284. Please use \texttt{\$(1)} and \texttt{\$(2)} here instead of the build system variables
  285. \texttt{\$(STAGING\_DIR)} and \texttt{\$(STAGING\_DIR\_HOST)}, because the build system behavior
  286. when staging libraries might change in the future to include automatic uninstallation.
  287. \textbf{\texttt{Package/\textit{<name>}/install}:} \\
  288. A set of commands to copy files out of the compiled source and into the ipkg
  289. which is represented by the \texttt{\$(1)} directory. Note that there are currently
  290. 4 defined install macros:
  291. \begin{itemize}
  292. \item \texttt{INSTALL\_DIR} \\
  293. install -d -m0755
  294. \item \texttt{INSTALL\_BIN} \\
  295. install -m0755
  296. \item \texttt{INSTALL\_DATA} \\
  297. install -m0644
  298. \item \texttt{INSTALL\_CONF} \\
  299. install -m0600
  300. \end{itemize}
  301. The reason that some of the defines are prefixed by "\texttt{Package/\textit{<name>}}"
  302. and others are simply "\texttt{Build}" is because of the possibility of generating
  303. multiple packages from a single source. OpenWrt works under the assumption of one
  304. source per package Makefile, but you can split that source into as many packages as
  305. desired. Since you only need to compile the sources once, there's one global set of
  306. "\texttt{Build}" defines, but you can add as many "Package/<name>" defines as you want
  307. by adding extra calls to \texttt{BuildPackage} -- see the dropbear package for an example.
  308. After you have created your \texttt{package/\textit{<name>}/Makefile}, the new package
  309. will automatically show in the menu the next time you run "make menuconfig" and if selected
  310. will be built automatically the next time "\texttt{make}" is run.
  311. \subsection{Creating binary packages}
  312. You might want to create binary packages and include them in the resulting images as packages.
  313. To do so, you can use the following template, which basically sets to nothing the Configure and
  314. Compile templates.
  315. \begin{Verbatim}[frame=single,numbers=left]
  316. include $(TOPDIR)/rules.mk
  317. PKG_NAME:=binpkg
  318. PKG_VERSION:=1.0
  319. PKG_RELEASE:=1
  320. PKG_SOURCE:=binpkg-$(PKG_VERSION).tar.gz
  321. PKG_SOURCE_URL:=http://server
  322. PKG_MD5SUM:=9b7dc52656f5cbec846a7ba3299f73bd
  323. PKG_CAT:=zcat
  324. include $(INCLUDE_DIR)/package.mk
  325. define Package/binpkg
  326. SECTION:=net
  327. CATEGORY:=Network
  328. TITLE:=Binary package
  329. endef
  330. define Package/bridge/description
  331. Binary package
  332. endef
  333. define Build/Configure
  334. endef
  335. define Build/Compile
  336. endef
  337. define Package/bridge/install
  338. $(INSTALL_DIR) $(1)/usr/sbin
  339. $(INSTALL_BIN) $(PKG_BUILD_DIR)/* $(1)/usr/sbin/
  340. endef
  341. $(eval $(call BuildPackage,bridge))
  342. \end{Verbatim}
  343. Provided that the tarball which contains the binaries reflects the final
  344. directory layout (/usr, /lib ...), it becomes very easy to get your package
  345. look like one build from sources.
  346. Note that using the same technique, you can easily create binary pcakages
  347. for your proprietary kernel modules as well.
  348. \subsection{Creating kernel modules packages}
  349. The OpenWrt distribution makes the distinction between two kind of kernel modules, those coming along with the mainline kernel, and the others available as a separate project. We will see later that a common template is used for both of them.
  350. For kernel modules that are part of the mainline kernel source, the makefiles are located in \textit{package/kernel/modules/*.mk} and they appear under the section "Kernel modules"
  351. For external kernel modules, you can add them to the build system just like if they were software packages by defining a KernelPackage section in the package makefile.
  352. Here for instance the Makefile for the I2C subsytem kernel modules :
  353. \begin{Verbatim}[frame=single,numbers=left]
  354. I2CMENU:=I2C Bus
  355. define KernelPackage/i2c-core
  356. TITLE:=I2C support
  357. DESCRIPTION:=Kernel modules for i2c support
  358. SUBMENU:=$(I2CMENU)
  359. KCONFIG:=CONFIG_I2C_CORE CONFIG_I2C_DEV
  360. FILES:=$(MODULES_DIR)/kernel/drivers/i2c/*.$(LINUX_KMOD_SUFFIX)
  361. AUTOLOAD:=$(call AutoLoad,50,i2c-core i2c-dev)
  362. endef
  363. $(eval $(call KernelPackage,i2c-core))
  364. \end{Verbatim}
  365. To group kernel modules under a common description in menuconfig, you might want to define a \textit{<description>MENU} variable on top of the kernel modules makefile.
  366. \begin{itemize}
  367. \item \texttt{TITLE} \\
  368. The name of the module as seen via menuconfig
  369. \item \texttt{DESCRIPTION} \\
  370. The description as seen via help in menuconfig
  371. \item \texttt{SUBMENU} \\
  372. The sub menu under which this package will be seen
  373. \item \texttt{KCONFIG} \\
  374. Kernel configuration option dependency. For external modules, remove it.
  375. \item \texttt{FILES} \\
  376. Files you want to inlude to this kernel module package, separate with spaces.
  377. \item \texttt{AUTOLOAD} \\
  378. Modules that will be loaded automatically on boot, the order you write them is the order they would be loaded.
  379. \end{itemize}
  380. After you have created your \texttt{package/kernel/modules/\textit{<name>}.mk}, the new kernel modules package
  381. will automatically show in the menu under "Kernel modules" next time you run "make menuconfig" and if selected
  382. will be built automatically the next time "\texttt{make}" is run.
  383. \subsection{Conventions}
  384. There are a couple conventions to follow regarding packages:
  385. \begin{itemize}
  386. \item \texttt{files}
  387. \begin{enumerate}
  388. \item configuration files follow the convention \\
  389. \texttt{\textit{<name>}.conf}
  390. \item init files follow the convention \\
  391. \texttt{\textit{<name>}.init}
  392. \end{enumerate}
  393. \item \texttt{patches}
  394. \begin{enumerate}
  395. \item patches are numerically prefixed and named related to what they do
  396. \end{enumerate}
  397. \end{itemize}
  398. \subsection{Troubleshooting}
  399. If you find your package doesn't show up in menuconfig, try the following command to
  400. see if you get the correct description:
  401. \begin{Verbatim}
  402. TOPDIR=$PWD make -C package/<name> DUMP=1 V=99
  403. \end{Verbatim}
  404. If you're just having trouble getting your package to compile, there's a few
  405. shortcuts you can take. Instead of waiting for make to get to your package, you can
  406. run one of the following:
  407. \begin{itemize}
  408. \item \texttt{make package/\textit{<name>}/clean V=99}
  409. \item \texttt{make package/\textit{<name>}/install V=99}
  410. \end{itemize}
  411. Another nice trick is that if the source directory under \texttt{build\_dir/\textit{<arch>}}
  412. is newer than the package directory, it won't clobber it by unpacking the sources again.
  413. If you were working on a patch you could simply edit the sources under the
  414. \texttt{build\_dir/\textit{<arch>}/\textit{<source>}} directory and run the install command above,
  415. when satisfied, copy the patched sources elsewhere and diff them with the unpatched
  416. sources. A warning though - if you go modify anything under \texttt{package/\textit{<name>}}
  417. it will remove the old sources and unpack a fresh copy.
  418. Other useful targets include:
  419. \begin{itemize}
  420. \item \texttt{make package/\textit{<name>}/prepare V=99}
  421. \item \texttt{make package/\textit{<name>}/compile V=99}
  422. \item \texttt{make package/\textit{<name>}/configure V=99}
  423. \end{itemize}
  424. \subsection{Using build environments}
  425. OpenWrt provides a means of building images for multiple configurations
  426. which can use multiple targets in one single checkout. These \emph{environments}
  427. store a copy of the .config file generated by \texttt{make menuconfig} and the contents
  428. of the \texttt{./files} folder.
  429. The script \texttt{./scripts/env} is used to manage these environments, it uses
  430. \texttt{git} (which needs to be installed on your system) as backend for version control.
  431. The command
  432. \begin{Verbatim}
  433. ./scripts/env help
  434. \end{Verbatim}
  435. produces a short help text with a list of commands.
  436. To create a new environment named \texttt{current}, run the following command
  437. \begin{Verbatim}
  438. ./scripts/env new current
  439. \end{Verbatim}
  440. This will move your \texttt{.config} file and \texttt{./files} (if it exists) to
  441. the \texttt{env/} subdirectory and create symlinks in the base folder.
  442. After running make menuconfig or changing things in files/, your current state will
  443. differ from what has been saved before. To show these changes, use:
  444. \begin{Verbatim}
  445. ./scripts/env diff
  446. \end{Verbatim}
  447. If you want to save these changes, run:
  448. \begin{Verbatim}
  449. ./scripts/env save
  450. \end{Verbatim}
  451. If you want to revert your changes to the previously saved copy, run:
  452. \begin{Verbatim}
  453. ./scripts/env revert
  454. \end{Verbatim}
  455. If you want, you can now create a second environment using the \texttt{new} command.
  456. It will ask you whether you want to make it a clone of the current environment (e.g.
  457. for minor changes) or if you want to start with a clean version (e.g. for selecting
  458. a new target).
  459. To switch to a different environment (e.g. \texttt{test1}), use:
  460. \begin{Verbatim}
  461. ./scripts/env switch test1
  462. \end{Verbatim}
  463. To rename the current branch to a new name (e.g. \texttt{test2}), use:
  464. \begin{Verbatim}
  465. ./scripts/env rename test2
  466. \end{Verbatim}
  467. If you want to get rid of environment switching and keep everything in the base directory
  468. again, use:
  469. \begin{Verbatim}
  470. ./scripts/env clear
  471. \end{Verbatim}