Openwrt PDF
April 13, 2023 | Author: Anonymous | Category: N/A
Short Description
Download Openwrt PDF...
Description
Contents 1 The The Rout Router er
3
1.1 Gettin Gettingg sta starte rted d . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
1.1.1 1.1 .1
Instal Installat lation ion . . . . . . . . . . . . . . . . . . . . . . . . . .
3
1.1.2 1.1 .2
Initia Initiall configu configurat ration ion . . . . . . . . . . . . . . . . . . . . .
3
1.1.3 1.1 .3
Fail ailsaf safee mode mode . . . . . . . . . . . . . . . . . . . . . . . . .
3
1.2 Configuring Configuring OpenWrt OpenWrt . . . . . . . . . . . . . . . . . . . . . . . . 1.2. 1.2.11 Net Netwo work rk . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 3
1.2. 1.2.22
Wire Wirele less ss . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
1.3 Advanced Advanced configurat configuration ion . . . . . . . . . . . . . . . . . . . . . . .
9
1.3. 1.3.11
Hotp Hotplu lugg . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10
1.3.2 1.3 .2
Init Init script scriptss . . . . . . . . . . . . . . . . . . . . . . . . . .
10
1.3.3 1.3 .3
Netwo Network rk script scriptss . . . . . . . . . . . . . . . . . . . . . . . .
12
2 Develo Developme pment nt issu issues es
2.1 The build build system system . . . . . . . . . . . . . . . . . . . . . . . . . . .
13 13
2.1.1 2.1 .1
Buildi Building ng an image image . . . . . . . . . . . . . . . . . . . . . .
13
2.1.2 2.1.3
Creating Creating packa packages ges . . . . . . . . . . . . . . . . . . . . . . Creating Creating kernel kernel modules packa packages ges . . . . . . . . . . . . . .
16 21
2.1.4 2.1 .4
Conve Convent ntion ionss . . . . . . . . . . . . . . . . . . . . . . . . . .
22
2.1.5
Troubleshoot roubleshooting ing . . . . . . . . . . . . . . . . . . . . . . .
22
Ex Extr traa tools tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
2.2.1 2.2 .1
Image Image Builde Builderr . . . . . . . . . . . . . . . . . . . . . . . . .
23
2.2. 2.2.22
SDK SDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
2.3 Adding Adding platfo platform rm support support . . . . . . . . . . . . . . . . . . . . . .
23
2.2 2.2
2.3.1
Which Which Operating Operating System System does this device device run? run? . . . . . .
23
2.3.2
Finding Finding and and using using the manufact manufacturer urer SDK . . . . . . . . .
26
1
2
CONTENTS
2.4 Debugging Debugging and debrickin debrickingg . . . . . . . . . . . . . . . . . . . . . .
33
2.4.1 2.4 .1
Adding Adding a serial serial port . . . . . . . . . . . . . . . . . . . . .
33
2. 2.4. 4.22
JTA JTAG . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
33
2.5 Reporti Reporting ng bugs bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.5.1 Using the Trac tic ticket ket system system . . . . . . . . . . . . . . . .
33 33
Chapter 1
The Router 1.1 1. 1
Gett Gettin ing g st star arte ted d
1.1.1 1.1 .1
Instal Installat lation ion
1.1.2 1.1 .2
Initia Initiall configu configurat ration ion
1.1.3 1.1 .3
Failsaf ailsafe e mode
1.2 1. 2
Co Confi nfigu guri ring ng Ope OpenW nWrt rt
1.2. 1.2.1 1
Net Network ork
The network configuration in Kamikaze is stored in /etc/config/network /etc/config/network and is divided into interface configurations. Each interface configuration either refers directly to an ethernet/wifi interface (eth0, wl0, ..) or to a bridge bridge contai containin ningg multiple interfaces. It looks like this: conf confi ig in inte terf rfa ace opt ptio ion n if ifn name ame opt ptio ion n pr pro oto op opti tion on ip ipad addr dr option opt ion net netmas mask k option opt ion gat gatewa eway y option dns
"lan "lan" " "eth eth0" "sta stati tic" c" "1 "192 92.1 .168 68.1 .1.1 .1" " "25 "255.2 5.255. 55.255 255.0" .0" "19 "192.1 2.168. 68.1.2 1.254" 54" "192.168.1.254"
ifname specifi specifies es the Linux interface interface name. If you want to use bridging bridging on one or more interfaces, set ifname to a list of interfaces and add: option type
"bridge"
3
4
CHAPT CHAPTER ER 1. THE RO ROUTE UTER R
It is possible to use VLAN tagging on an interface simply by adding the VLAN IDs to it, e.g. eth0.1. These can be nested as well. This sets up a simple static configuration for eth0. proto specifies the protocol used for the interface. interface. The default default image usually provides provides ’none’ ’static’, ’dhcp’ and ’pppoe’. Others can be added by installing additional packages. When using the ’static’ method like in the example, the options ipaddr and netmask are mandatory, while gateway and dns are optional. DHCP currently only accepts ipaddr (IP address to request from the server) and hostname (client hostname identify as) - both are optional. PPP based protocols (pppoe, pptp, ...) accept these options: •
•
•
username The PPP username (usually with PAP authentication) password The PPP password keepalive Ping the server The value of ecting. thisng. option themaximum maxim umPPP number of (using failed LCP). pings before reconnecti reconn Thespecifies ping interinter val defaults to 5, but can be changed by appending ”,” to the keepalive value
•
•
demand Use Dial on Demand (value specifies the maximum idle time. server: (pptp) The remote pptp server IP
For all protocol types, you can also specify the MTU by using the mtu option. Setting up static routes You can set up static routes for a specific interface that will be brought up after the interface is configured. Simply add a config section like this: config con fig rou route te foo option opti on inte interfac rface e lan option opti on targ target et 1.1.1 1.1.1.0 .0 option opti on netm netmask ask 255.255. 255.255.255.0 255.0 option opti on gate gateway way 192.168. 192.168.1.1 1.1
The name for the route section is optional, the interface, target and gateway options are mandatory. Leaving out the netmask option will turn the route into a host route.
1.2. CONF CONFIGURI IGURING NG OPE OPENWR NWRT T
5
Setting up the switch (currently broadcom only) The switch configuration is set by adding a ’switch’ config section. Example: config switch option vl vlan0 option vlan1
"eth0" "1 2 3 4 5*" "0 5"
On Broadcom hardware the section name needs to be eth0, as the switch driver does not detect detect the switc switch h on an any y other other physi physical cal device. device. Every Every vlan option option needs to have the name vlan where is the VLAN number as used in the switch driver. As value it takes a list of ports with these optional suffixes: •
’*’: Set the default VLAN (PVID) of the Port to the current VLAN
•
’u’: Force the port to be untagged
•
’t’: Force the port to be tagged
The CPU port defaults defaults to tagged, all other ports to untagged untagged.. On Broadcom Broadcom hardware hardw are the CPU port p ort is always 5. The other ports may vary vary with different different hardware.
1.2. 1.2.2 2
Wire Wirele less ss
The WiFi settings are configured in the file /etc/config/wireless /etc/config/wireless (currently supported support ed on Broadcom Broadcom and Atheros). Atheros). When booting the router for the first time it should detect your card and create a sample configuration file. By default ’opti option on netw network ork lan’ is commente commented. d. This prev prevent entss unsecured unsecured sharing of the network over the wireless interface.
Generic Broadcom wireless config: conf confi ig wi wifi fi-d -de evice vice option type option channel config wifi-iface option device # option network lan option mode option ssid option hidden op opti tion on en encr cryp ypti tion on
"wl wl0" 0" "broadcom" "5"
"wl0" "ap" "OpenWrt" "0" "n "non one" e"
6
CHAPT CHAPTER ER 1. THE RO ROUTE UTER R
Generic Atheros wireless config: co conf nfi ig wifi wifi-d -dev evi ice option type
"wifi wifi0" 0" "atheros"
option channel option mode
"5" "11g"
config wifi-iface option device # option network lan option mode option ssid option hidden op opti tion on en encr cryp ypti tion on
"wifi0" "ap" "OpenWrt" "0" "n "non one" e"
Generic multi-radio Atheros wireless conifg: config con fig wi wififi-dev device ice option type op opti tion on cha chann nnel el
wifi0 wifi0 atheros 1
config wifi-iface opti option on devi device ce wifi wifi0 0 # option network lan option mode ap opti option on ssid ssid Open OpenWr Wrt_ t_pr priv ivat ate e opt option ion hidd hidde en 0 option optio n encry encryptio ption n none config con fig wi wififi-dev device ice option type op opti tion on cha chann nnel el
wifi1 wifi1 atheros 11
config wifi-iface opti option on devi device ce wifi wifi1 1 # option network lan option mode ap opti option on ssid ssid Open OpenWr Wrt_ t_pu publ blic ic opt option ion hidd hidde en 1 option optio n encry encryptio ption n none
There are two two types of config sections sections in this file. The ’wifi-device’ refers to the physical wifi interface and ’wifi-iface’ configures a virtual interface on top of that (if supported by the driver). A full outline of the wireless configuration file with description of each field: conf config ig wifi wifi-d -dev evic ice e opti option on type type
wifi wifi devi device ce name name broa broadc dcom om, , athe athero ros s
1.2. CONF CONFIGURI IGURING NG OPE OPENWR NWRT T
op opti tion on option opt ion option opti on option opti on
count country ry cha channe nnel l maxas maxassoc soc dista distance nce
opti option on mode mode
7
us us, , uk uk, , fr fr, , de de, , et etc. c. 1-14 1-14 1-128 (broadco (broadcom m only only) ) 1-n 11b, 11b, 11g, 11g, 11a, 11a, 11bg 11bg (ath (ather eros os only only) )
config wifi-iface option opt ion networ network k the interf interface ace you want wif wifi i to brid bridge ge with op opti tion on devic device e wi wifi fi0, 0, wifi wifi1, 1, wifi2 wifi2, , wifiN wifiN opt ptio ion n mo mod de ap, ap, sta ta, , ad adho hoc c, or wds option ssid ssid name opti option on bssi bssid d bssi bssid d addr addres ess s option opt ion enc encryp ryptio tion n none, none, wep wep, , psk psk, , psk2, psk2, wpa wpa, , wpa2 wpa2 option key encryption key option key1 key 1 option key2 key 2 option key3 key 3 option key4 key 4 op opti tion on se serv rver er ip ad addr dres ess s option port port opti option on hidd hidden en op opti tion on isol isolat ate e
0,1 0,1 0, 0,1 1
Options for the wifi-device: •
type
The driver to use for this interface. •
country
The country code used to determine the regulatory settings. •
channel
The wifi channel (e.g. 1-14, depending on your country setting). •
maxassoc
Optional: Optio nal: Maximum Maximum number number of associated associated clients clients.. This feature feature is supported only on the broadcom chipset. •
distance
Optional: Distance between the ap and the furthest client in meters. This feature is supported only on the atheros chipset. •
mode
The frequency band (b, g, bg, a). This feature feature is only supported supported on the atheros chipset. Options for the wifi-iface: •
network
Selects the interface section from /etc/config/network /etc/config/network to be used with this interface
8
•
CHAPT CHAPTER ER 1. THE RO ROUTE UTER R
device
Set the wifi device name. •
mode
Operating mode: – ap Access point mode – sta Client mode – adhoc Ad-Hoc mode – wds WDS point-to-point link •
ssid Set the SSID to be used on the wifi device.
•
bssid Set the BSSID address to be used for wds to set the mac address
of the other wds unit. •
encryption
Encryption setting. Accepts the following values: – none – wep – psk, psk2 WPA(2) Pre-shared Key – wpa, wpa2 WPA(2) RADIUS •
key, key, key key1, 1, key key2, 2, key3, key3, key key4 4 (wep, wpa and psk)
WEP key, WPA key (PSK mode) or the RADIUS shared secret (WPA
•
RADIUS mode) RADIUS server (wpa) The RADIUS server ip address
•
port (wpa)
The RADIUS server port •
hidden
0 broadcasts the ssid; 1 disables broadcasting of the ssid •
isolate
Optional: Isolation is a mode usually set on hotspots that limits the clients to communicat communicatee only with the AP and not with other wireless wireless clients. clients. 0 disables disab les ap isolation isolation (default); (default); 1 enables enables ap isolation. isolation.
1.3.
ADV ADVANCED ANCED CONFIGURA CONFIGURATION TION
9
Limitations: There are certain limitations limitations when combining combining modes. Only the following mode combinations are supported: •
Broadcom: Broadcom: – 1x sta, 0-3x ap – 1-4x ap – 1x adhoc WDS links can only be used in pure AP mode and cannot use WEP (except when sharing the settings with the master interface, which is done automatically).
•
Atheros: Atheros: – 1x sta, 0-4x ap – 1-4x ap – 1x adhoc
1.3
Adv Advanc anced ed con configu figurat ration ion
Structure of the configuration files The config files are divided into sections and options/values. Every section has a type, Every type, but does not necessarily necessarily have have a name. Every Every option has a name and a value and is assigned to the section it was written under. Syntax: config option
[""] ""
# Section # Option
Every parameter needs to be a single string and is formatted exactly like a parameter for a shell function. The same rules for Quoting and special characters also apply, as it is parsed by the shell. Parsing configuration files in custom scripts To be able to load configuration files, you need to include the common functions with: . /etc/functions.sh /etc/functions.sh
10
CHA CHAPT PTER ER 1. THE RO ROUTE UTER R
Then you can use config_load to lo load ad config config files. files. The The func functi tion on first checks for as absolute filename and falls back to loading it from /etc/config (which is the most common way of using it). If you want to use special callbacks for sections and/or options, you need to define the following shell functions before running config_load (after including /etc/functions.sh): config_cb() config_cb () { local type type="$1 ="$1" " local name name="$2 ="$2" " # co comm mman ands ds to be ru run n fo for r ev ever ery y se sect ctio ion n } option_cb() option_cb () { # co comm mman ands ds to be ru run n fo for r ev ever ery y op opti tion on }
You can also alter option_cb from config_cb based on the section type. This allows you to process every single config section based on its type individually. config_cb is run every time a new section starts (before options are being processed). You can access the last section through the CONFIG_SECTION variable. Also an extra call to config_cb (without a new section) is generated after config_load is done. That allows you to process sections both before and after all
options were processed. You can access already processed options with the config_get command Syntax: config_get # prints the value of the option config_ge confi g_get t # stores stores the value value inside inside the variable variable
In busybox ash the three-option config_get is faster, because it does not result in an extra fork, so it is the preferred way. Additionally you can also modify or add options to sections by using the config_set command. Syntax: config_se confi g_set t
1. 1.3. 3.1 1
Hotp Hotplu lug g
1.3. 1.3.2 2
Init Init scri script ptss
Because OpenWrt uses its own init script system, all init scripts must be installed as /etc/init.d/name use /etc/rc.common as a wrapper. Example: /etc/init.d/httpd
1.3.
ADV ADVANCED ANCED CONFIGURA CONFIGURATION TION
11
#!/bin/sh /etc/rc.commo /etc/rc.common n # Copyr Copyright ight (C) 2006 OpenWrt. OpenWrt.org org START=50 start start() [() -d{/www /www ] && htt httpd pd -p 80 -h /www /www -r Op Open enWr Wrt t } stop() sto p() { killall kill all httpd httpd }
as you can see, the script does not actually parse the command line arguments itself. This is done by the wrapper script /etc/rc.common /etc/rc.common. start() and stop() are the basic functions, which almost any init script should provide. start() is called when the user runs /etc/init.d/httpd /etc/init.d/httpd start or (if
the script is enabled and does not override this behavior) at system boot time. Enabling and disabling init scripts is done by running /etc/init.d/name enname disable able /etc/init.d/ . This crea creates tes removes removes symbolic symboli c links to the or init script in /etc/rc.d , which is processed by or /etc/init.d/rcS /etc/init.d/r cS at boot time.
The order in which these scripts are run is defined in the variable START in the init script, which is optional and defaults to 50. Chang Changing ing it requires requires running /etc/init.d/name enable again. You can also override these standard init script functions: •
boot()
Commands to be run at boot time. Defaults to start() •
restart()
Restart your service. Defaults to stop(); start() •
reload()
Reload the configuration files for your service. Defaults to restart() You can also add custom commands by creating the appropriate functions and referencing them in the EXTRA_COMMANDS vari variabl able. e. Helpte Helptext xt is add added ed in EXTRA_HELP. Example: status() { status() # print print the stat status us inf info o } EXTRA_COMMANDS="status" EXTR EXTRA A_H _HEL ELP= P=" " sta status tus
Pri rint nt the the stat status us of the se serv rvic ice" e"
12
1.3.3 1.3 .3
CHA CHAPT PTER ER 1. THE RO ROUTE UTER R
Netwo Network rk script scriptss
Using the network scripts To able tobyaccess the network functions, you need to include the necessary shellbescripts running: . /etc /etc/f /fun unct ctio ions ns.s .sh h in incl clud ude e /l /lib ib/n /net etwo work rk scan_interfaces
# comm common on func functi tion ons s # in incl clud ude e /li /lib/ b/ne netw twor ork/ k/*. *.sh sh # read and parse the network config
Some protoc Some protocols ols,, such such as PPP PPP might might chang changee the configu configured red in inter terfac facee names names at run time (e.g. eth0 => ppp0 for PPPoE). That’s why you have to run scan_interfaces instead instead of reading reading the values from the config directly. directly. After running scan_interfaces, the ’ifname’ option option will always contain contain the effective interface name (which is used for IP traffic) and if the physical device name differs from it, it will be stored in the ’device’ option. That means that running c config onfig_get _get lan ifname ifname after scan_interfaces scan_interfaces might not return the same result as running it before. scan_interfaces, the following functions are available: After running scan_interfaces •
find_config interface
looks for a network configuration that includes the specified network interface. •
setup_interface interface interface [config] [config] [prot [protocol ocol] ]
will set up the specified interface, optionally overriding the network configuration name or the protocol that it uses. Writing protocol handlers You can add custom protocol handlers by adding shell scripts to /lib/network. They provide the following two shell functions: scan_() { scan_() local config="$1" # change change the interf interface ace nam names es if necess necessary ary } setup_interface_() setup_interface_() { local interface="$1" interface="$1" local config="$2" # se set t up th the e in inte terf rfac ace e } scan_protocolname is optional and only necessary if your protocol uses a cus-
tom device, e.g. a tunnel or a PPP device.
Chapter 2
Development issues 2.1 2. 1
The The bu buil ild d sy syst stem em
One of the biggest challenges to getting started with embedded devices is that you cannot justif install copy of Linux anda compiler expect toand be every able to compile a firmware. Even you didaremember to install development tool offered, you still would not have the basic set of tools needed to produce a firmwar firmwaree image. image. The embedded embedded device device repre represen sents ts an entirely entirely new hardware 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 often means you will be using a rath rather er dated set of tools. Likewise 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.
2.1. 2.1.1 1
Buil Buildi ding ng an imag image e
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 13
14
CHAP CHAPTER TER 2. DEVE DEVELOPM LOPMENT ENT ISSUE ISSUES S
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 transparen trans parent. t. This does not just apply to the kernel, kernel, but to anything anything included included with OpenWrt – Itonisthe thisbleeding one simple concept which is whatkernels allows OpenWrt to stay edgeunderstated with the latest compilers, latest and latest applications. So let’s take a look at OpenWrt and see how this all works. Download OpenWrt This article refers to the ”Kamikaze” branch of OpenWrt, which can be downloaded via subversion using the following command: $ svn checkout https://svn.openwrt.org/openwrt/ https://svn.openwrt.org/openwrt/trunk trunk kamikaze
Additionally, there is a trac interface on on https://dev.openwrt.org/ https://dev.openwrt.org/ which which can be used to monitor svn commits and browse the source repository. The directory structure There are four key directories in the base: •
tools
•
toolchain
•
package
•
target
tools and toolchain refer to common tools which will be used to build the
firmware firmwa re image image,, the compile compiler, r, and the C librar library y. The resu result lt of this this is three three new directories, tool_build, which is a temporary directory for building the toolchain_build_ target which is used for building theindependent toolchain fortools, a specific architecture, and staging_dir_ where the resulting resulting toolchain toolchain is installed. installed. You will not need to do anything anything with the toolchain directory unless you intend to add a new version of one of the components above. •
tool_build
•
toolchain_build_
package is for exactly exactly that – packa packages. ges. In an OpenWrt OpenWrt firmware, firmware, almost everything is an .ipk, a software package which can be added to the firmware
to provide new features or remo removed ved to save save space. space. Note that packages packages are also maintained outside of the main trunk and can be obtained from subversion at the following location:
2.1.. 2.1
THE B BUIL UILD D SYS SYSTEM TEM
15
$ svn checkout https://svn.openwrt.org/openwrt/ https://svn.openwrt.org/openwrt/packages packages packages
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. From kamikaze you would do something like this: $ ls kamika kam ikaze ze packag packages es $ ln -s pack packages ages/net /net/nmap /nmap kamikaze kamikaze/pac /package kage/nmap /nmap
To include all packages, issue the following command: $ ln -s pack packages ages/*/* /*/* kami kamikaze kaze/pack /package/ age/ target refers to the embedded platform, this contains items which are specific to a specific embedded platform. Of particular interest here is the ”target/linux” directory which is broken down by platform and contains the patches to the kernel, profile config, for a particular platform. There’s also the ”target/image” directory which describes how to package a firmware for a specific platform.
Both the target and package steps will use the directory ”build_ ” as a temporary tempor ary directory directory for compiling. compiling. Additional Additionally ly,, anything anything downloaded downloaded by the toolchain, target or package steps will be placed in the ”dl” directory directory.. •
build_
•
dl
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 ” 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 packa pac kages ges you want want to install install into the firmware firmware image. Note that it will also check che ck to make make sure you have have the basic dependencies dependencies for it to run correctly 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, y/m/n which are represented as follows: •
(pressing y)
This will be included in the firmware image
16
•
CHAP CHAPTER TER 2. DEVE DEVELOPM LOPMENT ENT ISSUE ISSUES S
(pressing m)
This will be compiled but not included (for later install) •
< > (pressing n)
This will not be compiled 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 ” make kernel_menuco kernel_menuconfig nfig” and the build system system will unpack the kernel sources (if necessary), run menuconfig inside of the kernel tree, and then copy the kernel config to target/linux/ target/linux/ /config so that it is preserved over ” make clean” calls. calls. To begin compiling the firmware, type ” make”. By default OpenW OpenWrt rt will only display a high level overview of the compile process and not each individual command. Example: make[2] make[3] make[2] make[3] make[4]
toolchain/install toolchain/install -C toolchain install target/compile target/compile -C target compile -C target/utils prepare
[...]
This makes it easier to monitor which step it’s actually compiling and reduces the amount amount of noise cause caused d by the compile output. output. To see the full output, run the command ” make V=99”. During the build process, buildroot will download all sources to the ”dl” directory and will start patching and compiling them in the ”build_ ” directory direc tory.. When finishe resulting resulting firmware firmw arectory willy.be in the ”bin” directory and packages willfinished, be in d, thethe ”bin/packages ” director dire
2.1.2 2.1 .2
Creati Creating ng pack packages ages
One of the things that we’ve attempted to do with OpenWrt’s template system is make it incredibly incredibly easy to port p ort software software to OpenWrt. OpenWrt. If you look at a typical package directory in OpenWrt you’ll find two things: •
package/ /Makefile
•
package/ /patches
•
package/ /files
2.1.. 2.1
THE B BUIL UILD D SYS SYSTEM TEM
17
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 package/bridge/Makefile package/bridge/Makefile: 1 2 3 4 5 6 7
# # Copyri Copyright ght (C) 2006 Op OpenWr enWrt.or t.org g # # This This is free softw software are, , lic licens ensed ed under the GNU Gen Genera eral l Public Public Licens License e v2. # See /LICEN /LICENSE SE for more info informa rmatio tion. n. #
# $Id: $Id: Mak Makefi efile le 5624 2006-112006-11-23 23 00:29 00:29:07 :07Z Z nbd $
8 9
include $(TOPDIR)/rule $(TOPDIR)/rules.mk s.mk
10 11 12 13
PKG_NAME:=bridge PKG_VERSION:=1.0.6 PKG_RELEASE:=1
14 15 16 17 18
PKG_SOURCE:=bridge-utils-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=@SF/bridge PKG_MD5SUM:=9b7dc52656f5cbec846a7ba3299f73bd PKG_CAT:=zcat
19 20
PKG_BUILD_DIR:=$(BUILD_DIR)/bridge-utils-$(PKG_VERSION)
21 22
include $(INCLUDE_DIR) $(INCLUDE_DIR)/package.mk /package.mk
23 24 25 26 27 28 29 30 31 32
define Package/bridg Package/bridge e SECTION:=net CATEGORY:=Base CATEGORY:=Base system TITLE:=Ethernet TITLE:=Ethernet bridging configuratio configuration n utility DESCRIPTION:=\ Man Manage age e ethe therne rnet t bri bridgi dging: ng: a way way to con connec nect t networ networks ks toget together her to to \\\ for form m a lar larger ger net networ work. k. URL:=http://bridge.sourceforge.net/ endef
33 34 35 36
define Build/Configu Build/Configure re $(call Build/Configu Build/Configure/Default, re/Default, \ --with-linux-h --with-linux-headers="$(LIN eaders="$(LINUX_DIR)" UX_DIR)" \
18 37 38
CHAP CHAPTER TER 2. DEVE DEVELOPM LOPMENT ENT ISSUE ISSUES S
) endef
39 40
define Package/brid Package/bridge/install ge/install
41 42 43
$(INSTALL_DIR) $(INSTALL_DIR $(INSTALL_BIN) $(INSTALL_BIN) ) $(1)/usr/sbin $(PKG_BUILD_DI $(PKG_BUILD_DIR)/brctl/brct R)/brctl/brctl l $(1)/usr/sbin/ endef
44 45
$(eval $(call BuildPackage BuildPackage,bridge)) ,bridge))
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. •
PKG_NAME
The name of the package, as seen via menuconfig and ipkg •
PKG_VERSION
The upstream version number that we are downloading •
PKG_RELEASE
The version of this package Makefile •
PKG_SOURCE
The filename of the original sources •
PKG_SOURCE_URL
Where to downl Where download oad the source sourcess from from (no trailing trailing slash), slash), yo you u can add multiple download sources by separating them with a and a carriage return. •
PKG_MD5SUM
A checksum to validate the download •
PKG_CAT
How to decompress the sources (zcat, bzcat, unzip) •
PKG_BUILD_DIR
Where to compile the package The PKG_* variables define where to download the package from; @SF is a special keyword for downloading packages from sourceforge. There is also another keyword of @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 PKG_BUILD_DIR defines where to find the package after the sources are uncompressed into $(BUILD_DIR). At the bottom of the file is where the real magic happens, ”BuildPackage” is a macro set up by the earlier earlier include statements statements.. BuildPac BuildPacka kage ge only takes takes one argument directly – the name of the package to be built, in this case ”bridge”.
2.1.. 2.1
THE B BUIL UILD D SYS SYSTEM TEM
19
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 description template in Package/bridge is, which wouldn’t be the case if we passed this information directly as the Nth argument to BuildPackage. BuildPackage uses the following defines: Package/: matches the argument passed to buildroot, this describes the package the menuconfig menuconfig and ipkg entries. entries. Within Within Package/ you can define the
following variables: variables: •
SECTION
The type of package (currently unused) •
CATEGORY
Which menu it appears in menuconfig: Network, Sound, Utilities, Multimedia ... •
TITLE
A short description of the package •
URL
Where to find the original software •
MAINTAINER (optional)
Who to contact concerning the package •
DEPENDS (optional)
Which packages must be built/installed before this package. To reference a dependency defined in the same Makefile, use . If defined as an external package, use +. For a kernel kernel version dependency use: @LINUX 2 Package//conffiles (optional): A list of config files installed by this package, one file per line. Build/Prepare (optional):
A set of commands to unpack and patch the sources. You may safely leave this undefined. 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 ”$(call Build/Configure/Default, )” 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: -arg 1 -arg -arg 2. The second list contains contains arguments arguments that should should be defined defined before running the configure script such as autoconf or compiler specific variables.
To make it easier to modify the configure command line, you can either extend or completely override the following variables:
20
•
CHAP CHAPTER TER 2. DEVE DEVELOPM LOPMENT ENT ISSUE ISSUES S
CONFIGURE_ARGS
Contains all command line arguments (format: -arg -arg 1 -arg -arg 2) •
CONFIGURE_VARS
Contains all environment variables that are passed to ./configure (format: NAME="value" ) Build/Compile (optional):
How to compile the source; in most cases you should leave this undefined. As with Build/Configure there are two variables that allow you to override the make command line environment variables and flags: •
MAKE_FLAGS
Contains Con tains all command command line argum argument entss (typical (typically ly variable ariable overrid overrides es like NAME="value" •
MAKE_VARS
Contains all environment variables that are passed to the make command Package//install:
A set of commands to copy files out of the compiled source and into the ipkg which is represented by the $(1) di direct rectory ory.. Note that there there are current currently ly 4 defined install macros: •
INSTALL_DIR
install -d -m0755 •
INSTALL_BIN
install -m0755 •
INSTALL_DATA
install -m0644 •
INSTALL_CONF
install -m0600 The reason that some of the defines are prefixed by ”Package/ ” and others are simply ”Build” is because of the possibility of generating multiple packa pac kages ges from a single single source. OpenWrt OpenWrt works under the assumption assumption of one source per package Makefile, but you can split that source into as many packages as desired. Since you only need to compile the sources once, there’s one global set of ”Build” defines, defines, but you can add as many many ”Pack Package/” defines defines as as you want by adding extra calls to BuildPackage – see the dropbear package for an example. After you have created your package/ /Makefile, the new package will automatic autom atically ally show in the menu the next time you run ”mak ”makee menuconfi menuconfig” g” and if selected will be built automatically the next time ” make” is run run..
2.1.. 2.1
THE B BUIL UILD D SYS SYSTEM TEM
2.1.3
21
Creating Creating kernel kernel modules modules pac pack kages
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. For kernel modules that are part of the mainline kernel source, the makefiles are located in in package/kernel/modules/*.mk and package/kernel/modules/*.mk and they appear under the section ”Kernel modules” 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. Here for instance the Makefile for the I2C subsytem kernel modules : 1 2 3 4 5 6 7
# # # # # # #
Copyri Copyright ght (C) 2006 Op OpenWr enWrt.or t.org g This This is free softw software are, , lic licens ensed ed under the GNU Gen Genera eral l Public Public Licens License e v2. See /LICEN /LICENSE SE for more info informa rmatio tion. n. $Id $
8 9
I2CMENU:=I2C Bus
10 11 12 13 14 15 16 17 18 19
20
define KernelPackage KernelPackage/i2c-core /i2c-core TITLE:=I2C support DESCRIPTI DESCRIPTION:= ON:=Kerne Kernel l mo module dules s for i2c support support SUBMENU:=$(I2CMENU) KCONFIG:=$(CONFIG_I2C_CORE KCONFIG:=$(CONFIG_I2C_CORE) ) \ $(CONFIG_I2C_DEV) FILES:=$(MODULES_DIR)/kernel/drivers/i2c/*.$(LINUX_KMOD_SUFFIX) AUTOLOAD:=$(call AUTOLOAD:=$(call AutoLoad,50,i2c-core AutoLoad,50,i2c-core i2c-dev) endef $(eval $ $(call (call KernelPackage,i2c KernelPackage,i2c-core)) -core))
To group kernel modules under a common description in menuconfig, you might want to define a MENU MENU variable on top of the kernel modules makefile. •
TITLE
The name of the module as seen via menuconfig •
DESCRIPTION
The description as seen via help in menuconfig •
SUBMENU
The sub menu under which this package will be seen
22
•
CHAP CHAPTER TER 2. DEVE DEVELOPM LOPMENT ENT ISSUE ISSUES S
KCONFIG
Kernel configuration option dependency. For external modules, remove it. •
FILES
Files you want to inlude to this kernel module pack package, separate separate with spaces. •
AUTOLOAD
Modules that will be loaded automatically on boot, the order you write them is the order they would be loaded. After you have created your package/kernel/modules/ package/kernel/modules/ .mk .mk, the new kernel ker nel modules package package will automatically automatically show show in the menu menu under ”Kerne ”Kernell modules” next time you run ”make menuconfig” and if selected will be built automatically the next time ” make” is run run..
2.1.4 2.1 .4
Conve Convent ntion ionss
There are a couple conventions to follow regarding packages: •
files
1. configuration files follow the con convent vention ion .conf .conf
2. init files follow the conventi convention on .init .init •
patches
1. patches patches are numerically numerically prefixed prefixed and named related related to what they do
2.1.5 2.1 .5
Trouble roubleshoo shooti ting ng
If you find your package doesn’t show up in menuconfig, try the following command to see if you get the correct description: TOPDIR=$P TOPDI R=$PWD WD make -C packa package/< ge/ name> DUMP=1 V=99
If yo you’r u’ree just just havin havingg troubl troublee gettin gettingg yo your ur pack package to compil compile, e, there’ there’ss a few shortcuts you can take. Instead of waiting for make to get to your package, you can run one of the following: •
make pack package/ age/ -cle -clean an V=99
•
make pack package/ age/ -ins -install tall V=99
2.2.. 2.2
EXT EXTRA RA TOOLS TOOLS
23
Another nice trick is that if the source directory under build_ is newer than the package directory, it won’t clobber it by unpacking the sources again. If you were working on a patch you could simply edit the sources under the build_ / directory and run the install command above, when satisfied, the patched diff them with the unpatched sources. Acopy warning though sources - if you elsewhere go modifyand anything under package/ it will remove the old sources and unpack a fresh copy. Other useful targets include: •
make pack package/ age/ -pre -prepare pare V=99
•
make pack package/ age/ -com -compile pile V=99
•
make pack package/ age/ -configure V=99
2.2 2. 2
Ex Extr tra a too ools ls
2.2. 2.2.1 1
Imag Image e Buil Builde der r
2.2.2
SDK
2.3 2. 3
Ad Addi ding ng pl plat atfo form rm su suppo pport rt
Linux is now one of the most widespread operating system for embedded devices due to its openess as well as the wide variety of platforms it can run on. Many manufact manu facturer urer actually actually use it in firmwar firmwaree you can find on many devices: DVB DVB-T decoders, routers, routers, print servers, servers, DVD players players ... Most of the time the stock firmware is not really open to the consumer, even if it uses open source software. You might be interested in running a Linux based firmware for your router for various reasons: extending the use of a network protocol (such as IPv6), having new features, new piece of software inside, or for security reasons. A fully opensource firmware is de-facto needed for such applications, since you want to be free to use this or that version of a particular reason, be able to correct a particular bug. Few manufacturers do ship their routers with a Sample Development Kit, that would allow you to create your own and custom firmware and most of the time, when they do, you will most likely not be able to complete the firmware creation process. This is one of the reasons why OpenWrt and other firmware exists: providing a version independent, and tools independent firmware, that can be run on various platforms, known to be running Linux originaly.
2.3.1 2.3 .1
Whic Which Operatin Operating g System System does this this devic device e run?
There is a lot of methods to ensure your device is running Lin Linux. ux. Some of them do need your router to be unscrewed and open, some can be done by probing the device using its external network interfaces.
24
CHAP CHAPTER TER 2. DEVE DEVELOPM LOPMENT ENT ISSUE ISSUES S
Operating System fingerprinting and port scanning A large bunch of tools over the Internet exists in order to let you do OS fingerprinting, we will show here an example using nmap nmap:: nmap -P0 -O > Starti Sta rting ng Nmap Nmap 4.2 4.20 0 ( htt http:/ p://in /insec secure ure.or .org g ) at 2007-0 2007-01-0 1-08 8 11:05 11:05 CET Interesti Inter esting ng port ports s on 192. 192.168. 168.2.1: 2.1: Not shown: shown: 169 1693 3 clo closed sed por ports ts PORT PORT STAT STATE E SERV SERVIC ICE E 22 22/t /tcp cp op open en ss ssh h 23 23/t /tcp cp open open te teln lnet et 53 53/t /tcp cp open open do doma main in 80 80/t /tcp cp ope open n ht http tp MAC Address: Address: 00:13:xx: 00:13:xx:xx:xx xx:xx:xx :xx (Cisco-Li (Cisco-Linksys nksys) ) Device Devic e type type: : broad broadband band rout router er Running: Runni ng: Linksys Linksys embedded embedded OS det detail ails: s: Lin Linksy ksys s WRT54G WRT54GS S v4 runnin running g OpenWr OpenWrt t w/Linu w/Linux x kernel kernel 2.4.30 2.4.30 Networ Net work k Dis Distan tance: ce: 1 hop
nmap is able to report whether your device uses a Linux TCP/IP stack, and if so, will show you which Linux Linux kernel version version is probably runs. This report is quite reliable and it can make the distinction between BSD and Linux TCP/IP stacks and others. Using the same tool, you can also do port scanning and service version discovery. For instance, the following command will report which IP-based services are running on the device, and which version of the service is being used: nmap -P0 -sV s> Starti Sta rting ng Nmap Nmap 4.2 4.20 0 ( htt http:/ p://in /insec secure ure.or .org g ) at 2007-0 2007-01-0 1-08 8 11:06 11:06 CET Interesti Inter esting ng port ports s on 192. 192.168. 168.2.1: 2.1: Not shown: shown: 169 1693 3 clo closed sed por ports ts PO PORT RT ST STAT ATE E S SER ERVI VICE CE VE VERS RSIO ION N 22/t 22/tcp cp open open ssh ssh Drop Dropbe bear ar sshd sshd 0.48 0.48 (pro (proto toco col l 2. 2.0) 0) 23 23/t /tcp cp open open te teln lnet et Bu Busy sybo box x telne telnetd td 53 53/t /tcp cp open open do doma main in IS ISC C Bind Bind dns dnsma masq sq-2 -2.3 .35 5 80/t 80/tcp cp open open http http Open OpenWr Wrt t Busy BusyBo Box x http httpd d MAC Address: Address: 00:13:xx: 00:13:xx:xx:xx xx:xx:xx :xx (Cisco-Li (Cisco-Linksys nksys) ) Service Servi ce Info Info: : Devi Device: ce: WAP
The web server version, if identified, can be determining in knowing the Operating System. For instance, the BOA the BOA web web server is typical from devices running an open-so open-source urce Unix or Unix-like Unix-like.. Wireless Communications Fingerprinting Although Althou gh this this method method is not really really known known and widesp widesprea read, d, using using a wirele wireless ss scanner to discover which OS your router or Access Point run can be used. We
2.3. ADDIN ADDING G PLA PLATFO TFORM RM SUPPORT
25
do not have a clear example of how this could be achieved, but you will have to monitor raw 802.11 frames and compare them to a very similar device running a Linux based firmware. Web server security exploits The Linksys WRT54G was originally hacked by using a ”ping bug” discovered discovered in the web interface. interface. This tip has not been fixed for months months by Linksys, Linksys, allowing allowing people to enable enable the ”boot wait” helper process via the web interface interface.. Many Many web servers used in firmwares are open source web server, thus allowing the code to be audited audited to find an exploit. exploit. Once you you know the web server server vers version ion that runs on your device, by using nmap using nmap -sV or -sV or so, you might be interested in using exploits to reach shell access on your device. Native Telnet/SSH access Some firmwares might have restricted or unrestricted Telnet/SSH access, if so, try to log in with the web interface login/password and see if you can type in some commands commands. . This actually the case for Broad Broadcom com BCM963xx BCM96ISP 3xx based firmwares such as theisone in Neuf/Cegetel ISPsome routers, Club-Internet CI-Box CI-Bo x and many others. Some commands, commands, like like cat cat might might be left here and be used to determine the Linux kernel version. Analysing a binary firmware image You are very likely to find a firmware binary image on the manufacturer website, even if your device runs a proprietary operating system. If so, you can download it and use an hexadecimal editor to find printable words such as vmlinux vmlinux,, linux linux,, ramdisk,, mtd ramdisk mtd and and others. strings can Some Unix tools like hexdump like hexdump or or strings can be used to analyse the firmware. Below there is an example with a binary firmware found other the Internet:
hexdump hexdu mp 35 2e 00 00 31 2e 30 2e 30 00 00 00 00 00 38 00 45 45 92 89 54 66 1f 61 61 6d 64 69 73 6b 9b 9b f7 39 7b ef 73
less 00 0 00 0(more) 00 00 00 0 00 0 00 00 43 3 36 6 29 00 8b 0 08 8 08 f8 00 e ec c 7d 09 f6 1 19 9 3b 53
00 00 0a 10 bc 67
00 00 e6 68 d5 ea
00 00 dc 42 d3 44
|F |FIR IRE2 E2.5 .5.0 .0.. .... .... ...| .| |. |... ...1 .1.0 .0.0 .0.. .... .... ...| .| |. |... .... .... ..8. 8.C6 C6). )..? .??| ?| |T |TID IDE. E..T .Tf. f... ...? .?.h .hB| B| |. |..r .ram amdi disk sk.? .?}. }.?? ???| ?| |? |??? ??.? .?9{ 9{?s ?s?. ?.;S ;Sg? g?D| D|
Scroll over the firmware to find printable words that can be significant. Amount of flash memory Linux can hardly fit in a 2MB flash device, once you have opened the device and located the flash chip, try to find its characteristics on the Internet. If your flash
26
CHAP CHAPTER TER 2. DEVE DEVELOPM LOPMENT ENT ISSUE ISSUES S
chip is a 2MB or less device, your device is most likely to run a proprietary OS such as WindRiver VxWorks, or a custom manufacturer OS like Zyxel ZynOS. OpenWrt does not currently run on devices which have 2MB or less of flash memory. This limitation will probably not be worked around since those devices are most of the time micro-routers, or Wireless Access Points, which are not the main OpenWrt target. Pluging a serial port By using a serial port and a level shifter, you may reach the console that is being shown by the device for debugging or flashing purposes. purposes. By analysing analysing the output of this device, you can easily notice if the device uses a Linux kenrel or something different.
2.3.2 2.3 .2
Findin Finding g and using using the manu manufac factur turer er SDK SDK
Once you are sure your device run a Linux based firmware, you will be able to start hacking on it. If the manufacturer respected the GPL, it will have released a Sample Development Kit with the device. GPL violations Some manufacturers do release a Linux based binary firmware, with no sources at all. The first step before doing anything anything is to read the license license coming with your device, device, then write them them about this lack of Open Source Source code. If the manufacturer answers you they do not have to release a SDK containing Open Source software, then we recommend you get in touch with the gpl-violations.org community. You will find below a sample letter that can be sent to the manufacturer: Miss, Mister, I am using a , and I cannot find neither on your website nor on the CD-ROM the open source software used to build or modify the firmware. In conformance to the GPL license, you have to release the following sources: •
•
•
complete toolchain that made the kernel and applications be compiled (gcc, binutils, libc) tools to build a custom firmware (mksquashfs, mkcramfs ...) kernel sources with patches to make it run on this specific hardware, this does not include binary drivers
Thank you very much in advance for your answer. Best regards,
2.3. ADDIN ADDING G PLA PLATFO TFORM RM SUPPORT
27
Using the SDK Once the SDK is available, you are most likely not to be able to build a complete or functional firmware using it, but parts of it, like only the kernel, or only the root filesystem. Most manufacturers do not really care releasing a tool that do work every time you uncompress and use it. You should anyway be able to use the following components: •
kernel sources with more or less functional patches for your hardware
•
binary drivers linked or to be linked with the shipped kernel version
•
•
packages packages of the toolchain used to compile the whole firmware: gcc, binutils, libc or uClibc binary tools to create a valid firmware image
Your work can be divided into the following tasks: •
•
create a clean patch of the hardware specific part of the linux kernel spot potential kernel GPL violations especially on netfilter and USB stack stuff
•
make the binary drivers work, until there are open source drivers
•
use standard a GNU toolchain to make working executables
•
understand and write open source tools to generate a valid firmware image
Creating a hardware specific kernel patch Most of the time, the kernel source that comes along with the SDK is not really clean, and is not a standard Linux version, it also has architecture specific fixes backported fromparts the CVS or the CVS oreasily the git repository the git repository the as kernel development trees. Anyway, some can be isolated and of used a good start to make a vanilla kernel work your hardware. Some directories are very likely to have local modifications needed to make your hardw har dware are be recogn recognize ized d and used under under Linux. Linux. First First of all, all, yo you u need need to find out the linux kernel version that is used by your hardware, this can be found by editing the linux/Makefile the linux/Makefile file. file. head -5 linux-2. linux-2.x.x/ x.x/Makef Makefile ile VE VERS RSIO ION N = 2 PATCHL PAT CHLEVE EVEL L = x SUBLEV SUB LEVEL EL = y EXTRAV EXT RAVERS ERSION ION = z NAME=A NAME= A fanc fancy y name
28
CHAP CHAPTER TER 2. DEVE DEVELOPM LOPMENT ENT ISSUE ISSUES S
So no now, w, yo you u know know tha thatt yo you u have have to downl download oad a standa standard rd ke kerne rnell tarbal tarballl at kernel.org that kernel.org that matches the version being used by your hardware. Then you can create a diff a diff file file between the two trees, especially for the following directories:
diff -urN linux-2.x.x/ linux-2.x.x/arch/owner device_mtd_i nfo->owner = THIS_MODULE;
32
CHAP CHAPTER TER 2. DEVE DEVELOPM LOPMENT ENT ISSUE ISSUES S
int parsed parsed_nr _nr_pa _parts rts = 0; // We try here to use the partit partition ion schem schema a provid provided ed by the bootload bootloader er specif specific ic code code if (pa (parse rsed_n d_nr_p r_part arts s == 0) { int ret = parse_bootloader_partition parse_bootloader_partitions(device_mtd_ s(device_mtd_info, info, if (ret > 0) { part_typ part _type e = "BootLoad "BootLoader"; er"; parsed_n pars ed_nr_pa r_parts rts = ret; } }
add_mtd_partitions(devicd_ add_mtd_parti tions(devicd_mtd_info, mtd_info, parsed_parts, parsed_parts, parsed_nr_pa return retu rn 0; } iounmap(device_map.virt); return retu rn -ENX -ENXIO; IO; } // Thi This s fun functi ction on wil will l make make the drive driver r clean clean up the MTD device device mapping mapping static void __ex static __exit it devi device_m ce_mtd_c td_cleanu leanup(vo p(void) id) { // If we fo foun und d a MT MTD D de devi vice ce be befo fore re if (dev (device_ ice_mtd_ mtd_info) info) { // Dele Delete te every partiti partitions ons del_mtd_partitions(device del_mtd_part itions(device_mtd_info); _mtd_info); // Del Delete ete the associ associate ated d map map_destroy(device_mtd_in map_destroy( device_mtd_info); fo); } // If th the e vi virt rtua ual l ad addr dres ess s is al alre read ady y in us use e if (dev (device_ ice_map. map.virt) virt) { // Unm Unmap ap the physical physical addre address ss to a kernel kernel space addres address s iounmap(device_map.virt); // Res Reset et the str struct ucture ure fie field ld device_m devi ce_map.vi ap.virt rt = 0; } }
// Mac Macros ros tha that t ind indica icate te whi which ch fun functi ction on is called called on loadin loading/u g/unlo nloadi ading ng the module module module_init(device_mtd_init module_init(d evice_mtd_init); ); module_exit(device_mtd_clea module_exit(d evice_mtd_cleanup); nup);
// Mac Macros ros def defini ining ng lic licenc ence e and aut author hor, , parame parameter ters s can be define defined d here here too. too. MODULE_LICENSE("GPL"); MODULE_AUTHOR("Me, MODULE_AUTHOR ("Me, myself and I
View more...
Comments