linux下adb及fastboot编译与使用

  • 1、下载android system core代码:

git clone https://android.googlesource.com/platform/system/core.git

  • 2、编译fastboot

进入system/core/fastboot

gcc -o fastboot usb_linux.c util_linux.c fastboot.c protocol.c engine.c bootimg.c  ../libzipfile/zipfile.c ../libzipfile/centraldir.c -I../include -I../libzipfile -I../mkbootimg -lz

  • 3、fastboot修改:

根据你的设备pid/vid,protocal subClass属性修改fastboot.c

qiao@qiao-desktop:/sys/bus/usb/devices/1-6:1.0$ cat bInterfaceSubClass 

42

qiao@qiao-desktop:/sys/bus/usb/devices/1-6:1.0$ cat bInterfaceProtocol 

03

qiao@qiao-desktop:/sys/bus/usb/devices/1-6:1.0$ cat bInterfaceClass 

ff

fastboot.c

int match_fastboot(usb_ifc_info *info)
{
    if(!(vendor_id && (info->dev_vendor == vendor_id)) &&
       (info->dev_vendor != 0x18d1) &&  // Google
       (info->dev_vendor != 0x0451) &&
(info->dev_vendor != 0x1c9e) &&
       (info->dev_vendor != 0x0fce) &&  // Sony Ericsson
       (info->dev_vendor != 0x05c6) &&  // Qualcomm
       (info->dev_vendor != 0x22b8) &&  // Motorola
       (info->dev_vendor != 0x0955) &&  // Nvidia
       (info->dev_vendor != 0x413c) &&  // DELL
       (info->dev_vendor != 0x0bb4))    // HTC
            return -1;
    if(info->ifc_class != 0xff) return -1;
    if(info->ifc_subclass != 0x42) return -1;
    if(info->ifc_protocol != 0x03) return -1;

    // require matching serial number if a serial number is specified
    // at the command line with the -s option.
    if (serial && strcmp(serial, info->serial_number) != 0) return -1;
    return 0;
}

  • 4、编译adb
根据system/core/adb/android.mk添加Makefile,注意区分哪些是编译Adb的,哪些是编译adbd的。
# Makefile for adb
 
SRCS+= adb.c
SRCS+= adb_client.c
SRCS+= commandline.c
SRCS+= console.c
SRCS+= file_sync_client.c
SRCS+= fdevent.c
SRCS+= get_my_path_linux.c
SRCS+= services.c
SRCS+= sockets.c
SRCS+= transport.c
SRCS+= transport_local.c
SRCS+= transport_usb.c
SRCS+= usb_linux.c
SRCS+= usb_vendors.c
SRCS+= utils.c
#SRCS+= usb_linux_client.c
SRCS+= adb_auth_host.c
#SRCS+= adb_auth_client.c
#SRCS+= sysdeps_win32.c
 
VPATH+= ../libcutils
SRCS+= abort_socket.c
SRCS+= socket_inaddr_any_server.c
SRCS+= socket_local_client.c
SRCS+= socket_local_server.c
SRCS+= socket_loopback_client.c
SRCS+= socket_loopback_server.c
SRCS+= socket_network_client.c
SRCS+= load_file.c 
SRCS+= list.c
 
VPATH+= ../libzipfile
SRCS+= centraldir.c
SRCS+= zipfile.c


#VPATH+= ../libunz
#SRCS+= abort_socket.c
#SRCS+= socket_inaddr_any_server.c
#SRCS+= socket_local_client.c
#SRCS+= socket_local_server.c
#SRCS+= socket_loopback_client.c
#SRCS+= socket_loopback_server.c
#SRCS+= socket_network_client.c
 
CPPFLAGS+= -DADB_HOST=1
CPPFLAGS+= -DHAVE_FORKEXEC=1
CPPFLAGS+= -DHAVE_SYMLINKS
CPPFLAGS+= -DHAVE_TERMIO_H
CPPFLAGS+= -D_GNU_SOURCE
CPPFLAGS+= -D_XOPEN_SOURCE
CPPFLAGS+= -I.
CPPFLAGS+= -I../include
CPPFLAGS+= -I../libzipfile
#CPPFLAGS+= -I../mkbootimg
#CPPFLAGS+= -I../mincrypt
#CPPFLAGS+= -I../../../external/zlib
 
CFLAGS+= -O2 -Wno-unused-parameter
LDFLAGS= 
LIBS= -lrt -lpthread -lz -lcrypto -ldl   -lssl
 
#TOOLCHAIN= mipsel-unknown-linux-gnu-
CC= $(TOOLCHAIN)gcc
LD= $(TOOLCHAIN)gcc
 
OBJS= $(SRCS:.c=.o)
 
all: adb
 
adb: $(OBJS)
$(LD) -o $@ $(LDFLAGS) $(OBJS) $(LIBS)
 
clean:
rm -rf $(OBJS)
  • 5、修改adb

修改usb_vendor.c,将自己的设备vid加入即可。

你可能感兴趣的:(android,usb,linux)