设为首页收藏本站
查看: 537|回复: 5

【米尔瑞萨RZ/G2L开发板-创新应用】开启ADB devices功能

[复制链接]

8

主题

12

回帖

212

积分

中级会员

积分
212
贫穷贵公子 发表于 2023-8-5 08:51:11 | 显示全部楼层 |阅读模式
本文介绍,如何在开发板上开启ADB功能,方便后期的文件上传,等功能。毕竟,ADB功能较多,调试更为方便。

包括如下步骤:
1)kernel开启ADB相关的CONFIG配置宏
1.1)yocto recipes目录结构
Snipaste_2023-08-05_08-32-29.png

1.2)USB gadget相关配置宏
  1. CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2. CONFIG_USB_MON=y
  3. USB_GADGET_DEBUG=y
  4. CONFIG_USB_GADGET_DEBUG=y
  5. CONFIG_USB_GADGET_DEBUG_FILES=y
  6. CONFIG_USB_GADGET_DEBUG_FS=y
  7. CONFIG_USB_CONFIGFS=y
  8. CONFIG_USB_FUNCTIONFS=m
  9. CONFIG_USB_G_SERIAL=m
  10. CONFIG_USB_U_ETHER=y
  11. CONFIG_USB_F_ECM=y
  12. CONFIG_USB_F_SUBSET=y
  13. CONFIG_USB_F_RNDIS=y
  14. CONFIG_USB_F_MASS_STORAGE=y
  15. CONFIG_USB_CONFIGFS_SERIAL=y
  16. CONFIG_USB_CONFIGFS_ACM=y
  17. CONFIG_USB_CONFIGFS_OBEX=y
  18. CONFIG_USB_CONFIGFS_NCM=y
  19. CONFIG_USB_CONFIGFS_ECM=y
  20. CONFIG_USB_CONFIGFS_ECM_SUBSET=y
  21. CONFIG_USB_CONFIGFS_RNDIS=y
  22. CONFIG_USB_CONFIGFS_EEM=y
  23. CONFIG_USB_CONFIGFS_MASS_STORAGE=y
  24. CONFIG_USB_CONFIGFS_F_LB_SS=y
  25. CONFIG_USB_CONFIGFS_F_FS=y
  26. CONFIG_USB_CONFIGFS_F_UAC1=y
  27. CONFIG_USB_CONFIGFS_F_MIDI=y
  28. CONFIG_USB_CONFIGFS_F_HID=y
  29. CONFIG_USB_CONFIGFS_F_UVC=y
  30. CONFIG_USB_CONFIGFS_F_PRINTER=y
复制代码
2)增加usb gadget相关的recipes文件

2.1)目录结构如下
Snipaste_2023-08-05_08-39-08.png

Snipaste_2023-08-05_08-40-41.png

增加usb-start_1.0.bb文件,用来编译以及打包usb gadget相关的配置。
2.2)由于当前开发板使用systemd管理开机自启服务,因此需要在usb-start_1.0.bb文件当中,也需要使用systemd管理开机自启服务。
2.3)usb-start_1.0.bb文件内容如下。

  1. #
  2. # USB composite device configuration
  3. #

  4. SUMMARY = "USB composite device configuration"
  5. SECTION = "examples"
  6. LICENSE = "CLOSED"

  7. SRC_URI = " \
  8.     file://launch_adbd \
  9.     file://usb_start.service \
  10.     file://usb_start.sh \
  11. "

  12. S = "${WORKDIR}"

  13. do_install() {
  14.     install -m 0755 usb_start.sh -D ${D}${sysconfdir}/init.d/usb_start.sh
  15.     install -m 0755 launch_adbd  -D ${D}${sysconfdir}/launch_adbd

  16.     install -m 0644 usb_start.service -D ${D}${systemd_unitdir}/system/usb_start.service
  17.     if [ ! -d ${D}${systemd_unitdir}/system/multi-user.target.wants  ];then
  18.         mkdir ${D}${systemd_unitdir}/system/multi-user.target.wants
  19.     else
  20.         echo ${D}${systemd_unitdir}/system/multi-user.target.wants exist
  21.     fi
  22.     ln -sf ${systemd_unitdir}/system/usb_start.service ${D}${systemd_unitdir}/system/multi-user.target.wants/usb_start.service
  23. }

  24. FILES_${PN} += "${systemd_unitdir}/system"
  25. FILES_${PN} += "${systemd_unitdir}/system/local-fs.target.wants/"
