导航

    全志在线开发者论坛

    • 注册
    • 登录
    • 搜索
    • 版块
    • 话题
    • 在线文档
    • 社区主页

    【FAQ】全志R329 Tina中如何使用adb/串口密码登录?

    其它全志芯片讨论区
    r329 r328 r16 faq 技术支持
    1
    1
    2920
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • q1215200171
      budbool LV 9 最后由 q1215200171 编辑

      如果需要在adb shell密码登录命令行终端,可按以下步骤进行操作。

      /etc/shadow 文件,用于存储 Linux 系统中用户的密码信息,又称为“影子文件”。

      文件中每行代表一个用户,同样使用 “:” 作为分隔符,不同之处在于,每行用户信息被划分为 9 个字段。每个字段的含义如下:

      用户名:加密密码:最后一次修改时间:最小修改时间间隔:密码有效期:密码需要变更前的警告天数:密码过期后的宽限时间:账号失效时间:保留字段

      adb 设置密码登录,操作如下:

      1、创建密码:

      这个操作可通过 makepasswd 工具创建,命令如下:

      makepasswd  --clearfrom=-  --crypt-md5 <<< YourPass
      
      eg:
      usr # makepasswd  --clearfrom=-  --crypt-md5 <<< allwinner
      allwinner   $1$z6v447Dx$HH4Ytv0Hvi5MfxVgQ6uSE.
      

      2、填充 /etc/shadow 文件:

      在 target/allwinner/方案名/base-file/etc/shadow 文件中,添加如下信息,第二字段的信息就是上述 makepasswd 创建的密码密文:

      root:$1$z6v447Dx$HH4Ytv0Hvi5MfxVgQ6uSE.:1:0:99999999999:7:::
      

      3、修改 adb_shell 文件:

      在 tina/package/utils/adb 目录下,修改当前目录的 adb_shell 文件,将该文件的 /bin/sh 替换为 /bin/login;

      4、执行 make menuconfig

      在 Base system —> <> busybox —> Login/Password Management Utilities —> [] login,按照上述路径选上 login;

      5、重新编译烧写固件

      adb shell命令之后将会需要输入用户名和密码,上述的例子,用户名为:root,密码为:allwinner;

      注意:上述的操作,只是 adb shell 需要登录密码,在串口端仍不需要登录密码。

      串口端也进行密码登录的操作

      如果在串口端也需要进行相应的密码登录验证,需要修改 /etc/inittab 这个文件。在 target/allwinner/方案名/base-file/etc 目录下存在 inittab 文件,原文件如下:

      ::sysinit:/etc/init.d/rcS S boot
      ::shutdown:/etc/init.d/rcS K shutdown
      ::askconsole:/bin/ash --login
      

      修改为

      ::sysinit:/etc/init.d/rcS S boot
      ::shutdown:/etc/init.d/rcS K shutdown
      ::askconsole:/bin/login
      

      使串口终端通过 login 登录,注意,这个一样需要 login 的支持,所以 busybox 需要选上 login(参照上述adb的第 4 点选上 login)。

      通过公私钥的加密验证方式登录 adb 终端

      ubuntu 系统,~/.ssh 目录下,会存在一个 adb 使用的公私钥,分别是 id_rsa.pub 和 id_rsa ,而 windows 则是在系统盘的 user 目录下有 .android 目录存放公私钥。将 PC 端的公钥添加到设备端的某个路径,设备端的服务开启公私钥加密验证的方式,在使用 adb 的时候,将需要使用 PC 端的秘钥和设备端的公钥进行验证,验证通过之后才可以通过 adb 进入设备终端。
      当前 Tina 系统有支持通过adb的公私钥进行验证的,patch 如下:

      diff --git a/utils/adb/Makefile b/utils/adb/Makefile
      index c57fc6b..28c4ddb 100755
      --- a/utils/adb/Makefile
      +++ b/utils/adb/Makefile
      @@ -133,6 +133,9 @@ define Package/adbd_auth_service/install
              $(INSTALL_DIR) $(1)/bin
              $(INSTALL_BIN) $(PKG_BUILD_DIR)/auth/adbd_auth_service $(1)/bin/
       
      +       $(INSTALL_DIR) $(1)/etc
      +       $(INSTALL_DATA) ./id_rsa.pub $(1)/etc/
      +
              $(INSTALL_DIR) $(1)/etc/init.d
              if [[ $(KERNEL_PATCHVER) == 4.* ]]; then \
                $(INSTALL_BIN) ./adbd-configfs.init $(1)/etc/init.d/adbd; \
      diff --git a/utils/adb/auth/Makefile b/utils/adb/auth/Makefile
      index efc4816..c68e22c 100755
      --- a/utils/adb/auth/Makefile
      +++ b/utils/adb/auth/Makefile
      @@ -22,7 +22,7 @@ $(ADB_AUTH_LIB): $(LIB_OBJS)
              $(CC) -shared $(LOCAL_CFLAGS) $(LDFLAGS) -lev $^ -o $@
       
       $(ADB_AUTH_SERVICE): $(SERVICE_OBJS)
      -       $(CC) $(LDFLAGS) $(SERVICE_LIB) $^ -o $@
      +       $(CC) $(LDFLAGS) $(SERVICE_LIB) $^ -o $@ -lm
       
       lib:$(ADB_AUTH_LIB)
       
      diff --git a/utils/adb/auth/aw_adb_auth.c b/utils/adb/auth/aw_adb_auth.c
      index 24519f7..9817bee 100644
      --- a/utils/adb/auth/aw_adb_auth.c
      +++ b/utils/adb/auth/aw_adb_auth.c
      @@ -29,6 +29,37 @@ static int debug_mask = 0;
       static pubkey_detector_t g_pubkey_detector_func;
       static char *g_key_path = DEFAULT_KEY_PATH;
       
      +/*
      + * Copy src to string dst of size siz.  At most siz-1 characters
      + * will be copied.  Always NUL terminates (unless siz == 0).
      + * Returns strlen(src); if retval >= siz, truncation occurred.
      + */
      +size_t
      +strlcpy(char *dst, const char *src, size_t siz)
      +{
      +        char *d = dst;
      +        const char *s = src;
      +        size_t n = siz;
      +
      +        /* Copy as many bytes as will fit */
      +        if (n != 0) {
      +                while (--n != 0) {
      +                        if ((*d++ = *s++) == '\0')
      +                                break;
      +                }
      +  }
      +
      +        /* Not enough room in dst, add NUL and traverse rest of src */
      +        if (n == 0) {
      +                if (siz != 0)
      +                        *d = '\0';              /* NUL-terminate dst */
      +                while (*s++)
      +                        ;
      +        }
      +
      +        return(s - src - 1);    /* count does not include NUL */
      +}
      +
       void free_environment(const char *env[], int num)
       {
              int i;
      diff --git a/utils/adb/auth/aw_adb_auth_service.c b/utils/adb/auth/aw_adb_auth_service.c
      index 17a5c85..e8da189 100644
      --- a/utils/adb/auth/aw_adb_auth_service.c
      +++ b/utils/adb/auth/aw_adb_auth_service.c
      @@ -17,7 +17,7 @@ static bool publickey_detector(const char *pubkey, int len)
       {
              char *ptr = NULL;
              printf("get public key:\n%s\n", pubkey);
      -       ptr = strstr(pubkey, "forevercai");
      +       ptr = strstr(pubkey, "chengwei");
              if (!ptr)
                      return false;
              return true;
      @@ -35,14 +35,14 @@ int main()
                      printf("aw_adbd_create failed\n");
                      return -1;
              }
      -       /*aw_adbd_set_key_path(handle, "/opt/adb_keys");*/
      +       aw_adbd_set_key_path(handle, "/etc/id_rsa.pub");
              ret = aw_adbd_start(handle);
              if (ret != 0) {
                      printf("aw_adbd_start failed\n");
                      return -1;
              }
       
      -       /*aw_adbd_install_pubkey_detector(publickey_detector); */
      +       aw_adbd_install_pubkey_detector(publickey_detector);
              aw_adbd_event_loop(handle);
              printf("adbd_auth_service finish\n");
       }
      

      在上述的patch中,解析如下:

      • utils/adb/Makefile 中的修改,主要是将公钥文件拷贝到机器端,在使用adb功能时将会使用到公钥文件;
      • aw_adbd_set_key_path(handle, “/etc/id_rsa.pub”); 则是告知adb服务,公钥保存在机器端的位置;
      • aw_adbd_install_pubkey_detector(publickey_detector); 则是增加公钥的检查,在 publickey_detector() 中检查一下公钥,是否是正确的;

      按照上述配置修改编译之后,可验证只有 PC 端存在和设备端匹配的私钥才可以通过 adb 登录设备终端。

      附件:FlameGraph.tar.xz

      1 条回复 最后回复 回复 引用 分享 3
      • Referenced by  q1215200171 q1215200171 
      • Referenced by  q1215200171 q1215200171 
      • Referenced by  q1215200171 q1215200171 
      • Referenced by  q1215200171 q1215200171 
      • Referenced by  q1215200171 q1215200171 
      • Referenced by  Gadyellow Gadyellow 
      • Referenced by  whycan whycan 
      • Referenced by  whycan whycan 
      • 1 / 1
      • First post
        Last post

      Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

      行为准则 | 用户协议 | 隐私权政策