From c766190cf18c6c437ba3bf411077af6d7760e225 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Wed, 26 Jul 2023 16:30:46 +0800
Subject: [PATCH] Add build driver support

---
 kernel/drivers/user/Makefile |   37 ++++++++++++
 .gitignore                   |    1 
 kernel/build.sh              |   64 ++++++++++++++++++--
 kernel/drivers/user/hello.c  |   35 +++++++++++
 4 files changed, 129 insertions(+), 8 deletions(-)

diff --git a/.gitignore b/.gitignore
index 625ce24..0de544e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,3 +9,4 @@
 kirkstone/
 langdale/
 images/rootfs-*
+rtl8188fu/
diff --git a/kernel/build.sh b/kernel/build.sh
index 774d1f2..ed540c8 100755
--- a/kernel/build.sh
+++ b/kernel/build.sh
@@ -156,14 +156,64 @@
     make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} -j ${JOBS}
 }
 
-function build_driver()
+function build_driver_wifi()
 {
-    SRC=drivers
+    cd $PRJ_PATH/drivers
 
-    pr_info "Start build linux drivers"
-    cd $PRJ_PATH/${SRC}
+    if [[ $BOARD =~ 6ull ]] ; then
+        SRC=rtl8188fu
+
+        pr_info "Start build $SRC driver for $BOARD"
+
+        if [ ! -d $SRC ] ; then
+            if [ ! -s $TARBALL_PATH/$SRC.tar.xz ] ; then
+                pr_info "start fetch $SRC source code"
+                wget $URL/bsp/misc/$SRC.tar.xz -P $TARBALL_PATH
+            fi
+
+            do_unpack $TARBALL_PATH/$SRC.tar.xz
+        fi
+
+        cd $SRC
+
+        # Remove noisy debug print information
+        sed -i "s|^#define CONFIG_DEBUG|//#define CONFIG_DEBUG|g" include/autoconf.h
+        sed -i "/nolinked power/d" core/rtw_pwrctrl.c
+        sed -i "/request firmware/d" hal/rtl8188f/rtl8188f_hal_init.c
+
+        make KSRC=$KER_PATH M=$PWD -j ${JOBS}
+        make -C $KER_PATH M=$PWD modules_install INSTALL_MOD_PATH=$INST_PATH INSTALL_MOD_STRIP=1
+
+        mkdir -p $INST_PATH/lib/firmware/rtlwifi/
+        cp firmware/rtl8188fufw.bin $INST_PATH/lib/firmware/rtlwifi/
+    fi
 }
 
+function build_driver_user()
+{
+    cd $PRJ_PATH/drivers/user
+
+    pr_info "Start build user driver for $BOARD"
+    make -C $KER_PATH M=$PWD
+    make -C $KER_PATH M=$PWD modules_install INSTALL_MOD_PATH=$INST_PATH INSTALL_MOD_STRIP=1
+}
+
+function install_drv_kernel()
+{
+    # Install linux kernel modules
+
+    cd $KER_PATH
+    make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} modules_install INSTALL_MOD_PATH=$INST_PATH INSTALL_MOD_STRIP=1
+}
+
+function build_driver()
+{
+    install_drv_kernel
+
+    build_driver_user
+
+    build_driver_wifi
+}
 
 function do_install()
 {
@@ -191,9 +241,6 @@
         set +x
     fi
 
-    # Install linux kernel modules
-    make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} modules_install INSTALL_MOD_PATH=$INST_PATH INSTALL_MOD_STRIP=1
-
     # List install information
     pr_info "\nlinux kernel installed to '$INST_PATH'"
     ls $INST_PATH && echo ""
@@ -207,7 +254,7 @@
 
     do_install
 
-    #build_driver
+    build_driver
 }
 
 function do_clean()
@@ -219,6 +266,7 @@
         rm -rf $PRJ_PATH/$d
     done
 
+    rm -rf drivers/rtl8188fu/
     rm -rf $TARBALL_PATH
     rm -rf $INST_PATH
 }
diff --git a/kernel/drivers/user/Makefile b/kernel/drivers/user/Makefile
new file mode 100644
index 0000000..3b236cf
--- /dev/null
+++ b/kernel/drivers/user/Makefile
@@ -0,0 +1,37 @@
+#*********************************************************************************
+#      Copyright:  (C) 2021 LingYun IoT System Studio
+#                  All rights reserved.
+#
+#       Filename:  Makefile
+#    Description:  This Makefile used to compile all the drivers here
+#
+#        Version:  1.0.0(18/12/2021~)
+#                  Author:  Guo Wenxue <guowenxue@gmail.com>
+#      ChangeLog:  1, Release initial version on "18/12/2021 01:29:33 PM"
+#
+#********************************************************************************/
+
+LINUX_SRC ?= ${shell pwd}/../../linux-imx/
+INST_PATH ?= ${shell pwd}/../../install
+
+EXTRA_INSTPATH=/tftp
+
+PWD := $(shell pwd)
+
+obj-m += hello.o
+
+modules:
+	@echo ${LINUX_SRC}
+	@make -C $(LINUX_SRC) M=$(PWD) modules
+	@make -C $(LINUX_SRC) M=$(PWD) modules_install INSTALL_MOD_PATH=${INST_PATH} INSTALL_MOD_STRIP=1
+	@make clear
+
+install:
+	cp -af *.ko ${EXTRA_INSTPATH}
+
+clear:
+	@rm -f *.o *.mod* .*.cmd *.symvers *.order
+
+clean: clear
+	@rm -f  *.ko
+
diff --git a/kernel/drivers/user/hello.c b/kernel/drivers/user/hello.c
new file mode 100644
index 0000000..49acb63
--- /dev/null
+++ b/kernel/drivers/user/hello.c
@@ -0,0 +1,35 @@
+/*********************************************************************************
+ *      Copyright:  (C) 2021 LingYun IoT System Studio <www.weike-iot.com>
+ *                  All rights reserved.
+ *
+ *       Filename:  hello.c
+ *    Description:  This file is the linux kernel sample hello module 
+ *                 
+ *        Version:  1.0.0(18/12/2021~)
+ *         Author:  Guo Wenxue <guowenxue@gmail.com>
+ *      ChangeLog:  1, Release initial version on "18/12/2021 10:50:26 AM"
+ *                 
+ ********************************************************************************/
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+
+static __init int hello_init(void)
+{
+    printk(KERN_ALERT "Hello, LingYun IoT System Studio!\n");
+    return 0;
+}
+
+static __exit void hello_exit(void)
+{
+    printk(KERN_ALERT "Goodbye, I have found a good job!\n");
+}
+
+module_init(hello_init);
+module_exit(hello_exit);
+
+MODULE_AUTHOR("GuoWenxue <guowenxue@gmail.com>");
+MODULE_DESCRIPTION("Linux Kernel hello module");
+MODULE_LICENSE("Dual BSD/GPL");
+MODULE_INFO(intree, "Y");

--
Gitblit v1.9.1