aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/orion/image/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'target/linux/orion/image/Makefile')
-rw-r--r--target/linux/orion/image/Makefile114
1 files changed, 1 insertions, 113 deletions
diff --git a/target/linux/orion/image/Makefile b/target/linux/orion/image/Makefile
index 16ae4392fc..058519f720 100644
--- a/target/linux/orion/image/Makefile
+++ b/target/linux/orion/image/Makefile
@@ -7,118 +7,6 @@
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/image.mk
-define Image/Prepare
- cp $(LINUX_DIR)/arch/arm/boot/uImage $(KDIR)/uImage
-endef
-
-define Image/BuildKernel
- # Orion Kernel uImages
- # WRT350N v2: mach id 1633 (0x661)
- echo -en "\x06\x1c\xa0\xe3\x61\x10\x81\xe3" > $(KDIR)/wrt350nv2-zImage
- cat $(LINUX_DIR)/arch/arm/boot/zImage >> $(KDIR)/wrt350nv2-zImage
- $(STAGING_DIR_HOST)/bin/mkimage -A arm -O linux -T kernel \
- -C none -a 0x00008000 -e 0x00008000 -n 'Linux-$(LINUX_VERSION)' \
- -d $(KDIR)/wrt350nv2-zImage $(KDIR)/wrt350nv2-uImage
- cp $(KDIR)/wrt350nv2-uImage $(BIN_DIR)/openwrt-wrt350nv2-uImage
- # WNR854T: mach id 1801 (0x709)
- echo -en "\x07\x1c\xa0\xe3\x09\x10\x81\xe3" > $(KDIR)/wnr854t-zImage
- cat $(LINUX_DIR)/arch/arm/boot/zImage >> $(KDIR)/wnr854t-zImage
- $(STAGING_DIR_HOST)/bin/mkimage -A arm -O linux -T kernel \
- -C none -a 0x00008000 -e 0x00008000 -n 'Linux-$(LINUX_VERSION)' \
- -d $(KDIR)/wnr854t-zImage $(KDIR)/wnr854t-uImage
- cp $(KDIR)/wnr854t-uImage $(BIN_DIR)/openwrt-wnr854t-uImage
- # DT2: mach id 1514 (0x5EA)
- echo -en "\x05\x1c\xa0\xe3\xea\x10\x81\xe3" > $(KDIR)/dt2-zImage
- cat $(LINUX_DIR)/arch/arm/boot/zImage >> $(KDIR)/dt2-zImage
- $(STAGING_DIR_HOST)/bin/mkimage -A arm -O linux -T kernel \
- -C none -a 0x00008000 -e 0x00008000 -n 'Linux-$(LINUX_VERSION)' \
- -d $(KDIR)/dt2-zImage $(KDIR)/dt2-uImage
- cp $(KDIR)/dt2-uImage $(BIN_DIR)/openwrt-dt2-uImage
-endef
-
-define Image/Build/Netgear
- # Orion Netgear Images
- mkdir $(KDIR)/netgear_image
- cp $(KDIR)/wnr854t-uImage $(KDIR)/netgear_image/uImage
- $(STAGING_DIR_HOST)/bin/mkfs.jffs2 -m none -p -l -q -e 128KiB -o $(KDIR)/wnr854t-uImage.jffs2 -d $(KDIR)/netgear_image
- rm -rf $(KDIR)/netgear_image
- ( \
- dd if=$(KDIR)/wnr854t-uImage.jffs2 bs=1024k conv=sync; \
- dd if=$(KDIR)/root.$(1) bs=128k conv=sync; \
- ) > $(BIN_DIR)/openwrt-$(2)-$(1).img
- $(STAGING_DIR_HOST)/bin/add_header $(3) $(BIN_DIR)/openwrt-$(2)-$(1).img $(BIN_DIR)/openwrt-$(2)-$(1)-webupgrade.img
-endef
-
-define Image/Build/Linksys
- # Orion Linksys Images
- # sysupgrade image
- ( \
- dd if="${KDIR}/$2-uImage" bs=$5 conv=sync; \
- dd if="${KDIR}/root.$1" bs=64k conv=sync; \
- ) > "${BIN_DIR}/openwrt-$2-$1.img"
- # recovery image and webupgrade image for stock firmware
- rm -rf "${TMP_DIR}/$2_webupgrade"
- mkdir "${TMP_DIR}/$2_webupgrade"
- # create parameter file
- echo ":kernel $5 ${BIN_DIR}/openwrt-$2-uImage" >"${TMP_DIR}/$2_webupgrade/$2.par"
- echo ":rootfs 0 ${KDIR}/root.$1" >>"${TMP_DIR}/$2_webupgrade/$2.par"
- [ ! -f "$(STAGING_DIR_HOST)/share/wrt350nv2-builder/u-boot.bin" ] || ( \
- echo ":u-boot 0 $(STAGING_DIR_HOST)/share/wrt350nv2-builder/u-boot.bin" >>"${TMP_DIR}/$2_webupgrade/$2.par"; )
- echo "#version 0x2020" >>"${TMP_DIR}/$2_webupgrade/$2.par"
- # create bin file for recovery and webupgrade image
- ( cd "${TMP_DIR}/$2_webupgrade"; \
- "${STAGING_DIR_HOST}/bin/$2-builder" \
- -v -b "${TMP_DIR}/$2_webupgrade/$2.par"; \
- )
- # copy bin file as recovery image
- $(CP) "${TMP_DIR}/$2_webupgrade/wrt350n.bin" "$(BIN_DIR)/openwrt-$2-$1-recovery.bin"
- # create webupgrade image for stock firmware update mechanism
- zip "${TMP_DIR}/$2_webupgrade/wrt350n.zip" "${TMP_DIR}/$2_webupgrade/wrt350n.bin"
- "${STAGING_DIR_HOST}/bin/$2-builder" -v -z "${TMP_DIR}/$2_webupgrade/wrt350n.zip" "${BIN_DIR}/openwrt-$2-$1-webupgrade.img"
- rm -rf "${TMP_DIR}/$2_webupgrade"
-endef
-
-define Image/Build/Freecom
- # Orion Freecom Images
- # backup unwanted files
- rm -rf ${TMP_DIR}/$2_backup
- mkdir ${TMP_DIR}/$2_backup
- -mv $(TARGET_DIR)/{var,jffs,rom} ${TMP_DIR}/$2_backup
- # add extra files
- $(INSTALL_DIR) $(TARGET_DIR)/boot
- # TODO: Add special CMDLINE shim for webupgrade image here
- $(CP) $(KDIR)/dt2-uImage $(TARGET_DIR)/boot/uImage
- $(INSTALL_DIR) $(TARGET_DIR)/var
- # create image
- $(TAR) cfj $(BIN_DIR)/openwrt-$(2)-$(1).img --numeric-owner --owner=0 --group=0 -C $(TARGET_DIR)/ .
- $(STAGING_DIR_HOST)/bin/encode_crc $(BIN_DIR)/openwrt-$(2)-$(1).img $(BIN_DIR)/openwrt-$(2)-$(1)-webupgrade.img $(3)
- # remove extra files
- rm -rf $(TARGET_DIR)/{boot,var}
- # recover unwanted files
- -mv ${TMP_DIR}/$2_backup/* $(TARGET_DIR)/
- rm -rf ${TMP_DIR}/$2_backup
-endef
-
-define Image/Build
-$(call Image/Build/$(1),$(1))
-$(call Image/Build/Netgear,$(1),wnr854t,NG_WNR854T,$(1))
-$(call Image/Build/Freecom,$(1),dt2,DT,$(1))
- # Leave WRT350Nv2 at last position due to webimage dependency for zip
- # 5th parameter is kernel mtd size, e.g. 0x00100000 = 1048576 or 0x001A0000 = 1703936
-$(call Image/Build/Linksys,$(1),wrt350nv2,WNR350Nv2,$(1),1048576)
-endef
-
-define Image/Build/squashfs
-$(call prepare_generic_squashfs,$(KDIR)/root.squashfs)
- ( \
- dd if=$(KDIR)/uImage bs=1024k conv=sync; \
- dd if=$(KDIR)/root.$(1) bs=128k conv=sync; \
- ) > $(BIN_DIR)/$(IMG_PREFIX)-$(1).img
-endef
+include $(SUBTARGET).mk
$(eval $(call BuildImage))
-
-# Dependency for WRT350N v2 webupgrade image
-$(eval $(call RequireCommand,zip, \
- Please install zip. \
-))
'#n340'>340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594
One of the biggest challenges to getting started with embedded devices is that you
cannot just install a copy of Linux and expect to be able to compile a firmware.
Even if you did remember to install a compiler and every development tool offered,
you still would not have the basic set of tools needed to produce a firmware image.
The embedded device represents an entirely new hardware platform, which is
most of the time incompatible with the hardware on your development machine, so in a process called
cross compiling you need to produce a new compiler capable of generating code for
your embedded platform, and then use it to compile a basic Linux distribution to
run on your device.

The process of creating a cross compiler can be tricky, it is not something that is
regularly attempted and so there is a certain amount of mystery and black magic
associated with it. In many cases when you are dealing with embedded devices you will
be provided with a binary copy of a compiler and basic libraries rather than
instructions for creating your own -- it is a time saving step but at the same time
often means you will be using a rather dated set of tools. Likewise, it is also common
to be provided with a patched copy of the Linux kernel from the board or chip vendor,
but this is also dated and it can be difficult to spot exactly what has been
modified to make the kernel run on the embedded platform.

\subsection{Building an image}

OpenWrt takes a different approach to building a firmware; downloading, patching
and compiling everything from scratch, including the cross compiler. To put it
in simpler terms, OpenWrt does not contain any executables or even sources, it is an
automated system for downloading the sources, patching them to work with the given
platform and compiling them correctly for that platform. What this means is that
just by changing the template, you can change any step in the process.

As an example, if a new kernel is released, a simple change to one of the Makefiles
will download the latest kernel, patch it to run on the embedded platform and produce
a new firmware image -- there is no work to be done trying to track down an unmodified
copy of the existing kernel to see what changes had been made, the patches are
already provided and the process ends up almost completely transparent. This does not
just apply to the kernel, but to anything included with OpenWrt -- It is this one
simple understated concept which is what allows OpenWrt to stay on the bleeding edge
with the latest compilers, latest kernels and latest applications.

So let's take a look at OpenWrt and see how this all works.


\subsubsection{Download OpenWrt}

OpenWrt can be downloaded via subversion using the following command:

\begin{Verbatim}
$ svn checkout svn://svn.openwrt.org/openwrt/trunk openwrt-trunk
\end{Verbatim}

Additionally, there is a trac interface on \href{https://dev.openwrt.org/}{https://dev.openwrt.org/}
which can be used to monitor svn commits and browse the source repository.


\subsubsection{The directory structure}

There are four key directories in the base:

\begin{itemize}
    \item \texttt{tools}
    \item \texttt{toolchain}
    \item \texttt{package}
    \item \texttt{target}
\end{itemize}

\texttt{tools} and \texttt{toolchain} refer to common tools which will be
used to build the firmware image, the compiler, and the C library.
The result of this is three new directories, \texttt{build\_dir/host}, which is a temporary
directory for building the target independent tools, \texttt{build\_dir/toolchain-\textit{<arch>}*}
which is used for building the toolchain for a specific architecture, and
\texttt{staging\_dir/toolchain-\textit{<arch>}*} where the resulting toolchain is installed.
You will not need to do anything with the toolchain directory unless you intend to
add a new version of one of the components above.

\begin{itemize}
    \item \texttt{build\_dir/host}
    \item \texttt{build\_dir/toolchain-\textit{<arch>}*}
\end{itemize}

\texttt{package} is for exactly that -- packages. In an OpenWrt firmware, almost everything
is an \texttt{.ipk}, a software package which can be added to the firmware to provide new
features or removed to save space. Note that packages are also maintained outside of the main
trunk and can be obtained from subversion using the package feeds system:

\begin{Verbatim}
$ ./scripts/feeds update
\end{Verbatim}

Those packages can be used to extend the functionality of the build system and need to be
symlinked into the main trunk. Once you do that, the packages will show up in the menu for
configuration. You would do something like this:

\begin{Verbatim}
$ ./scripts/feeds search nmap
Search results in feed 'packages':
nmap       Network exploration and/or security auditing utility

$ ./scripts/feeds install nmap
\end{Verbatim}

To include all packages, issue the following command:

\begin{Verbatim}
$ make package/symlinks
\end{Verbatim}

\texttt{target} refers to the embedded platform, this contains items which are specific to
a specific embedded platform. Of particular interest here is the "\texttt{target/linux}"
directory which is broken down by platform \textit{<arch>} and contains the patches to the
kernel, profile config, for a particular platform. There's also the "\texttt{target/image}" directory
which describes how to package a firmware for a specific platform.

Both the target and package steps will use the directory "\texttt{build\_dir/\textit{<arch>}}"
as a temporary directory for compiling. Additionally, anything downloaded by the toolchain,
target or package steps will be placed in the "\texttt{dl}" directory.

\begin{itemize}
    \item \texttt{build\_dir/\textit{<arch>}}
    \item \texttt{dl}
\end{itemize}

\subsubsection{Building OpenWrt}

While the OpenWrt build environment was intended mostly for developers, it also has to be
simple enough that an inexperienced end user can easily build his or her own customized firmware.

Running the command "\texttt{make menuconfig}" will bring up OpenWrt's configuration menu
screen, through this menu you can select which platform you're targeting, which versions of
the toolchain you want to use to build and what packages you want to install into the
firmware image. Note that it will also check to make sure you have the basic dependencies for it
to run correctly.  If that fails, you will need to install some more tools in your local environment
before you can begin.

Similar to the linux kernel config, almost every option has three choices,
\texttt{y/m/n} which are represented as follows:

\begin{itemize}
    \item{\texttt{<*>} (pressing y)} \\
        This will be included in the firmware image
    \item{\texttt{<M>} (pressing m)} \\
        This will be compiled but not included (for later install)
    \item{\texttt{< >} (pressing n)} \\
        This will not be compiled
\end{itemize}

After you've finished with the menu configuration, exit and when prompted, save your
configuration changes.

If you want, you can also modify the kernel config for the selected target system.
simply run "\texttt{make kernel\_menuconfig}" and the build system will unpack the kernel sources
(if necessary), run menuconfig inside of the kernel tree, and then copy the kernel config
to \texttt{target/linux/\textit{<platform>}/config} so that it is preserved over
"\texttt{make clean}" calls.

To begin compiling the firmware, type "\texttt{make}". By default
OpenWrt will only display a high level overview of the compile process and not each individual
command.

\subsubsection{Example:}

\begin{Verbatim}
make[2] toolchain/install
make[3] -C toolchain install
make[2] target/compile
make[3] -C target compile
make[4] -C target/utils prepare

[...]
\end{Verbatim}

This makes it easier to monitor which step it's actually compiling and reduces the amount
of noise caused by the compile output. To see the full output, run the command
"\texttt{make V=99}".

During the build process, buildroot will download all sources to the "\texttt{dl}"
directory and will start patching and compiling them in the "\texttt{build\_dir/\textit{<arch>}}"
directory. When finished, the resulting firmware will be in the "\texttt{bin}" directory
and packages will be in the "\texttt{bin/packages}" directory.


\subsection{Creating packages}

One of the things that we've attempted to do with OpenWrt's template system is make it
incredibly easy to port software to OpenWrt. If you look at a typical package directory
in OpenWrt you'll find several things:

\begin{itemize}
    \item \texttt{package/\textit{<name>}/Makefile}
    \item \texttt{package/\textit{<name>}/patches}
    \item \texttt{package/\textit{<name>}/files}
\end{itemize}

The patches directory is optional and typically contains bug fixes or optimizations to
reduce the size of the executable. The package makefile is the important item, provides
the steps actually needed to download and compile the package.

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.

Looking at one of the package makefiles, you'd hardly recognize it as a makefile.
Through what can only be described as blatant disregard and abuse of the traditional
make format, the makefile has been transformed into an object oriented template which
simplifies the entire ordeal.

Here for example, is \texttt{package/bridge/Makefile}:

\begin{Verbatim}[frame=single,numbers=left]

include $(TOPDIR)/rules.mk

PKG_NAME:=bridge
PKG_VERSION:=1.0.6
PKG_RELEASE:=1

PKG_SOURCE:=bridge-utils-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/bridge
PKG_MD5SUM:=9b7dc52656f5cbec846a7ba3299f73bd
PKG_CAT:=zcat

PKG_BUILD_DIR:=$(BUILD_DIR)/bridge-utils-$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk

define Package/bridge
  SECTION:=net
  CATEGORY:=Base system
  TITLE:=Ethernet bridging configuration utility
  URL:=http://bridge.sourceforge.net/
endef

define Package/bridge/description
  Manage ethernet bridging: 
  a way to connect networks together to form a larger network.
endef

define Build/Configure
    $(call Build/Configure/Default, \
        --with-linux-headers="$(LINUX_DIR)" \
    )
endef

define Package/bridge/install
    $(INSTALL_DIR) $(1)/usr/sbin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/brctl/brctl $(1)/usr/sbin/
endef

$(eval $(call BuildPackage,bridge))
\end{Verbatim}

As you can see, there's not much work to be done; everything is hidden in other makefiles
and abstracted to the point where you only need to specify a few variables.

\begin{itemize}
    \item \texttt{PKG\_NAME} \\
        The name of the package, as seen via menuconfig and ipkg
    \item \texttt{PKG\_VERSION} \\
        The upstream version number that we are downloading
    \item \texttt{PKG\_RELEASE} \\
        The version of this package Makefile
    \item \texttt{PKG\_SOURCE} \\
        The filename of the original sources
    \item \texttt{PKG\_SOURCE\_URL} \\
        Where to download the sources from (no trailing slash), you can add multiple download sources by separating them with a \\ and a carriage return.
    \item \texttt{PKG\_MD5SUM} \\
        A checksum to validate the download
    \item \texttt{PKG\_CAT} \\
        How to decompress the sources (zcat, bzcat, unzip)
    \item \texttt{PKG\_BUILD\_DIR} \\
        Where to compile the package
\end{itemize}

The \texttt{PKG\_*} variables define where to download the package from;
\texttt{@SF} is a special keyword for downloading packages from sourceforge. There is also
another keyword of \texttt{@GNU} for grabbing GNU source releases. If any of the above mentionned download source fails, the OpenWrt mirrors will be used as source.

The md5sum (if present) is used to verify the package was downloaded correctly and
\texttt{PKG\_BUILD\_DIR} defines where to find the package after the sources are
uncompressed into \texttt{\$(BUILD\_DIR)}.

At the bottom of the file is where the real magic happens, "BuildPackage" is a macro
set up by the earlier include statements. BuildPackage only takes one argument directly --
the name of the package to be built, in this case "\texttt{bridge}". All other information
is taken from the define blocks. This is a way of providing a level of verbosity, it's
inherently clear what the contents of the \texttt{description} template in
\texttt{Package/bridge} is, which wouldn't be the case if we passed this information
directly as the Nth argument to \texttt{BuildPackage}.

\texttt{BuildPackage} uses the following defines:

\textbf{\texttt{Package/\textit{<name>}}:} \\
    \texttt{\textit{<name>}} matches the argument passed to buildroot, this describes
    the package the menuconfig and ipkg entries. Within \texttt{Package/\textit{<name>}}
    you can define the following variables:

    \begin{itemize}
        \item \texttt{SECTION} \\
            The section of package (currently unused)
        \item \texttt{CATEGORY} \\
            Which menu it appears in menuconfig: Network, Sound, Utilities, Multimedia ...
        \item \texttt{TITLE} \\
            A short description of the package
        \item \texttt{URL} \\
            Where to find the original software
        \item \texttt{MAINTAINER} (optional) \\
            Who to contact concerning the package
        \item \texttt{DEPENDS} (optional) \\
            Which packages must be built/installed before this package. To reference a dependency defined in the
			same Makefile, use \textit{<dependency name>}. If defined as an external package, use 
			\textit{+<dependency name>}. For a kernel version dependency use: \textit{@LINUX\_2\_<minor version>}
		\item \texttt{BUILDONLY} (optional) \\
			Set this option to 1 if you do NOT want your package to appear in menuconfig.
			This is useful for packages which are only used as build dependencies.
    \end{itemize}

\textbf{\texttt{Package/\textit{<name>}/conffiles} (optional):} \\
   A list of config files installed by this package, one file per line.

\textbf{\texttt{Build/Prepare} (optional):} \\
   A set of commands to unpack and patch the sources. You may safely leave this
   undefined.

\textbf{\texttt{Build/Configure} (optional):} \\
   You can leave this undefined if the source doesn't use configure or has a
   normal config script, otherwise you can put your own commands here or use
   "\texttt{\$(call Build/Configure/Default,\textit{<first list of arguments, second list>})}" as above to
   pass in additional arguments for a standard configure script. The first list of arguments will be passed
   to the configure script like that: \texttt{--arg 1} \texttt{--arg 2}. The second list contains arguments that should be