vault backup: 2025-11-24 15:12:58
Affected files: 21.01. OS/21.01. Linux/Replace custom build module driver.md 21.01. OS/21.01. Linux/modprobe 與 insmod 的差別.md 30. 工作 - Logitech/project - Lanky.md
This commit is contained in:
114
21.01. OS/21.01. Linux/Replace custom build module driver.md
Normal file
114
21.01. OS/21.01. Linux/Replace custom build module driver.md
Normal file
@@ -0,0 +1,114 @@
|
||||
---
|
||||
tags:
|
||||
aliases:
|
||||
date: 2025-11-24
|
||||
time: 15:05:35
|
||||
description:
|
||||
---
|
||||
This page note how to isntall custom built `.ko` file.
|
||||
|
||||
### 版號確認
|
||||
用 `uname -a` 查看目前 kernel 版本。
|
||||
用 `modinfo tcxxx_pcie_eth.ko` 檢查 vermagic 版本。
|
||||
ko 版本與 kernel 版本必須一致。
|
||||
```
|
||||
1|KM1:/ # uname -r
|
||||
5.15.78-qki-consolidate-android13-8-gf5cf1391b188
|
||||
```
|
||||
|
||||
```
|
||||
KM1:/ # modinfo /storage/emulated/0/Documents/tc956x_pcie_eth.ko
|
||||
filename: /storage/emulated/0/Documents/tc956x_pcie_eth.ko
|
||||
license: GPL v2
|
||||
author: Toshiba Electronic Devices & Storage Corporation
|
||||
description: TC956X PCI Express Ethernet Network Driver
|
||||
srcversion: 5F197F74D301D4F6ADC6A72
|
||||
depends:
|
||||
name: tc956x_pcie_eth
|
||||
vermagic: 5.15.167-g94a5a0e4b3fa SMP preempt mod_unload modversions aarch64
|
||||
```
|
||||
|
||||
### Unload old driver
|
||||
#### Old driver is a module
|
||||
用 `lsmod | grep tc956x` 確認原本的 module 已安裝。
|
||||
用 `rmmod` 移除原本的 module:`sudo rmmod tc956x_pcie_eth`
|
||||
用 `insmod` 來安裝新的 module:`insmod tc956x_pcie_eth.ko`
|
||||
|
||||
#### Old module is static link
|
||||
`lsmod` 找不到東西,但 `find` 卻在 `/sys` 裡看到了一堆 `tc956x` 相關的檔案。這代表原本的驅動程式是**直接編譯進核心 (Static Linked)**,而不是獨立的 `.ko` 檔案。
|
||||
|
||||
##### 1. 確認原本的 Module 是否已正確安裝
|
||||
```shell
|
||||
ls -l /sys/bus/pci/drivers/tc956x_pci-eth/
|
||||
```
|
||||
如果在該目錄下看到類似 `0001:05:00.0` 這樣的 PCI ID 連結(Symlink),就代表**原本的內建驅動已經抓到裝置並正在控制它**。
|
||||
|
||||
##### 2. 解綁原本的內建驅動
|
||||
```shell
|
||||
# 解綁 Port 0
|
||||
echo -n "0001:05:00.0" > /sys/bus/pci/drivers/tc956x_pci-eth/unbind
|
||||
|
||||
# 解綁 Port 1 (如果有)
|
||||
echo -n "0001:05:00.1" > /sys/bus/pci/drivers/tc956x_pci-eth/unbind
|
||||
```
|
||||
|
||||
##### 3. 載入新的 `.ko` 檔
|
||||
```shell
|
||||
insmod tc956x_pcie_eth.ko
|
||||
```
|
||||
|
||||
|
||||
### 可能的錯誤
|
||||
#### Unbind driver 就 reboot
|
||||
##### 試著先把 eth 關掉:
|
||||
```
|
||||
ip link set eth0 down
|
||||
```
|
||||
|
||||
如果還是會當機,試著查看 log,先確認 log 目錄下有哪些檔案:
|
||||
```shell
|
||||
ls -l /sys/fs/pstore/
|
||||
```
|
||||
|
||||
假設有發現檔案叫做 `pmsg-ramoops-0`,那可以:
|
||||
```shell
|
||||
cat /sys/fs/pstore/pmsg-ramoops-0
|
||||
```
|
||||
|
||||
如果是亂碼,試著:
|
||||
```shell
|
||||
logcat -P /sys/fs/pstore/pmsg-ramoops-0
|
||||
```
|
||||
|
||||
或是:
|
||||
```shell
|
||||
string /sys/fs/pstore/pmsg-ramoops-0
|
||||
```
|
||||
|
||||
##### 使用 `driver_override` (繞過 Unbind 的崩潰)
|
||||
1. 先載入新的 KO 檔
|
||||
1. `insmod /storage/emulated/0/Documents/tc956x_pcie_eth.ko`
|
||||
2. **設定 Driver Override** 強制指定該 PCI 裝置未來只能使用新的驅動名稱。
|
||||
1. `echo "tc956x_pcie_eth" > /sys/bus/pci/devices/0001:05:00.0/driver_override`
|
||||
3. **嘗試替換**
|
||||
- 不執行 `unbind` (因為會當機),我們嘗試執行 `bind` 給新驅動。但在標準 Linux 中,如果裝置已被佔用,通常需要先 `unbind`。
|
||||
- 但在某些架構下,如果我們無法執行 `unbind`,唯一的路是修改 `boot.img` 的 cmdline,加上 `initcall_blacklist` 禁用舊驅動初始化。
|
||||
|
||||
#### Unknown symbol
|
||||
如果 insmod 的訊息是:`tc956x_pcie_eth: Unknown symbol ...` 之類。
|
||||
這代表您的驅動程式依賴某個核心功能(例如 PHY 介面或 PTP),但目前的核心沒有開啟該功能。
|
||||
|
||||
#### Version mismatch (版本不符)
|
||||
核心會說 `disagrees about version of symbol` 或 `version magic '...' should be '...'`。
|
||||
這代表您的 `.ko` 檔是給 Kernel A 編譯的,但您的機器跑的是 Kernel B。
|
||||
|
||||
#### Initialization failed
|
||||
初始化失敗 - 這是最像 ENOENT 的原因。
|
||||
如果驅動程式在載入時(`module_init`)嘗試讀取某個**設定檔**或**Firmware (韌體)**(例如 `/vendor/firmware/tc956x.bin`),而那個檔案不存在,驅動程式會回傳錯誤代碼 `-ENOENT`,導致 `insmod` 顯示「找不到檔案」。
|
||||
|
||||
### 題外化
|
||||
#### [[modprobe 與 insmod 的差別]]
|
||||
|
||||
# 參考來源
|
||||
- [Linux .ko 檔案置換教學](https://gemini.google.com/app/52b1336e11a24217?hl=zh-TW)
|
||||
|
||||
16
21.01. OS/21.01. Linux/modprobe 與 insmod 的差別.md
Normal file
16
21.01. OS/21.01. Linux/modprobe 與 insmod 的差別.md
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
tags:
|
||||
aliases:
|
||||
date: 2025-11-24
|
||||
time: 15:08:20
|
||||
description:
|
||||
---
|
||||
| **特性** | **modprobe** | **insmod** |
|
||||
| -------- | -------------------------------------------------------------- | -------------------------------------------------- |
|
||||
| **處理依賴** | **會**自動檢查並載入所有相依的模組(需要 `modules.dep` 檔案)。 | **不會**處理依賴。您必須手動依序載入所有相依的模組。 |
|
||||
| **輸入參數** | 只需要模組名稱 (e.g., `tc956x_pcie_eth`)。 | 需要模組的完整檔案路徑 (e.g., `/path/to/tc956x_pcie_eth.ko`)。 |
|
||||
| **檔案路徑** | 預設在標準路徑下尋找 (e.g., `/lib/modules/$(uname -r)/kernel/...`)。 | 必須明確指定路徑。 |
|
||||
| **系統整合** | 會讀取設定檔 (`/etc/modprobe.d/*`) 來處理黑名單 (blacklist) 或設定別名 (alias)。 | 不會讀取設定檔,只負責載入檔案。 |
|
||||
| **適用情境** | **標準系統操作、永久安裝驅動、處理複雜依賴。** | **測試單一模組、從非標準路徑載入。** |
|
||||
|
||||
# 參考來源
|
||||
Reference in New Issue
Block a user