Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision Next revisionBoth sides next revision | ||
| playground:experiment:docs:development:new_device [2016/10/01 14:04] – created richb-hanover | docs:guide-developer:adding_new_device [2024/10/22 09:39] – Add note about using curl as an option. evs | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ==== Adding a new device ==== | + | ====== Adding a new device |
| A good all-round advice would be to start by looking at recent commits about adding a new device, to see what files where changed and how. Many files try to be as self-explanatory as possible, most of the times just opening them will be enough to understand their function. | A good all-round advice would be to start by looking at recent commits about adding a new device, to see what files where changed and how. Many files try to be as self-explanatory as possible, most of the times just opening them will be enough to understand their function. | ||
| + | |||
| + | ===== Learn by example ===== | ||
| + | |||
| + | ==== Search by grep locally ==== | ||
| + | |||
| + | A good method is learn by example, so you can do: | ||
| + | |||
| + | grep -lri mt300a target/ | ||
| + | |||
| + | The result is minimal list of files required to add a new board: | ||
| + | |||
| + | < | ||
| + | target/ | ||
| + | target/ | ||
| + | target/ | ||
| + | target/ | ||
| + | target/ | ||
| + | target/ | ||
| + | </ | ||
| + | |||
| + | ==== Search by Git commit ==== | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | ===== Important files ===== | ||
| This is a general map of where most important files are located: | This is a general map of where most important files are located: | ||
| - | === / | + | ==== / |
| This folder contains files and folders that will be integrated in the firmware’s /etc folder. | This folder contains files and folders that will be integrated in the firmware’s /etc folder. | ||
| Line 14: | Line 39: | ||
| * **…hotplug.d/ | * **…hotplug.d/ | ||
| * **…init.d/ | * **…init.d/ | ||
| - | * **…uci-defaults/ | + | * **…uci-defaults/ |
| * **…diag.sh** defines what is the led to use for error codes for each board | * **…diag.sh** defines what is the led to use for error codes for each board | ||
| + | //Note that some of these functions are now done in the DTS for the board.// | ||
| ==== / | ==== / | ||
| Line 31: | Line 57: | ||
| This folder contains files and folders that will be integrated in the firmware’s /sbin folder, usually common < | This folder contains files and folders that will be integrated in the firmware’s /sbin folder, usually common < | ||
| - | === / | + | ==== / |
| Device tree source files, or dts for short. | Device tree source files, or dts for short. | ||
| + | //Certain architectures have the DTS directory deeper down. ARM devices, for example, typically have it located at '' | ||
| + | |||
| + | //If the DTS or DTSI file is already present in upstream Linux, they will usually not be present in the OpenWrt source. Configuring for the target and running '' | ||
| ==== / | ==== / | ||
| Line 46: | Line 75: | ||
| Arch-specific kernel module config file for menuconfig | Arch-specific kernel module config file for menuconfig | ||
| + | |||
| + | ==== Making new device appear in make menuconfig ==== | ||
| + | |||
| + | After edit the files above, you need to touch the makefiles | ||
| + | |||
| + | touch target/ | ||
| + | |||
| + | ===== Patches ===== | ||
| + | The patches-* subdirectories contain the kernel patches applied for every target.\\ | ||
| + | All patches should be named ' | ||
| + | |||
| + | **0xx** - upstream backports\\ | ||
| + | **1xx** - code awaiting upstream merge\\ | ||
| + | **2xx** - kernel build / config / header patches\\ | ||
| + | **3xx** - architecture specific patches\\ | ||
| + | **4xx** - mtd related patches (subsystem and drivers)\\ | ||
| + | **5xx** - filesystem related patches\\ | ||
| + | **6xx** - generic network patches\\ | ||
| + | **7xx** - network / phy driver patches\\ | ||
| + | **8xx** - other drivers\\ | ||
| + | **9xx** - uncategorized other patches\\ | ||
| + | |||
| + | <WRAP center round tip 80%> | ||
| + | All patches must be written in a way that they are potentially upstreamable, | ||
| + | |||
| + | - they must contain a **proper subject** | ||
| + | - they must contain a **proper commit message** explaining what they change | ||
| + | - they must contain a **valid Signed-off-by line** | ||
| + | </ | ||
| + | |||
| + | ===== Testing images ===== | ||
| + | Test firmware images without writing them to flash by using ramdisk images. | ||
| + | |||
| + | In **make menuconfig** select **Target Images** and then you can select the **ramdisk** option. | ||
| + | |||
| + | This will create an image with kernel + initramfs, that will have **initramfs** in the name. The resulting image can be loaded in the device through the bootloader' | ||
| + | |||
| + | ===== Tips and tricks ===== | ||
| + | ==== Getting a shell on the target device ==== | ||
| + | In order to collect relevant data for a port of OpenWrt to the device of interest one wants shell access. Most devices though do not offer a way to get a shell with telnet or ssh. | ||
| + | === Abuse Unsanitized User Input === | ||
| + | Some router offers ping test or NTP server configuration and may not properly sanitize user input. Try to enter shell script and see if you are lucky. You may need some '' | ||
| + | == Starting telnetd == | ||
| + | <code bash> | ||
| + | $( / | ||
| + | </ | ||
| + | == Obtain the password hash using HTTP or use '' | ||
| + | <code bash> | ||
| + | $( cp /etc/shadow /www ) | ||
| + | $( cp /etc/passwd /www ) | ||
| + | </ | ||
| + | Then try to download them to your computer and crack the hash | ||
| + | |||
| + | === Downgrade to older firmware === | ||
| + | Some router may try to download a firmware file (e.g. [[toh: | ||
| + | |||
| + | === Downgrade by Serial access === | ||
| + | Serial access may allow you to enter console mode of u-boot for flashing/ | ||
| + | See [[docs: | ||
| + | |||
| + | === HTTP Server Vulnerability === | ||
| + | Some routers may be running outdated/ | ||
| + | |||
| + | === Netgear === | ||
| + | With [[toh: | ||
| + | When such means cannot be used, one could try to flash an image build from the sources published by the vendor with telnetd enabled. | ||
| + | |||
| + | With [[https:// | ||
| + | |||
| + | ==== Collecting relevant data ==== | ||
| + | On [[https:// | ||
| + | |||
| + | Typically one can use the following commands: | ||
| + | |||
| + | <code bash> | ||
| + | dmesg # log buffer might be to small, see note 1. | ||
| + | cat / | ||
| + | cat / | ||
| + | cat / | ||
| + | cat / | ||
| + | ls / | ||
| + | cat /proc/mtd | ||
| + | cat / | ||
| + | ifconfig -a | ||
| + | ls / | ||
| + | brctl show | ||
| + | cat / | ||
| + | </ | ||
| + | |||
| + | **Note 1:** Often the log buffer is to small and the earliest messages may be missing from the information retrieved with '' | ||
| + | |||
| + | **Note 2:** [[http:// | ||
| + | |||
| + | Another useful tool for getting information for setting LEDs might be [[https:// | ||
| + | |||
| + | ==== Getting collected data from a device ==== | ||
| + | Because of the limited space, common file transfer utilities such as rsync/ | ||
| + | |||
| + | Assume the router ip is '' | ||
| + | |||
| + | === HTTP by '' | ||
| + | If the web interface are served from ''/ | ||
| + | |||
| + | == Sender == | ||
| + | <code bash> | ||
| + | mount -o bind /tmp /www | ||
| + | </ | ||
| + | |||
| + | == Receiver == | ||
| + | <code bash> | ||
| + | wget http:// | ||
| + | </ | ||
| + | |||
| + | === FTP by '' | ||
| + | == Receiver == | ||
| + | Setup an FTP server. Add an anonymous account with write permission | ||
| + | |||
| + | <code bash> | ||
| + | python -m pyftpdlib -w -p 21 | ||
| + | </ | ||
| + | == Sender == | ||
| + | <code bash> | ||
| + | busybox ftpput 192.168.0.123 important-data.txt / | ||
| + | </ | ||
| + | |||
| + | === netcat by '' | ||
| + | == Receiver == | ||
| + | <code bash> | ||
| + | busybox nc -l -p 12345 > important-data.txt | ||
| + | </ | ||
| + | == Sender == | ||
| + | <code bash> | ||
| + | cat / | ||
| + | </ | ||
| + | |||
| + | === TFTP by '' | ||
| + | == Receiver == | ||
| + | Setup a tftp server | ||
| + | |||
| + | == Sender == | ||
| + | <code bash> | ||
| + | busybox tftp -p -l / | ||
| + | </ | ||
| + | |||
| + | === Use Curl to upload === | ||
| + | Depending on what is compiled into your curl binary if available you may also be able to auth, use ftp/tftp etc. | ||
| + | "It supports these protocols: DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, | ||
| + | HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, POP3, POP3S, RTMP, RTMPS, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, | ||
| + | and WSS. The command is designed to work without user interaction. | ||
| + | " | ||
| + | Extract from curl man page: | ||
| + | < | ||
| + | -T, --upload-file < | ||
| + | This transfers the specified local file to the remote URL. If there is no file part in the specified URL, curl will append | ||
| + | the local file name. NOTE that you must use a trailing / on the last directory to really prove to Curl that there is no | ||
| + | file name or curl will think that your last directory name is the remote file name to use. That will most likely cause the | ||
| + | upload operation to fail. If this is used on an HTTP(S) server, the PUT command will be used. | ||
| + | |||
| + | Use the file name " | ||
| + | riod) may be specified instead of " | ||
| + | uploaded. | ||
| + | |||
| + | You can specify one -T, --upload-file for each URL on the command line. Each -T, --upload-file + URL pair specifies what to | ||
| + | upload and to where. curl also supports " | ||
| + | files to a single URL by using the same URL globbing style supported in the URL. | ||
| + | |||
| + | When uploading | ||
| + | set of headers and mail body formatted correctly by the user as curl will not transcode nor encode it further in any way. | ||
| + | |||
| + | -T, --upload-file can be used several times in a command line | ||
| + | |||
| + | Examples: | ||
| + | curl -T file https:// | ||
| + | curl -T " | ||
| + | curl --upload-file " | ||
| + | |||
| + | See also -G, --get and -I, --head. | ||
| + | |||
| + | </ | ||
| + | === Copy from terminal === | ||
| + | If all of the above tools/ | ||
| + | |||
| + | base64 would be a common choice to work around this limitation, but many routers lack such a command. You can first escape binary data to screen-safe hexadecimal by piping to busybox hexdump on the router: | ||
| + | <code bash> | ||
| + | hexdump -v -e '/1 " | ||
| + | </ | ||
| + | You can then reverse it on the computer with the following command: | ||
| + | <code bash> | ||
| + | xxd -r -p | ||
| + | </ | ||
| + | |||