泰晓科技 -- 聚焦 Linux - 追本溯源,见微知著!
网站地址:https://tinylab.org

儿童Linux系统,可打字编程学数理化
请稍侯

Linux Lab 真板开发日志(2):macOS 和 Windows 环境之无串口开发


如何通过 ssh 开发真板
贾献华 创作于 2021/02/08

By 贾献华 of TinyLab.org Jan 16, 2021

前言

本文所采用的 i.MX6ULL Pro 开发板可以直接从 泰晓科技自营店 选购。

Docker 下串口识别问题

前文提到,在 macOSWindowsDocker 是无法直接访问串口的,我们可以通过 ssh 使用网络访问,第一步就是要知道真板的 ip 地址。

先通过 Host 机访问串口,Windows 可以从设备管理器找到 COM 口,macOS 可以通过 /dev/usb* 识别。

// microUSB 带网口
// usb 转串口
$ ls -l /dev/cu.usb*
/dev/cu.usbmodem1234fire56783
/dev/cu.usbserial-144430

// Ctrl + A + K: exit screen
// Ctrl + A + D: exit screen, can resume
$ screen -L /dev/cu.usbmodem1234fire56783 115200


// resume
$ screen -r

imx6ull

通过主机串口获取 IP 地址

接下来通过串口获取到板子的 IP 地址:

debian@npi:~$ ifconfig | grep 192
        inet 192.168.1.137  netmask 255.255.255.0  broadcast 192.168.1.255
        inet 192.168.7.2  netmask 255.255.255.252  broadcast 192.168.7.3

在 Linux Lab 下无串口开发真板

识别到 IP 地址就好办了,跟着文档 操作就好。

$ sed -i -e "s/nand/mmc/g" boards/arm/ebf-imx6ull/Makefile
$ make BOARD=arm/ebf-imx6ull
$ make kernel-build
$ make kernel-upload
$ make login

这里会提示需要配置 BOARD_SERIAL or BOARD_IP

Makefile:2923: *** This is a real hardware board, please buy one from https://shop155917374.taobao.com and configure BOARD_SERIAL or BOARD_IP in /labs/linux-lab/boards/arm/ebf-imx6ull/Makefile before uploading.  Stop.

我们通过 ssh 访问,可以简单的设置环境变量。

$ export BOARD_IP=192.168.1.137

make login 还需要传递 BOARD_USERBOARD_PASS

默认是以 root:linux-lab 登录的,新的开发板还没有配置好,我们要覆盖默认值。

$ make login BOARD_IP=192.168.1.137 BOARD_USER=debian BOARD_PASS=temppwd

修改默认密码并配置登录提示

接下来为了方便管理,把密码改成 linux-lab,顺便修改提示。

debian@npi:~$ sudo sed -i -e "s/temppwd/linux-lab/g" /etc/{issue,issue.net}
[sudo] password for debian:

debian@npi:~$ sudo -s
root@npi:/home/debian# passwd root
New password: linux-lab
Retype new password: linux-lab
passwd: password updated successfully

root@npi:/home/debian# sudo sed -i -e "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config
root@npi:/home/debian# sudo service sshd restart

root@npi:/home/debian# passwd debian
New password: linux-lab
Retype new password: linux-lab
passwd: password updated successfully

先看一下当前内核版本:

root@npi:/home/debian# uname -a
Linux npi 4.19.71-imx-r1 #1stable SMP PREEMPT Thu Nov 26 13:47:40 CST 2020 armv7l GNU/Linux

这是野火 2020年11月26 发布的预览版。

上传 zImage, dtb 和 modules

按照文档操作即可。

  • 上传内核
ubuntu@linux-lab:/labs/linux-lab$ make kernel-upload
Building dtb ...
  DTS: /labs/linux-lab/src/linux-stable/arch/arm/boot/dts/imx6ull-mmc-npi.dts
  DTB: /labs/linux-lab/build/arm/linux-v4.19.35-ebf-imx6ull/arch/arm/boot/dts/imx6ull-mmc-npi.dtb
  DTC     arch/arm/boot/dts/imx6ull-mmc-npi.dtb