复制代码
2.4)launch_adbd文件内容如下

  1. #! /bin/sh
  2. #
  3. # Copyright (c) 2017, The Linux Foundation. All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions are
  7. # met:
  8. #   * Redistributions of source code must retain the above copyright
  9. #     notice, this list of conditions and the following disclaimer.
  10. #   * Redistributions in binary form must reproduce the above
  11. #     copyright notice, this list of conditions and the following
  12. #     disclaimer in the documentation and/or other materials provided
  13. #     with the distribution.
  14. #   * Neither the name of The Linux Foundation nor the names of its
  15. #     contributors may be used to endorse or promote products derived
  16. #     from this software without specific prior written permission.
  17. #
  18. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  19. # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  20. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  21. # ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  22. # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  25. # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  27. # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  28. # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE

  29. export TERM=linux
  30. DAEMON="adbd"
  31. PIDFILE="/var/run/$DAEMON.pid"

  32. if [ -f /etc/default/adbd ]; then
  33.     echo "/etc/default/adbd" > /dev/kmsg
  34.     . /etc/default/adbd
  35. fi
  36. echo "Launch adb is starting adbd... "
  37. start-stop-daemon -b -m -S -q -p "$PIDFILE" -x "/usr/bin/adbd"

  38. # If UDC is not set up set it up.
  39. if [ -z /sys/kernel/config/usb_gadget/g1/UDC ]; then
  40.    udcname=`ls -1 /sys/class/udc | head -n 1`
  41.    echo -n "udcname $udcname" > /dev/kmsg
  42.    echo $udcname > /sys/kernel/config/usb_gadget/g1/UDC
  43. fi

  44. echo -n "Launch adbd. done" > /dev/kmsg

  45. exit 0
复制代码
2.5)usb_start.service文件内容如下

  1. [Unit]
  2. Description=Renesas usb start
  3. After=auditd.service

  4. [Service]
  5. Type=simple
  6. RemainAfterExit=yes
  7. #Restart=on-failure
  8. #RestartSec=5s
  9. #Nice=-5
  10. ExecStart=/etc/init.d/usb_start.sh start
  11. ExecStop=/etc/init.d/usb_start.sh stop

  12. [Install]
  13. WantedBy=multi-user.target
复制代码
2.6)usb_start.sh文件内容如下

  1. #!/bin/sh

  2. DAEMON="start_usb"
  3. PIDFILE="/var/run/$DAEMON.pid"

  4. UpdateLog()
  5. {
  6.     echo "${1}" 2>&1 | tee /dev/kmsg
  7. }

  8. run_usb_configfs() {
  9.     usb_vid=0x0BB8
  10.     usb_pid=0x5300
  11.     manu_string="Renesas_Manufacturer"
  12.     prod_string="Renesas_Product"
  13.     usb_maxpower=500
  14.     #serialnum=`devmem 0x5c005238`
  15.     serialnum="123456789"
  16.     #func_str="ecm.ecm,ffs.adb,gser.0,uac1.uac1,mass_storage.0,ncm.0,rndis.rndis"
  17.     #func_str="ecm.ecm,ffs.adb,gser.0,uac1.uac1,mass_storage.0,ncm.0"
  18.     #func_str="gser.0,gser.1,gser.2,gser.3,ffs.adb,uac1.uac1"
  19.     #func_str="ecm.ecm,gser.0,ffs.adb,uac1.uac1"
  20.     #func_str="ffs.adb,uac1.uac1"
  21.     func_str="ffs.adb"

  22.     UpdateLog "start adb"
  23.     pkill adbd
  24.     /etc/launch_adbd start
  25.     sleep 1

  26.     cd /sys/kernel/config/usb_gadget/g1
  27.     echo $usb_vid > idVendor
  28.     echo $usb_pid > idProduct
  29.     echo 0xA0 > configs/c.1/bmAttributes
  30.     echo "UAC_SER_RMNET" > configs/c.1/strings/0x409/configuration
  31.     echo $manu_string > strings/0x409/manufacturer
  32.     echo $prod_string > strings/0x409/product
  33.     echo $serialnum   > strings/0x409/serialnumber
  34.     echo $usb_maxpower > /sys/kernel/config/usb_gadget/g1/configs/c.1/MaxPower

  35.     funcs=$(echo $func_str |tr "," "\n")
  36.     func_index=1
  37.     for func in $funcs
  38.     do
  39.         echo "ln $func $func_index"
  40.         ln -s functions/$func configs/c.1/f$func_index
  41.         func_index=$((func_index+1))
  42.     done
  43.     UpdateLog "binding UDC with Gadget ...\n" $1
  44.     echo $1 > UDC
  45.     cd /
  46. }

  47. start() {
  48.     UpdateLog 'Starting %s: \n' $DAEMON
  49.     #depmod
  50.     #modprobe libcomposite
  51.     #sleep 1
  52.     #mount -t configfs none /sys/kernel/config
  53.     if [ -d /sys/kernel/config/usb_gadget ];then
  54.         UpdateLog "Configuring the USB gadget using ConfigFS"
  55.         cd /sys/kernel/config/usb_gadget/
  56.         mkdir g1
  57.         cd g1
  58.         mkdir strings/0x409
  59.         mkdir configs/c.1
  60.         mkdir configs/c.1/strings/0x409
  61.         mkdir functions/mass_storage.0
  62.         mkdir functions/mass_storage.1
  63.         mkdir functions/ffs.adb
  64.         mkdir functions/gser.0
  65.         mkdir functions/gser.1
  66.         mkdir functions/gser.2
  67.         mkdir functions/gser.3
  68.         mkdir functions/ncm.0
  69.         mkdir functions/uac1.uac1
  70.         mkdir functions/rndis.rndis
  71.         mkdir functions/ecm.ecm

  72.         if [ ! -s "/etc/adb_devid" ]; then
  73.             #serialnum=`devmem 0x5c005238`
  74.             serialnum="123456789"
  75.             echo $serialnum > /etc/adb_devid
  76.             sync
  77.         fi
  78.    
  79.         udcname=`ls /sys/class/udc`
  80.         UpdateLog "udcname=$udcname"
  81.         run_usb_configfs $udcname &

  82.         cd /
  83.     fi

  84.     #mount functionfs
  85.     mkdir -p /dev/usb-ffs/adb
  86.     mount -o uid=2000,gid=2000 -t functionfs adb /dev/usb-ffs/adb
  87.     #mount -o remount,gid=5,mod=620 /dev/pts

  88.     UpdateLog "usb.service initialized successfully"
  89. }

  90. stop() {
  91.     UpdateLog 'Stopping %s: ' "$DAEMON"
  92.     if [ -d /sys/kernel/config/usb_gadget ];then
  93.         UpdateLog "Stop USB Android Gadget"
  94.         echo none > /sys/kernel/config/usb_gadget/g1/UDC
  95.         UpdateLog -n "usb.service stopped successfully"
  96.     fi
  97. }

  98. restart() {
  99.     stop
  100.     sleep 1
  101.     start
  102. }

  103. case "$1" in
  104.     start|stop|restart)
  105.         "$1";;
  106.     reload)
  107.         # Restart, since there is no true "reload" feature.
  108.         restart;;
  109.     *)
  110.         echo "Usage: $0 {start|stop|restart|reload}"
  111.         exit 1
  112. esac
