xref: /openwifi/doc/app_notes/drv_fpga_dynamic_loading.md (revision 7eea29887ac31c48428f5ca2004418fc9511987e)
170cedb22SXianjun JiaoThe **wgd.sh** (running on board) supports reloading driver and/or FPGA image dynamically without rebooting/power-cycle. It can work in a
240773b78SXianjun Jiaoflexible way.
340773b78SXianjun Jiao
470cedb22SXianjun JiaoThe purpose of this feature is to help you easily reload driver and FPGA built from your branch/version/variant/modification, and switch/run different driver and FPGA of different branch/version/variant/modification without rebooting. To enjoy this feature, always ensure your onboard openwifi/files are the latest files in [user_space](../../user_space)).
570cedb22SXianjun Jiao
640773b78SXianjun Jiao- [[Reload driver only](#Reload-driver-only)]
740773b78SXianjun Jiao- [[Reload driver and FPGA](#Reload-driver-and-FPGA)]
840773b78SXianjun Jiao- [[Reload driver and FPGA in target directory](#Reload-driver-and-FPGA-in-target-directory)]
970cedb22SXianjun Jiao- [[Reload driver and FPGA from a single package file](#Reload-driver-and-FPGA-from-a-single-package-file)] -- **RECOMMENDED!**
102576903aSJiao Xianjun- [[Suggested practice to generate driver FPGA variants](#Suggested-practice-to-generate-driver-FPGA-variants)]
1140773b78SXianjun Jiao- [[Detailed full usage info](#Detailed-full-usage-info)]
1240773b78SXianjun Jiao
13e41746cbSJiao XianjunNote: Make sure you have compiled driver before. Check [Update Driver](../../README.md#update-driver).
14e41746cbSJiao Xianjun
1540773b78SXianjun Jiao## Reload driver only
16f3d767acSJiao XianjunThis is the original way. To let **wgd.sh** only loads the driver without touching FPGA, please ensure FPGA image file **system_top.bit.bin** is **NOT**
1740773b78SXianjun Jiaopresent in the directory. If wgd.sh can not find the FPGA image, it will skip reloading it.
1840773b78SXianjun Jiao
1940773b78SXianjun Jiao## Reload driver and FPGA
2040773b78SXianjun Jiao- Generate the reloadable FPGA file **system_top.bit.bin**. In the Linux host computer:
2140773b78SXianjun Jiao  ```
2240773b78SXianjun Jiao  cd openwifi/user_space
23*7eea2988SXianjun Jiao  ./drv_and_fpga_package_gen.sh $OPENWIFI_HW_IMG_DIR $XILINX_DIR $BOARD_NAME
2440773b78SXianjun Jiao  ```
2570cedb22SXianjun Jiao  Then **system_top.bit.bin** will be generated in openwifi/user_space.
262576903aSJiao Xianjun
2740773b78SXianjun Jiao- Put **system_top.bit.bin** on board in the same directory as wgd.sh and other driver files (.ko)
2840773b78SXianjun Jiao- Run **wgd.sh** on board as usual
2940773b78SXianjun Jiao
3040773b78SXianjun Jiao## Reload driver and FPGA in target directory
3140773b78SXianjun JiaoPut **system_top.bit.bin** on board together with other driver files (.ko) in a directory ($TARGET_DIR), then run on board:
3240773b78SXianjun Jiao```
3340773b78SXianjun Jiao./wgd.sh $TARGET_DIR
3440773b78SXianjun Jiao```
3540773b78SXianjun JiaoIn this way, different versions/variants of driver/FPGA can be put in different directories. Then **wgd.sh** can be used to switch
3640773b78SXianjun Jiaobetween them without rebooting/power-cycle.
3740773b78SXianjun Jiao
3840773b78SXianjun Jiao## Reload driver and FPGA from a single package file
3940773b78SXianjun JiaoThe openwifi/user_space/**drv_and_fpga_package_gen.sh** also generates a single package file **drv_and_fpga.tar.gz**, which includes driver files (.ko),
4070cedb22SXianjun JiaoFPGA image and many other source files with rich infos that are related.
4170cedb22SXianjun Jiao
4270cedb22SXianjun JiaoYou can switch to your own branch/version/variant, build the single package file via **drv_and_fpga_package_gen.sh**, rename it with a more meaningful name (such as add version or variant info as postfix), put the renamed **drv_and_fpga_MEANINGFUL_POSTFIX.tar.gz** on board in the same directory as **wgd.sh**, and let **wgd.sh** load it:
4340773b78SXianjun Jiao```
4440773b78SXianjun Jiao./wgd.sh ./drv_and_fpga_MEANINGFUL_POSTFIX.tar.gz
4540773b78SXianjun Jiao```
4670cedb22SXianjun JiaoIn this way, different version/variants of driver/FPGA can be switched by **wgd.sh** without rebooting/power-cycle.
4740773b78SXianjun Jiao
482576903aSJiao Xianjun## Suggested practice to generate driver FPGA variants
492576903aSJiao XianjunThere are several ways to generate variants of the single driver-FPGA package file. For example:
502576903aSJiao Xianjun
512576903aSJiao Xianjun- Switch/create another branch for openwifi and openwifi-hw, work/modify there, then generate the single package file via **drv_and_fpga_package_gen.sh**. This package is the branch specific, so renaming the package name to a more meaningful one would be good practice.
522576903aSJiao Xianjun- In the same branch, set different arguments (finally macro definitions in .h and .v files) via conditional compiling to enable/disable different driver and FPGA code blocks/functionalities, then generate the single package file via **drv_and_fpga_package_gen.sh**. Rename the package to remind you which conditions are ON/OFF.
532576903aSJiao Xianjun    - Check "Conditional compile by verilog macro" in openwifi-hw README for FPGA design
542576903aSJiao Xianjun    - Input more arguments (max 5) to driver building script "make_all.sh $XILINX_DIR ARCH_BIT". Those arguments will be converted to "#define argument" in pre_def.h for driver conditional compiling. **Attention:** **drv_and_fpga_package_gen.sh** currently only call **make_all.sh** without extra arguments. If you have conditional compiling arguments, do not forget to put them into **drv_and_fpga_package_gen.sh** as extra arguments of **make_all.sh**.
552576903aSJiao Xianjun
5640773b78SXianjun Jiao## Detailed full usage info
5740773b78SXianjun JiaoRun the "./wgd.sh -h" on board or open wgd.sh to see full usage info:
5840773b78SXianjun Jiao```
5940773b78SXianjun Jiaousage:
6040773b78SXianjun Jiao  Script for load (or download+load) different driver and FPGA img without rebooting
6140773b78SXianjun Jiao  no  argument: Load .ko driver files and FPGA img (if system_top.bit.bin exist) in current dir with test_mode=0.
6240773b78SXianjun Jiao  1st argument: If it is a NUMBER, it will be assigned to test_mode. Then load everything from current dir.
6340773b78SXianjun Jiao  1st argument: If it is a string called "remote", it will download driver/FPGA and load everything.
6440773b78SXianjun Jiao  - 2nd argument (if exist) is the target directory name for downloading and reloading
6540773b78SXianjun Jiao  - 3rd argument (if exist) is the value for test_mode
6640773b78SXianjun Jiao  1st argument: neither NUMBER nor "remote" nor a .tar.gz file, it is regarded as a directory and load everything from it.
6740773b78SXianjun Jiao  - 2nd argument (if exist) is the value for test_mode
6840773b78SXianjun Jiao  1st argument: a .tar.gz file, it will be unpacked then load from that unpacked directory
6940773b78SXianjun Jiao  - 2nd argument (if exist) is the value for test_mode
7040773b78SXianjun Jiao```
71