User Tools

Site Tools


zh:docs:guide-developer:adding_new_device

FIXME This page is not fully translated, yet. Please help completing the translation.
(remove this paragraph once the translation is finished)

为新设备添加OpenWrt支持

为了全面了解如何添加新设备支持,我们建议您查看一台新设备相关的最新的commit,摸清楚哪些文件发生了修改和如何修改它们。这些文件尽可能不言自明,大多数时候只是打开它们就足以理解它们的功能。(先机器翻译一次,后面再来修改,“海涵”)

通过实例进行学习

一个好方法是通过示例学习,我们通过搜索mt300a这个版型文件来,找出需要修改的文件,所以你可以这样做:

grep -lri mt300a target/

显示结果是添加新板所需的最少文件列表:

target/linux/ramips/base-files/etc/board.d/01_leds

target/linux/ramips/base-files/etc/board.d/02_network

target/linux/ramips/base-files/lib/upgrade/platform.sh

target/linux/ramips/base-files/lib/ramips.sh

target/linux/ramips/dts/GL-MT300A.dts

target/linux/ramips/image/mt7620.mk

重要文件

最重要的文件一般存放于以下目录:

/target/linux/<arch_name>/base-files/etc/…

该目录的文件和文件夹最终将会存放于设备固件的/etc/目录。

它一般包含下列的文件和文件夹:

  • …board.d/ 定义设备专用的默认硬件的脚本,如LED和网络接口。
  • …hotplug.d/ 定义设备专用的,在插入热插拔设备时自动运行的脚本
  • …init.d/ 定义设备专用的在启动时自动运行的脚本
  • …uci-defaults/ 定义设备专用的UCI默认设置
  • …diag.sh 定义设备显示的错误代码

/target/linux/<arch_name>/base-files/lib/…

该文件夹下的文件夹和文件对应固件中的/lib文件夹。

它的子文件夹和文件有:

  • …<arch_name>.sh阅读友好的设备名转化为脚本安全的设备名的脚本
  • …preinit/ 通用<arch_name>预初始化脚本
  • …upgrade/ 通用<arch_name>升级脚本

/target/linux/<arch_name>/base-files/sbin

该文件夹对应固件中的/sbin文件夹, 一般为通用的<arch_name> sbin脚本和工具.

/target/linux/<arch_name>/dts/

设备树源文件(Device tree source files, 简写为dts).

/target/linux/<arch_name>/image/

用于构建写入用镜像的设置文件。

/target/linux/<arch_name>/<board_name>/

设备专用的设置文件

/target/linux/<arch_name>/modules.mk

menuconfig中使用的架构专用(Arch-specific)配置文件

使新设备出现在make menuconfig中

在编辑了上述的文件后, 你需要对Makefile使用touch命令

touch target/linux/*/Makefile

Patches

The patches-* subdirectories contain the kernel patches applied for every target.
All patches should be named 'NNN-lowercase_shortname.patch' and sorted into the following categories:

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

All patches must be written in a way that they are potentially upstreamable, meaning:

- 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's tftp function and should boot to a prompt without relying on flash/filesystem support.

豆知识

Getting a shell on the target device

In order to collect relevant data for a port of LEDE 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.

With netgear-telnetenable many Netgear devices can be opened up for telnet access. Also see GitHub: insanid/NetgearTelnetEnable. 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 nmrpflash many Netgear devices can be flashed. Devices that are compatible with this tool become effectively unbrickable.

Collecting relevant data

On WikiDevi lots of information can be found, e.g. the FCC ID is very useful when searching for documentation, datasheets and internal photo's (to be able to distinguish used chips without having to open the casing).

Typically one can use the following commands:

dmesg                          # log buffer might be to small, see note 1.
cat /proc/cmdline
cat /proc/cpuinfo
cat /proc/meminfo
cat /proc/devices
ls /sys/devices/platform
cat /proc/mtd
cat /sys/class/mtd/mtd*/offset # Linux 4.1 and newer, see note 2.
ifconfig -a
ls /sys/class/net
brctl show

Note 1: Often the log buffer is to small and the earliest messages may be missing from the information retrieved with dmesg. If one build a stock image from the sources the vendor has published, a larger buffer size can be set within the kernel config.

Note 2: http://lxr.free-electrons.com/source/Documentation/ABI/testing/sysfs-class-mtd

Another useful tool for getting information for setting LEDs might be gpiodump, a MT7620 GPIOMODE register dumper (RAMIPS).

Getting collected data from a device

Sometimes no normal means such as scp or ftp are available for retrieving files from a device. Still one could use httpd and busybox its mount command to do so. How? Assume the files with relevant data on the device with IP address 192.168.0.123 are stored under /tmp and pages of the web interface are served from /www. On the device do:

cp important-data.txt /tmp
mount -o bind /tmp /www

After that the data on the host connected to the device do:

wget http://192.168.0.123/important-data.txt
zh/docs/guide-developer/adding_new_device.txt · Last modified: 2018/08/10 07:17 by miroky