复制代码
3)打包usb-start相关的recipes文件到根文件系统当中
Snipaste_2023-08-05_08-48-52.png
4)USB gadget ADB功能测试

Snipaste_2023-08-05_08-50-39.png

回复

使用道具 举报

8

主题

12

回帖

212

积分

中级会员

积分
212
 楼主| 贫穷贵公子 发表于 2023-8-5 08:59:03 | 显示全部楼层
顺便请教一个问题,当前使用123456789作为ADB设备的serialnumber,如果多个开发板同时接入一台host设备,那么就会
因为serialnumber统一,而导致无法区分adb devices。因此,需要使用SOC芯片的 Unique ID作为serialnumber。
我在r01uh0914ej0110-rzg2l-rzg2lc.pdf文件当中,并没有找到Unique ID的寄存器地址,以及读取方法,有知道的,方便告知一下,
万分感谢!!!
回复 支持 反对

使用道具 举报

8

主题

12

回帖

212

积分

中级会员

积分
212
 楼主| 贫穷贵公子 发表于 2023-8-17 22:32:58 | 显示全部楼层
找到了这个寄存器,LSI Device ID Register (SYS_DEVID)
设备ID,devmem 0x11020A04
root@myir-yg2lx-1g:/lib/systemd/system# devmem 0x11020A04
0x4841C447
回复 支持 反对

使用道具 举报

1

主题

3

回帖

71

积分

注册会员

积分
71
lint019 发表于 2024-3-5 23:21:22 | 显示全部楼层
你能上传一下adbd这个执行文件吗?多谢!
回复 支持 反对

使用道具 举报

1

主题

3

回帖

71

积分

注册会员

积分
71
lint019 发表于 2024-3-6 15:31:55 | 显示全部楼层
lint019 发表于 2024-3-5 23:21
你能上传一下adbd这个执行文件吗?多谢!

我已经编译好了,见附件。哈哈。

结合上面的步骤,可以使用adb了

adbd.zip

50.04 KB, 下载次数: 14

回复 支持 反对

使用道具 举报

8

主题

12

回帖

212

积分

中级会员

积分
212
 楼主| 贫穷贵公子 发表于 2024-3-28 12:00:14 | 显示全部楼层
yocto构建系统当中,增加一个android-tools依赖,即可。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录

本版积分规则

Archiver|手机版|小黑屋|米尔科技论坛   

GMT+8, 2024-4-28 07:10 , Processed in 0.050951 second(s), 23 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表