env PATH=/usr/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin  make O=/labs/linux-lab/build/arm/linux-v4.19.35-ebf-imx6ull -C /labs/linux-lab/src/linux-stable ARCH=arm LOADADDR= CROSS_COMPILE=arm-linux-gnueabi- V=  CONFIG_INITRAMFS_SOURCE= -j4 zImage
  GEN     ./Makefile
  Using /labs/linux-lab/src/linux-stable as source for kernel
  CALL    /labs/linux-lab/src/linux-stable/scripts/checksyscalls.sh
  CHK     include/generated/compile.h
  Kernel: arch/arm/boot/Image is ready
  Kernel: arch/arm/boot/zImage is ready
LOG: Upload kernel image from /labs/linux-lab/build/arm/linux-v4.19.35-ebf-imx6ull/arch/arm/boot/zImage to 192.168.1.137:/boot/vmlinuz-4.19.35+
  • 上传设备树
ubuntu@linux-lab:/labs/linux-lab$ make dtb-upload
LOG: Upload dtb image from /labs/linux-lab/build/arm/linux-v4.19.35-ebf-imx6ull/arch/arm/boot/dts/imx6ull-mmc-npi.dtb to 192.168.1.137:/boot/dtbs/4.19.35+/imx6ull-mmc-npi.dtb
  • 上传模块
ubuntu@linux-lab:/labs/linux-lab$ make modules-upload
LOG: Upload modules from /labs/linux-lab/boards/arm/ebf-imx6ull/bsp/root/2020.02//rootfs/lib/modules/4.19.35+ to 192.168.1.137:/lib/modules/4.19.35+
Warning: Permanently added '192.168.1.137' (ECDSA) to the list of known hosts.
Debian GNU/Linux 10

embedfire.com Debian Image 2020-11-26

Support/FAQ: www.firebbs.cn/forum.php

default username:password is [debian:linux-lab]

sending incremental file list
modules.alias
...
kernel/sound/usb/snd-usbmidi-lib.ko

sent 6,699,045 bytes  received 2,782 bytes  2,680,730.80 bytes/sec
total size is 6,688,486  speedup is 1.00

更换内核配置并重启

组合动作

ubuntu@linux-lab:/labs/linux-lab$ make boot
LOG: Configure new kernel and dtbs images
LOG: Rebooting via ssh
LOG: Login via ssh protocol
root@npi:~# Connection to 192.168.1.137 closed by remote host.
make: *** [Makefile:3670: _boot] Error 255

真板一重启,ssh 就断开连接了,所以要手动连接。

分解动作

  • 设置启动项
ubuntu@linux-lab:/labs/linux-lab$ make boot-config
LOG: Configure new kernel and dtbs images
  • 重启真板
ubuntu@linux-lab:/labs/linux-lab$ make reboot
LOG: Rebooting via ssh
  • 重新登录
ubuntu@linux-lab:/labs/linux-lab$ make login BOARD_IP=192.168.1.137
LOG: Login via ssh protocol
  • 查看内核版本
root@npi:~# uname -a
Linux npi 4.19.35+ #3 SMP PREEMPT Fri Jan 15 09:30:59 CST 2021 armv7l GNU/Linux

内核版本已经改为 4.19.35+

开发内核模块

直接使用 Linux Lab 提供的 hello 模块。

$ make modules m=hello
$ make modules-install m=hello
$ make modules-upload

验证一下。

ubuntu@linux-lab:/labs/linux-lab$ make login
LOG: Login via ssh protocol

root@npi:~# sudo modprobe hello
root@npi:~# lsmod | grep hello
hello                  16384  0
root@npi:~# dmesg | grep hello
[  393.911872] hello: loading out-of-tree module taints kernel.
[  393.936401] hello module init

macOS_Windows

总结

通过简单的设置一下 BOARD_IP,通过 ssh 也可以像 串口 一样简洁方便的进行开发。



Read Album:

Read Related:

Read Latest: