Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revisionBoth sides next revision
zh:docs:guide-developer:adding_new_device [2018/07/12 08:46] – [重要文件] hejian2150663zh:docs:guide-developer:adding_new_device [2020/09/09 02:44] – [从设备获取数据] star_twinkling
Line 1: Line 1:
 FIXME **This page is not fully translated, yet. Please help completing the translation.**\\ //(remove this paragraph once the translation is finished)// FIXME **This page is not fully translated, yet. Please help completing the translation.**\\ //(remove this paragraph once the translation is finished)//
  
-====== 添加新设备 ======+====== 新设备添加OpenWrt支持 ======
  
-一个好的全面建议是从最近关于添加新设备的提交开始,看哪些文件发生了变化以及如何变更。 许多文件试图尽可能不言自明大多数时候打开它们足以理解它们的功能(先机器翻译一次,后面再来修改,“海涵”)+为了全面了解如何添加新设备支持我们建议您查一台新设备相关的最新的commit,摸清楚哪些文件发生了修改和如何修改它们这些文件非常方便理解我们需要去打开查看理解。 
 +===== 通过实例进行学习 =====
  
-===== 实例学习 ===== +一个好方法是通过示例学习,我们通过搜索__mt300a__这个版型文件来,找出需要修改的文件,所以你可以这样做:
- +
-一个好方法是通过示例学习,我们通过搜索mt300a 这个版型文件来,找出需要修改的文件,所以你可以这样做:+
  
 grep -lri mt300a target/ grep -lri mt300a target/
Line 27: Line 26:
 ===== 重要文件 ===== ===== 重要文件 =====
  
-这是大多数重要文件所在位置的一般目录:+重要文件一般存放于以下目录:
  
 ==== /target/linux/<arch_name>/base-files/etc/… ==== ==== /target/linux/<arch_name>/base-files/etc/… ====
  
