Refer to:
1. http://fatalfeel.blogspot.com/2015/12/openocd-with-eclipse-debug-kernel-of.html
2. http://fatalfeel.blogspot.com/2013/09/debug-android-framework-and-service-in.html
3. https://www.cnblogs.com/mauricewei/p/10502300.html
4. https://zhuanlan.zhihu.com/p/344526925
5. http://www.mediafire.com/file/0adoj9isttdtod4/kernel_imx_aarch64.tar.gz
Kernel debug we choosing jtag and wpa_supplicant choosing otg
1. rtl8723BU_WiFi module change to build in driver for debugging easier
gedit ~/OK8MM-android/vendor/nxp-opensource/kernel_imx/arch/arm64/configs/android_defconfig
CONFIG_RTL8723BU=m
//change to
CONFIG_RTL8723BU=y
2. cancel depmod module load in android
gedit ~/OK8MM-android/device/fsl/imx8m/evk_8mm/BoardConfig.mk
BOARD_VENDOR_KERNEL_MODULES += $(KERNEL_OUT)/drivers/net/wireless/realtek/rtl8723BU_WiFi/8723bu.ko
//comment to
# BOARD_VENDOR_KERNEL_MODULES += $(KERNEL_OUT)/drivers/net/wireless/realtek/rtl8723BU_WiFi/8723bu.ko
3. wifi in kernel have those main trunks
(a) ~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi
(b) ~/OK8MM-android/vendor/nxp-opensource/kernel_imx/net/core
(c) ~/OK8MM-android/vendor/nxp-opensource/kernel_imx/net/ipv4
(d) ~/root/OK8MM-android/vendor/nxp-opensource/kernel_imx/net/wireless
Add this flag to those Makefile
KBUILD_CFLAGS += -O1
4. wpa_supplicant setting
~/OK8MM-android/external/wpa_supplicant_8/Android.mk
//find
LOCAL_MODULE := wpa_supplicant
//add flags before "include $(BUILD_EXECUTABLE)"
LOCAL_CFLAGS += -O1 -g
LOCAL_CPPFLAGS += -O1 -g
LOCAL_STRIP_MODULE := false
5. add file ~/OK8MM-android/external/wpa_supplicant_8/wpa_supplicant/gdb-androidx.cmds for eclipse [GDB command file]
//add follows
set directories $cwd:/root/OK8MM-android:/root/OK8MM-android/external/wpa_supplicant_8/src/drivers
set solib-absolute-prefix /root/OK8MM-android/out/target/product/evk_8mm/symbols
set solib-search-path /root/OK8MM-android/out/target/product/evk_8mm/symbols/system/lib64:/root/OK8MM-android/out/target/product/evk_8mm/symbols/vendor/lib64:/root/OK8MM-android/out/target/product/evk_8mm/symbols/system/bin:/root/OK8MM-android/out/target/product/evk_8mm/symbols/vendor/bin:/root/OK8MM-android/out/target/product/evk_8mm/symbols/vendor/bin/hw
###########################################################
#####################kernel init sequence#####################
###########################################################
flow chart for NAPI(New API):
(a.) hardware interrupt to software interrupt
https://pic2.zhimg.com/v2-2222b699f2c3e300ac185a7ef9b095a1_r.jpg
(b.) after software interrupt NET_RX_SOFTIRQ, cpu process data
https://pic4.zhimg.com/v2-58a4c3029661fc274e5d2e33e4097433_r.jpg
1. configuration API for 802.11 devices
OK8MM-android/vendor/nxp-opensource/kernel_imx/net/wireless/core.c
static int __init cfg80211_init(void)
{
...
}
2. usb to realtek driver
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/usb/core/driver.c
static int usb_probe_interface(struct device *dev)
{
...
error = driver->probe(intf, id);
...
}
//goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/os_dep/linux/usb_intf.c
_adapter *rtw_usb_primary_adapter_init(struct dvobj_priv *dvobj, struct usb_interface *pusb_intf)
{
...
if (rtw_set_hal_ops(padapter) == _FAIL)
...
}
//goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/hal/rtl8723b/usb/usb_halinit.c
void rtl8723bu_set_hal_ops(_adapter *padapter)
{
...
rtl8723b_set_hal_ops(pHalFunc);
...
}
//goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/hal/rtl8723b/rtl8723b_hal_init.c
void rtl8723b_set_hal_ops(struct hal_ops *pHalFunc)
{
...
}
3.
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/os_dep/linux/usb_intf.c
static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
{
...
padapter = rtw_usb_primary_adapter_init(dvobj, pusb_intf);
...
}
//through some functions then goto
_adapter *rtw_usb_primary_adapter_init(struct dvobj_priv *dvobj, struct usb_interface *pusb_intf)
{
...
//_adapter refer to struct _ADAPTER of drv_types.h
padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter));
..
}
//through some functions then goto
OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/os_dep/linux/os_intfs.c
int rtw_os_ndevs_register(struct dvobj_priv *dvobj)
{
...
status = rtw_os_ndev_register(adapter, name);
...
}
//through some functions then goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/os_dep/linux/os_intfs.c
int rtw_os_ndev_register(_adapter *adapter, const char *name)
{
...
netif_napi_add(ndev, &adapter->napi, rtw_recv_napi_poll, RTL_NAPI_WEIGHT);
...
}
//through some functions then goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/net/core/dev.c
void netif_napi_add(struct net_device *dev, struct napi_struct *napi, int (*poll)(struct napi_struct *, int), int weight)
{
...
napi->poll = poll; //poll = <rtw_recv_napi_poll>
...
napi_hash_add(napi);
}
###########################################################
#####################kernel recv sequence####################
###########################################################
1.
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/include/linux/skbuff.h
struct sk_buff {
...
};
2. malloc struct sk_buff
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/os_dep/osdep_service.c
inline struct sk_buff *_rtw_skb_alloc(u32 sz)
{
#ifdef PLATFORM_LINUX
return __dev_alloc_skb(sz, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
#endif /* PLATFORM_LINUX */
...
}
3. realtek recvbuf
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/os_dep/linux/usb_ops_linux.c
void usb_recv_tasklet(void *priv)
{
...
recvbuf2recvframe(padapter, pskb);
...
}
//goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/hal/rtl8723b/usb/usb_ops.c
{
...
pre_recv_entry(precvframe, pattrib->physt ? (pbuf + RXDESC_OFFSET) : NULL);
...
}
//goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/core/rtw_recv.c
s32 pre_recv_entry(union recv_frame *precvframe, u8 *pphy_status)
{
...
ret = rtw_recv_entry(precvframe);
...
}
//goto
s32 rtw_recv_entry(union recv_frame *precvframe)
{
...
ret = recv_func(padapter, precvframe);
...
}
//goto
int recv_func(_adapter *padapter, union recv_frame *rframe)
{
...
ret = recv_func_posthandle(padapter, rframe);
...
}
//goto
int recv_func_posthandle(_adapter *padapter, union recv_frame *prframe)
{
...
ret = process_recv_indicatepkts(padapter, prframe);
...
}
//goto
int process_recv_indicatepkts(_adapter *padapter, union recv_frame *prframe)
{
...
if (recv_indicatepkt_reorder(padapter, prframe) != _SUCCESS)
...
}
4. schedule
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/os_dep/linux/recv_linux.c
int rtw_recv_indicatepkt(_adapter *padapter, union recv_frame *precv_frame)
{
...
rtw_os_recv_indicate_pkt(padapter, skb, pattrib);
...
}
void rtw_os_recv_indicate_pkt(_adapter *padapter, _pkt *pkt, struct rx_pkt_attrib *pattrib)
{
...
napi_schedule(&padapter->napi); // padapter->napi->poll = rtw_recv_napi_poll
...
}
5. tcp ipv4 get buff
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/net/core/dev.c
static int napi_poll(struct napi_struct *n, struct list_head *repoll)
{
...
work = n->poll(n, weight); //poll = rtw_recv_napi_poll
...
}
//goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/os_dep/linux/recv_linux.c
int rtw_recv_napi_poll(struct napi_struct *napi, int budget)
{
...
work_done = napi_recv(padapter, budget);
...
}
//goto
static int napi_recv(_adapter *padapter, int budget)
{
...
if (rtw_napi_gro_receive(&padapter->napi, pskb) != GRO_DROP)
...
}
//through some functions then goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/net/ipv4/ip_input.c
int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
{
...
return NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING,
net, NULL, skb, dev, NULL,
ip_rcv_finish);
...
}
//goto
static int ip_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb)
{
...
return dst_input(skb);
...
}
//goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/net/ipv4/tcp_ipv4.c
int tcp_v4_rcv(struct sk_buff *skb)
{
...
}
##################################################
######################wifi ioctl#####################
##################################################
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/net/core/dev_ioctl.c
int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
{
...
return wext_handle_ioctl(net, &iwr, cmd, arg);
...
}
//goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/net/wireless/wext-core.c wext_handle_ioctl(struct net *net, struct iwreq *iwr, unsigned int cmd, void __user *arg)
{
...
ret = wext_ioctl_dispatch(net, iwr, cmd, &info,
...
}
//goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/net/wireless/wext-core.c
static int wext_ioctl_dispatch(struct net *net, struct iwreq *iwr,
{
...
ret = wireless_process_ioctl(net, iwr, cmd, info, standard, private);
...
}
//goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/net/wireless/wext-core.c
static int wireless_process_ioctl(struct net *net, struct iwreq *iwr,
unsigned int cmd,
struct iw_request_info *info,
wext_ioctl_func standard,
wext_ioctl_func private)
{
...
handler = get_handler(dev, cmd);
...
}
//goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/net/wireless/wext-core.c
static iw_handler get_handler(struct net_device *dev, unsigned int cmd)
{
...
return handlers->private[index];
...
}
//goto
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/os_dep/linux/ioctl_linux.c
struct iw_handler_def rtw_handlers_def = {
...
.private = rtw_private_handler,
...
}
~/OK8MM-android/vendor/nxp-opensource/kernel_imx/drivers/net/wireless/realtek/rtl8723BU_WiFi/os_dep/linux/ioctl_linux.c
static iw_handler rtw_private_handler[] = {
rtw_wx_write32, /* 0x00 */
rtw_wx_read32, /* 0x01 */
rtw_drvext_hdl, /* 0x02 */
...
}
###########################################################
#####################wpa_supplicant recv sequence#############
###########################################################
1.
~/OK8MM-android/external/wpa_supplicant_8/wpa_supplicant/wpa_supplicant.c
static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s, struct wpa_interface *iface)
{
...
if (wpas_init_driver(wpa_s, iface) < 0)
...
}
//goto
static int wpas_init_driver(struct wpa_supplicant *wpa_s, struct wpa_interface *iface)
{
...
if (wpa_supplicant_set_driver(wpa_s, driver) < 0)
...
}
~/OK8MM-android/external/wpa_supplicant_8/wpa_supplicant/src/drivers/driver_nl80211.c
static void * nl80211_global_init(void *ctx)
{
...
if (wpa_driver_nl80211_init_nl_global(global) < 0)
...
}
//goto
static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
{
...
global->nl = nl_create_handle(global->nl_cb, "nl");
...
}
//goto
static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg)
{
...
if (genl_connect(handle))
...
}
//goto
~/OK8MM-android/external/libnl/lib/nl.c
int nl_connect(struct nl_sock *sk, int protocol)
{
...
sk->s_fd = socket(AF_NETLINK, SOCK_RAW | flags, protocol);
...
}
2.
~/OK8MM-android/external/wpa_supplicant_8/wpa_supplicant/src/drivers/driver_nl80211.c
static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, void *handle)
{
...
res = nl_recvmsgs(handle, cb);
...
}
//goto
~/OK8MM-android/external/libnl/lib/nl.c
int nl_recvmsgs_report(struct nl_sock *sk, struct nl_cb *cb)
{
...
return recvmsgs(sk, cb);
}
//through some functions then goto
~/OK8MM-android/external/wpa_supplicant_8/wpa_supplicant/events.c
void wpa_supplicant_event(void *ctx, enum wpa_event_type event, union wpa_event_data *data)
{
...
}
作者已經移除這則留言。
回覆刪除