2024年1月18日 星期四

STM32MP157 buildroot USB_Gadget

Board: STM32MP157f-DK2
OS: buildroot (branch: remotes/origin/st/2022.02)
patch: buildroot-external-st (branch: st/2022.02.7)

Add OpenSSH within buildroot
...
BR2_PACKAGE_OPENSSH=y
BR2_PACKAGE_OPENSSH_CLIENT=y
BR2_PACKAGE_OPENSSH_SERVER=y
BR2_PACKAGE_OPENSSH_KEY_UTILS=y
BR2_PACKAGE_DROPBEAR=y //不然scp/ssh連不進來

sshd debug
client to host,使用scp沒有很順利,debug keyword也查不到什麼有用的方法...
BR2_PACKAGE_DROPBEAR=y,這個打開就好了 = =
# sshd -f /etc/ssh/sshd_config -ddd
or
# cat /var/log/message

...
...
debug3: append_hostkey_type: ssh-rsa key not permitted by HostkeyAlgorithms [preauth]
debug3: append_hostkey_type: ssh-dss key not permitted by HostkeyAlgorithms [preauth]
debug1: list_hostkey_types: rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256 [preauth]
debug3: send packet: type 20 [preauth]
debug1: SSH2_MSG_KEXINIT sent [preauth]
debug1: monitor_read_log: child log fd closed
debug3: mm_request_receive: entering
debug1: do_cleanup
debug1: Killing privsep child 271

ChatGPT是說
It appears that the client is offering host key algorithms (ssh-rsa and ssh-dss) that are not permitted by the server's configuration. 
The server's allowed host key algorithms are RSA (rsa-sha2-512, rsa-sha2-256), and ECDSA (ecdsa-sha2-nistp256).

To address this issue, you can modify the SSH client's configuration to prioritize key algorithms that are permitted by the server. 
On the client side, you can create or modify the ~/.ssh/config file and add the following lines:

Host your_server_ip
    HostKeyAlgorithms +ssh-rsa
但沒有用 :(


image/stm32mp157f-dk2.dtb to image/stm32mp157f-dk2.dts
$ cp image/stm32mp157f-dk2.dtb ~/temp; cd ~/temp
$ dtc -I dtb -O dts -o stm32mp157f-dk2.dts stm32mp157f-dk2.dtb


stm32mp157f-dk2.dts
...
...
usb-otg@49000000 {
			compatible = "st,stm32mp15-hsotg\0snps,dwc2";
			reg = <0x49000000 0x10000>;
			clocks = <0x0c 0xa6>;
			clock-names = "otg";
			resets = <0x0c 0x4cc8>;
			reset-names = "dwc2";
			interrupts-extended = <0x18 0x2c 0x04>;
			g-rx-fifo-size = <0x200>;
			g-np-tx-fifo-size = <0x20>;
			g-tx-fifo-size = <0x100 0x10 0x10 0x10 0x10 0x10 0x10 0x10>;
			dr_mode = "otg";
			otg-rev = <0x200>;
			usb33d-supply = <0x55>;
			power-domains = <0x19>;
			wakeup-source;
			status = "okay";
			phys = <0x56 0x00>;
			phy-names = "usb2-phy";
			usb-role-switch;
			phandle = <0xd3>;

			port {

				endpoint {
					remote-endpoint = <0x57>;
					phandle = <0x78>;
				};
			};

Turn on USB0 ethernet interface, on STM32MP157f board side
# modprobe g_ethenet
[   22.665154] using random self ethernet address
[   22.668254] using random host ethernet address
[   22.675328] usb0: HOST MAC fe:84:b8:59:9c:3a
[   22.678235] usb0: MAC 16:a6:c6:69:07:2d
[   22.682567] using random self ethernet address
[   22.686483] using random host ethernet address
[   22.691144] g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
[   22.697547] g_ether gadget: g_ether ready
[   22.701548] dwc2 49000000.usb-otg: bound driver g_ether
# [   23.064628] dwc2 49000000.usb-otg: new device is high-speed
[   23.244897] dwc2 49000000.usb-otg: new device is high-speed
[   23.414495] dwc2 49000000.usb-otg: new address 20

# ifconfig usb0 192.167.1.66 up

# ifconfig usb0
usb0      Link encap:Ethernet  HWaddr 11:22:33:44:55:66
          inet addr:192.168.1.66  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::14a6:c6ff:fe69:72d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:476 errors:0 dropped:0 overruns:0 frame:0
          TX packets:476 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:56935 (55.6 KiB)  TX bytes:565828 (552.5 KiB)
PC side
$ sudo dmesg | grep -i cdc_ether
[27492.731417] cdc_ether 3-4.3:1.0 usb0: register 'cdc_ether' at usb-0000:00:14.0-4.3, CDC Ethernet Device, fe:84:b8:59:9c:3a
[27492.744387] cdc_ether 3-4.3:1.0 enxfe84b8599c3a: renamed from usb0

$ sudo  ifconfig enxfe84b8599c3a 192.167.1.77 up

$ ifconfig enxfe84b8599c3a
enxfe84b8599c3a: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.77  netmask 255.255.255.0  broadcast 192.168.1.255
        ether 11:22:33:44:55:66  txqueuelen 1000  (Ethernet)
        RX packets 476  bytes 559164 (559.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 480  bytes 64459 (64.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ref:
1. USB Gadget Ethernet
2. 嵌入式Linux adbd实现概要梳理
3. AllWinner T113 buildroot ssh连接功能
4. How to Fix the SSH “Connection Refused” Error
5. SSH使用问题以及解决方案(expecting SSH2_MSG_KEX_ECDH_REPLY) //not work for me :(

沒有留言:

張貼留言