-文件夹包含集成在固件中’包含一些重要配置,(/etc/目录+该目录的文件和文件夹最终会存放于设备固件/etc/目录
  
-这些是它的文件和文件: +一般包含下列的文件和文件
- +
-  * **…board.d/** scripts for defining device-specific default hardware, like leds and network interfaces. +
-  * **…hotplug.d/** scripts for defining device-specific actions to be done automatically on hotplugging of devices +
-  * **…init.d/** scripts for defining device-specific actions to be done automatically on boot +
-  * **…uci-defaults/** files for defining device-specific uci configuration defaults +
-  * **…diag.sh** defines what is the led to use for error codes for each board+
  
 +  * **…board.d/** 定义设备专用的默认硬件的脚本,如LED和网络接口。
 +  * **…hotplug.d/** 定义设备专用的,在插入热插拔设备时自动运行的脚本
 +  * **…init.d/** 定义设备专用的在启动时自动运行的脚本
 +  * **…uci-defaults/** 定义设备专用的UCI默认设置
 +  * **…diag.sh** 定义设备显示的错误代码
 ==== /target/linux/<arch_name>/base-files/lib/… ==== ==== /target/linux/<arch_name>/base-files/lib/… ====
  
-This folder contains files and folders that will be integrated in the firmware’s /lib folder.+该文件夹下的文件夹和文件对应固件中的/lib目录下文件夹和文件。
  
-These are its subfolders and files:+它的子文件夹和文件有:
  
-  * **…<arch_name>.sh** human-readable full board name associated to script-safe board name +  * **…<arch_name>.sh** 将__阅读友好的设备名__转化为__脚本安全的设备名__的脚本 
-  * **…preinit/** common <arch_name> preinit startup scripts +  * **…preinit/** 通用<arch_name>预初始化脚本 
-  * **…upgrade/** common <arch_name> upgrade scripts+  * **…upgrade/** 通用<arch_name>升级脚本
  
 ==== /target/linux/<arch_name>/base-files/sbin ==== ==== /target/linux/<arch_name>/base-files/sbin ====
  
-This folder contains files and folders that will be integrated in the firmware’s /sbin folderusually common <arch_name> sbin scripts and tools.+该文件夹对应固件中的/sbin文件夹一般为通用的<arch_name> sbin脚本和工具.
  
 ==== /target/linux/<arch_name>/dts/ ==== ==== /target/linux/<arch_name>/dts/ ====
  
-Device tree source files, or dts for short.+设备树源文件(Device tree source files, 简写为dts).
  
 ==== /target/linux/<arch_name>/image/ ==== ==== /target/linux/<arch_name>/image/ ====
  
-Configuration needed to build device-specific flashable images. +用于构建写入用镜像的设置文件。
 ==== /target/linux/<arch_name>/<board_name>/ ==== ==== /target/linux/<arch_name>/<board_name>/ ====
  
-Board-specific configuration.+设备专用的设置文件
  
 ==== /target/linux/<arch_name>/modules.mk ==== ==== /target/linux/<arch_name>/modules.mk ====
  
-Arch-specific kernel module config file for menuconfig+__menuconfig__中使用的架构专用(Arch-specific)配置文件
  
  
-==== Making new device appear in make menuconfig ====+==== 使新设备出现在make menuconfig中 ====
  
-After edit the files aboveyou need to touch the makefiles+在编辑了上述的文件后你需要对Makefile使用touch命令
  
 touch target/linux/*/Makefile touch target/linux/*/Makefile
  
-===== Patches ===== +===== 补丁 ===== 
-The patches-* subdirectories contain the kernel patches applied for every target.\\  +子目录 patches-xxx 是对一个 目标版本xxx 的内核补丁.\\  
-All patches should be named 'NNN-lowercase_shortname.patch' and sorted into the following categories:+它包含的文件名('3个数字-全小写字母的简介.patch')称含义如下:
  
-**0xx** - upstream backports\\ +**0xx** - 上游需要回退的内容补丁\\ 
-**1xx** - code awaiting upstream merge\\ +**1xx** - 等待上游合并的代码补丁\\ 
-**2xx** - kernel build / config / header patches\\ +**2xx** - 内核构建、配置和头文件的补丁\\ 
-**3xx** - architecture specific patches\\ +**3xx** - 用于特定体系结构的补丁\\ 
-**4xx** - mtd related patches (subsystem and drivers)\\ +**4xx** - MTD相关的补丁(系统和设备方面)\\ 
-**5xx** - filesystem related patches\\ +**5xx** - 文件系统相关的补丁\\ 
-**6xx** - generic network patches\\ +**6xx** - 网络通用补丁\\ 
-**7xx** - network / phy driver patches\\ +**7xx** - 网络物理层驱动补丁\\ 
-**8xx** - other drivers\\ +**8xx** - 其他设备补丁\\ 
-**9xx** - uncategorized other patches\\+**9xx** - 未分类的其他补丁\\
  
 <WRAP center round tip 80%> <WRAP center round tip 80%>
-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\\ +必须有一个**明确清晰的commit信息**来解析补丁作出了什么样的改变\\ 
-they must contain a valid Signed-off-by line\\+补丁必须包含**一个签署人**\\
 </WRAP> </WRAP>
  
-===== Testing images ===== +===== 镜像测试 ===== 
-Test firmware images without writing them to flash by using ramdisk images.\\+测试镜像固件通过ramdisk镜像而不通过烧写到Flash。\\
  
-In **make menuconfig** select **Target Images** and then you can select the **ramdisk** option.\\+**make menuconfig**配置中选择**Target Images**,然后再选择**ramdisk**选项。\\
  
-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'tftp function and should boot to a prompt without relying on flash/filesystem support.+这样将会编译生成一个kernel+inittramfs(内核加上内存根文件系统)的镜像文件,它的名字中将会包含**initramfs**。通过BootLoader的tftp功能可以将这个镜像文件导入到设备,这样可以在不需要flash文件系统的支持下进行启动。
  
-===== Tips and tricks ===== +===== 小窍门 ===== 
-==== Getting a shell on the target device ==== +==== 使用目标设备中的shell ==== 
-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.+为了获取到某个你感兴趣的OpenWrt设备的端口的相关数据,需要进行shell访问。但是大多数设备都没有提供使用telnet或者ssh连接shell的方法。
  
-With [[https://wiki.openwrt.org/toh/netgear/telnet.console|netgear-telnetenable]] many Netgear devices can be opened up for telnet access. Also see [[https://github.com/insanid/NetgearTelnetEnable|GitHub: insanid/NetgearTelnetEnable]]+==== 通过PING或者NTP功能进入shell ==== 
-When such means cannot be used, one could try to flash an image build from the sources published by the vendor with telnetd enabled.+某些路由器提供ping测试或NTP服务器配置,并且可能无法正确清理用户输入。尝试输入shell脚本,看看您是否幸运。您可能需要一些JavaScript知识才能禁用客户端输入验证。 
 +== 使用telnetd == 
 +<code bash> 
 +$( /bin/busybox telnetd -l/bin/sh -p23 & ) 
 +</code> 
 +== 如果需要远程登录,请使用HTTP获取密码哈希或使用“sed”删除/更改默认密码 == 
 +<code bash> 
 +$( cp /etc/shadow /www ) 
 +$( cp /etc/passwd /www ) 
 +</code> 
 +然后尝试将他们下载到您的电脑并且破解哈希密码。 
 +== 降级固件 == 
 +某些路由器可能会在启动之初尝试从特定的专用IP下载固件文件(例如TP-Link Archer C2 AC750),从而允许用户降级到较旧的固件。 
 +== HTTP服务器漏洞 == 
 +一些路由器可能正在运行过时/不安全的HTTP服务器,并且可能容易受到缓冲区溢出或其他攻击的影响。 
 +== 网件 == 
 +使用 [[toh:netgear:telnet.console|netgear-telnetenable]] 许多网件设备都可以通过telnet进入,也可以查看 [[https://github.com/insanid/NetgearTelnetEnable|GitHub: insanid/NetgearTelnetEnable]]。如果无法使用这种方法,则可以尝试从启用了telnetd的供应商发布的源中刷新映像构建。
  
-With [[https://github.com/jclehner/nmrpflash|nmrpflash]] many Netgear devices can be flashed. Devices that are compatible with this tool become effectively unbrickable.+通过 [[https://github.com/jclehner/nmrpflash|nmrpflash]]许多网件设备可以被烧录,但是无法确定能够使用该工具的设备有哪些。 
 +==== 收集相关数据 ==== 
 +在[[https://wikidevi.com/wiki/Main_Page|WikiDevi]]上面许多信息可以被查询到,例如:FCC ID:十分的有用处当你搜寻文件的时候,datasheets和网络照片:能够无需打开机壳就能区分使用过的芯片。
  
-==== Collecting relevant data ==== +通常可以使用以下的命令: 
-On [[https://wikidevi.com/wiki/Main_Page|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). +<code bash>
- +
-Typically one can use the following commands:+
   dmesg                          # log buffer might be to small, see note 1.   dmesg                          # log buffer might be to small, see note 1.
   cat /proc/cmdline   cat /proc/cmdline
Line 132: Line 145:
   ls /sys/class/net   ls /sys/class/net
   brctl show   brctl show
-   +  cat /sys/kernel/debug/gpio     # GPIO information 
-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.+</code> 
 + 
 +**注意1**:通过**dmesg**检索时,如果日志的缓存区太小,就会丢失掉最早的信息。如果从供应商发布的资源中构建库存及镜像文件,则可以在内核配置中设置更大的缓冲区大小。 
 + 
 +**注意2**:[[http://lxr.free-electrons.com/source/Documentation/ABI/testing/sysfs-class-mtd]] 
 + 
 +获取设置LED信息的另一个有用的工具是[[https://github.com/jclehner/gpiodump-mt7620|gpiodump]],它是MT7620 GPIOMODE寄存器转储器(RAMIPS)。 
 + 
 + 
 +==== 从设备获取数据 ==== 
 +由于空间有限,常见的文件传输实用程序(例如rsync/curl/ssh/scp/ftp/http/tftp)可能不可用,精简版version/applet可能在busybox中可用。 
 + 
 +假设路由器ip为192.168.0.123,要传输的文件位于/tmp/important-data.txt 
 + 
 +=== HTTP通过"httpd"和"busybox mount"=== 
 +  
 +如果从/www提供Web界面 
 + 
 +== Sender == 
 +<code bash> 
 +mount -o bind /tmp /www 
 +</code> 
 + 
 +== Receiver == 
 +<code bash> 
 +wget http://192.168.0.123/important-data.txt 
 +</code> 
 + 
 +=== FTP通过“busybox ftpput” === 
 +== Receiver == 
 +设置一个FTP服务器,添加一个具有写权限的匿名账号。 
 +<code bash> 
 +python -m pyftpdlib -w -p 21 
 +</code> 
 + 
 + 
 +== Sender == 
 +<code bash> 
 +busybox ftpput 192.168.0.123 important-data.txt /tmp/important-data.txt  
 +</code> 
 + 
 +=== netcat通过“buxybox nc” === 
 +== Receiver == 
 +<code bash> 
 +busybox nc -l -p 12345 > important-data.txt  
 +</code> 
 + 
 +== Sender == 
 +<code bash> 
 +cat /tmp/important-data.txt | busybox nc 192.168.0.123:12345  
 +</code>
  
-Note 2: http://lxr.free-electrons.com/source/Documentation/ABI/testing/sysfs-class-mtd+=== TFTP通过“busybox tftp” === 
 +== Receiver == 
 +Setup a tftp server
  
-Another useful tool for getting information for setting LEDs might be [[https://github.com/jclehner/gpiodump-mt7620|gpiodump]], a MT7620 GPIOMODE register dumper (RAMIPS).+== Sender == 
 +<code bash> 
 +busybox tftp -p -l /tmp/important-data.txt -r important-data.txt 192.168.0.123 
 +</code>
  
-==== Getting collected data from a device ==== +=== 通过终端(terminal)复制 === 
-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? +如果上述所有工具/小工具都不可用,则可以从telnet终端进行复制,但不适用于二进制文件
-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+
      
  • Last modified: 2021/04/17 20:24
  • by guyezi