2021/5/31

bookmark: bluethooth 5.0 and raspberry pi

ref:

Failed to Load the Server certificate.

結果是 openssl/ctx.go:
// LoadVerifyLocations tells the context to trust all certificate authorities
// provided in either the ca_file or the ca_path.
// See http://www.openssl.org/docs/ssl/SSL_CTX_load_verify_locations.html for
// more.
func (c *Ctx) LoadVerifyLocations(ca_file string, ca_path string) error {
    runtime.LockOSThread()
    defer runtime.UnlockOSThread()
    var c_ca_file, c_ca_path *C.char
    if ca_file != "" {
        c_ca_file = C.CString(ca_file)
        defer C.free(unsafe.Pointer(c_ca_file))
    }
    if ca_path != "" {
        c_ca_path = C.CString(ca_path)
        defer C.free(unsafe.Pointer(c_ca_path))
    }
    if C.SSL_CTX_load_verify_locations(c.ctx, c_ca_file, c_ca_path) != 1 {
        return errorFromErrorQueue()
    }
    runtime.KeepAlive(c)
    return nil
}
caller 是:
func loadServerTrust(ctx *openssl.Ctx, conf *Config) (*openssl.Ctx, error) {
    defaultCertDir, err := openssl.GetDefaultCertificateDirectory()
    if err != nil {
        return ctx, errors.Wrap(err, "Failed to get the default OpenSSL certificate directory. Please verify the OpenSSL setup")
    }
    sysCertsFound, err := nrOfSystemCertsFound(defaultCertDir)
    if err != nil {
        log.Warnf("Failed to list the system certificates with error: %s", err.Error())
    }

    // Set the default system certificate path for this OpenSSL context
    err = ctx.SetDefaultVerifyPaths()
    if err != nil {
        return ctx, fmt.Errorf("Failed to set the default OpenSSL directory. OpenSSL error code: %s", err.Error())
    }
    // Load the server certificate into the OpenSSL context
    err = ctx.LoadVerifyLocations(conf.ServerCert, "")
    if err != nil {
        if strings.Contains(err.Error(), "No such file or directory") {
            log.Warnf(errMissingServerCertF, conf.ServerCert)
        } else {
            log.Errorf("Failed to Load the Server certificate. Err %s", err.Error())
        }
        // If no system certificates, nor a server certificate is found,
        // warn the user, as this is a pretty common error.
        if sysCertsFound == 0 {
            log.Error(errMissingCerts)
        }
    }
    return ctx, err
}

2021/5/25

More on IIS2DLPC , Wake Up

ST 的 application note AN5201 有比較仔細的 wakeup 功能說明。

Section 5.4 Wake-up interrupt

Wakeup source 可以選 Hight-pass fileter 或 offset filter

選 offset filter 為 source 時..

三軸之中,任一軸的值大於 threshold
然後還要符合 duration,大於 threshold 的時間要超過 duration 的設定。

產生 interrupt 後的動作,如果沒有設定 latch mode,一旦 低於 threshold, interrupt 自動reset。
如果設定是 latch mode,一旦觸發 interrupt後,就會一直保持,直到 讀取了 WAKE_UP_SRC 或 ALL_INT_SRC

AN 中有使用 high pass filter 的設定範例,當sensor 有大幅度改變時..任一軸大於 threshold 後產生 interrupt。
write 64h in CTRL1(20h)
write 04h in CTRL6(25h)
write 20h in CTRL7(3fh)
write 00h in WAKE_UP_DUR(35h)
write 02h in WAKE_UP_THS(34h)
write 20h in CTRL4_INT1_PAD_CTRL(23h)
還有一個用USER OFFSET 做srce 的設定範例,採用 X-0. Y-0. Z-02 之後,大於 threshold 之後產生 interrupt (因為 duration 0)
write 04h in CTRL6(25h)
write 34h in CTRL7(35h)
write 00h in X/Y_OFS_USR(3ch,3dh)
write 40h in Z_OFS_USR(3eh)
write 00h in WAKE_UP_DUR(35h)
write 02h in WAKE_UP_THS(34h)
write 20h in CTRL4_INT1_PAD_CTRL(23h)
write 64h in CTRL1(20h)
發現 官方的 input driver 沒有宣告 CTRK7(3fh).
所以相關的 enable 也沒做,那個 input4/wake_up/enable 並沒有開啟 CTRK7 的 INTERRUPTS_ENABLE.

在 driver 的 i2c_write output log,開機有做的 register write..
[    0.945939] lis2dwi2c w 21 4c
[    0.949619] lis2dwi2c w 20 1
[    0.953205] lis2dwi2c w 22 10
[    0.956880] lis2dwi2c w 21 c
[    0.960467] lis2dwi2c w 36 1
[    0.964054] lis2dwi2c w 36 9
[    0.968054] lis2dwi2c w 30 9
[    0.971642] lis2dwi2c w 34 2
[    5.170523] lis2dwi2c w 20 11
[    5.175374] lis2dwi2c w 20 51
enable input4/wake_up/enable 的話..
[  198.030489] lis2dwi2c w 23 20
所以wakeup需要的幾乎都沒設
所以要再 enable 的時候都設好...

為了檢查,可能要把 intertupt status 讀出來,27h
                7           6         5           4              3         2       1      0
-----------------------------------------------------------------------------------------------
STATUS | 27h | FIFO_THS | WU_IA | SLEEP_STATE | DOUBLE_TAP | SINGLE_TAP | 6D_IA | FF_IA | DRDY |
在sysfs input4/wake_up 下增加一個 regv
cat 內容就是 27h 的內容。
測試..
# echo 1 > enable 
[  161.304567] --lis2dw12_enable_sensors--
[  161.308934] --lis2dw12_update_drdy_irq--
[  161.313552] lis2dwi2c w 23 20
[  161.317201] lis2dwi2c w 20 64
[  161.320851] lis2dwi2c w 25 4
[  161.324128] lis2dwi2c w 3f 20
[  161.327782] lis2dwi2c w 35 0
[  161.331009] lis2dwi2c w 34 2
[  161.334305] lis2dwi2c w 23 20
# 
# cat regv 
1
# cat regv 
0
# cat regv 
1
# cat regv 
0
----- 敲打機器 ----

# cat regv 
41
# cat regv 
40
WU_IA bit set,所以應該 OK

2021/5/24

bookmark : google 專利 : camera under the screen

原來螢幕挖一個洞,下面放一個會旋轉的菱鏡,可以控制反射到鏡頭或是一個小螢幕。
好麻煩,還要準備一個小 display...然後 camera 的進光量也會受影響。

是說這個缺口有這麼重要嗎.....其他更重要的修改還很多吧...

2021/5/21

systemd : run my script before shutdown.

ref: 所以試試看:
先產生..
# cat /etc/systemd/system/runmyshutdown.service 
[Unit]
Description=Run my custom task at shutdown
DefaultDependencies=no
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/myshutdown.sh
TimeoutStartSec=0

[Install]
WantedBy=shutdown.target
還有測試的 script:
# cat /usr/local/bin/myshutdown.sh 
#!/bin/bash
/bin/touch /data/sssss
然後..
# systemctl daemon-reload
# systemctl enable runmyshutdown
Created symlink /etc/systemd/system/shutdown.target.wants/runmyshutdown.service → /etc/systemd/system/runmyshutdown.service.
原來沒有 /etc/systemd/system/shutdown.target.wants 這個目錄。
因為 WantedBy 的關係,所以新 create。

測試,reboot 後,到 /data 去看,果然有 ssss,所以是成功了。

G Sensor: IIS2DLPC, wakeup function

Control Register 4 (23h):
  • bit 5: INT1_WU : 將 wakeup 狀態由 INT1 輸出
Status Register (27h):
  • bit 6: WU_IA : Wake Up Event Status
WAKE_UP_THS (34h):
  • bit 7: Single/Double : 0 - only single tap enabled, 1 - single and double tap enabled
  • bit 6: Sleep on : 0 - sleep disabled, 1 - enabled
  • bit 0-5 : threshold, 6bit unsigned
WAKE_UP_DUR (35h): -- 太複雜了...

WAKE_UP_SRC (38h):
  • bit 5 : Free Fall
  • bit 4 : Sleep Event Detected
  • bit 3 : Wake Up Event Detected
  • bit 2 : Wake Up Event on X
  • bit 1 : Wake Up Event on Y
  • bit 0 : Wake Up Event on Z
ALL_INT_SRC (3bh): 讀取這個 register 會 reset 所有 關聯到 INT 的 interrupt 狀態
  • bit 1: Wake Up
X/Y/Z_OFS_USR(3ch,3dh,3eh): 不知道是什麼意思
  • bit 0-7 : wo's complement user offset value on X/Y/Z-axis data, used for wakeup function
linux kernel driver 有時做出四個input device driver
  • input0 : accel
  • input1 : free_fall
  • input2 : tap
  • input3 : double_tap
  • input4 : wake_up
其中 input0, accel 的 configurable 內容有 enable, polling_rate, resolution, scale, scale_avail
其他的input1~4 都只有 enable 而已。

source code:
static DEVICE_ATTR(enable,
           S_IWUSR | S_IRUGO,
           lis2dw12_get_enable,
           lis2dw12_set_enable);
然後..
static struct attribute *lis2dw12_accel_attribute[] = {
    &dev_attr_enable.attr,
    &dev_attr_resolution.attr,
    &dev_attr_polling_rate.attr,
    &dev_attr_scale_avail.attr,
    &dev_attr_scale.attr,
    NULL,
};

static struct attribute *lis2dw12_step_ff_attribute[] = {
    &dev_attr_enable.attr,
    NULL,
};

static struct attribute *lis2dw12_tap_attribute[] = {
    &dev_attr_enable.attr,
    NULL,
};

static struct attribute *lis2dw12_double_tap_attribute[] = {
    &dev_attr_enable.attr,
    NULL,
};

static struct attribute *lis2dw12_wakeup_attribute[] = {
    &dev_attr_enable.attr,
    NULL,
};
可以看到,所有 inputX 的 attrib enable 都共用 function : lis2dw12_set_enable( )
然後 lis2dw12_set_enable( ) 依照傳入的 dev 決定是那一個 input call 的..

查 enable --- 最後到 _lis2dw21_enable_sensors( ),先..err = lis2dw12_update_drdy_irq(sdata),啟動 INT1..
CTRL4 就是控制 interrput 到 INT1 的開關
     7            6             5        4         3            2           1           0
------------------------------------------------------------------------------------------------
| INT1_6D | INT1_SINGLE_TAP | INT1_WU | INT1_FF | INT1_TAP | INT1_DIFF5 | INT1_FTH | INT1_DRDY |
------------------------------------------------------------------------------------------------
其中,INT1_WU 就是 wake up
static int lis2dw12_update_drdy_irq(struct lis2dw12_sensor_data *sdata)
{
    u8 reg_addr = LIS2DW12_CTRL4_INT1_PAD_ADDR, reg_val, reg_mask;

    switch (sdata->sindex) {
    case LIS2DW12_FF:
    case LIS2DW12_TAP:
    case LIS2DW12_DOUBLE_TAP:
    case LIS2DW12_WAKEUP:
        reg_val = lis2dw12_event_irq1_value(sdata->cdata);
        reg_mask = LIS2DW12_INT1_EVENTS_MASK;
        break;
    case LIS2DW12_ACCEL:
        return 0;
    default:
        return -EINVAL;
    }

    return lis2dw12_write_data_with_mask(sdata->cdata, reg_addr, reg_mask,
                       reg_val >> __ffs(reg_mask), true);
}
所以driver 中,Wakeup 的 threshold, duration 都是hard-code,不是 configurable.
sysfs 中只有 enable/disable 功能。就是把 interrupt 開啟/關閉。
#define LIS2DW12_WAKE_UP_THS_WU_MASK    0x3f
#define LIS2DW12_WAKE_UP_THS_WU_DEFAULT 0x02


static int lis2dw12_init_sensors(struct lis2dw12_data *cdata)
{
      ...
      err = lis2dw12_write_data_with_mask(sdata->cdata,
                      LIS2DW12_WAKE_UP_THS_ADDR,
                      LIS2DW12_WAKE_UP_THS_WU_MASK,
                      LIS2DW12_WAKE_UP_THS_WU_DEFAULT, true);
這個 write_data_with_mask( )就是 read, mask, update 的動作。
mask 就是把這幾個 bit 都 clear,然後填熱 後面的 data。
然後 DURATION 都沒設。

--- 結果沒這麼簡單...

查 application note AN5201, 5.1 Interrupt pin configutation:
All the embedded function interrupt signals are subordinate to the INTERRUPTS_ENABLE bit in register CTRL7.
If this bit is set, the embedded functions are enabled and the interrupts signals can be routed to the INT1 and/or
INT2 pins; otherwise, if this bit is not set, the embedded functions are disabled
可是 source code 中沒有看到CTRL7 的宣告,也沒有設定。(除非 reset value 是 SET)
所以 INT1 沒有動作。

2021/5/17

picocom ..

比較間單直接,也是 opensource 的。 ubuntu 18.04 的版本是 v2.2,官網最後一個版本是 3.3 了 (2019).

但是很奇怪,一直都沒有 timetag 功能。

Opensource 果然,就有人幫忙...
但是版本只有到 1.7

build 的方法很簡單,就 clone下來 make 就可以...
./picocom --help
picocom v1.7+
Usage is: picocom [options] <tty device>
Options are:
  --<baud> <baudrate>
  --<f>low s (=soft) | h (=hard) | n (=none)
  --<p>arity o (=odd) | e (=even) | n (=none)
  --<d>atabits 5 | 6 | 7 | 8
  --<e>scape <char>
  --<noi>nit
  --no<r>eset
  --no<l>ock
  --<s>end-cmd <command>
  --recei<v>e-cmd <command>
  --<t>imestamp
  --<h>elp
<?> indicates the equivalent short option.
Short options are prefixed by "-" instead of by "--".
所以加上 timetag 的 option 是 -t
./picocom -t -b 115200 /dev/ttyUSB0 
picocom v1.7+

port is        : /dev/ttyUSB0
flowcontrol    : none
baudrate is    : 115200
parity is      : none
databits are   : 8
escape is      : C-a
noinit is      : no
noreset is     : no
nolock is      : no
send_cmd is    : ascii_xfr -s -v -l10
receive_cmd is : rz -vv

Terminal ready


0:00.002 Welcome to Ambarella
0:00.006 Ambarella login: 
0:09.447 [    0.000000] Booting Linux on physical CPU 0x0
0:09.451 [    0.000000] Linux version 4.14.181 (webb-li@rdsuper) (gcc version 8.2.1 20180802 (Linaro GCC 8.2-2018.08~dev)) #1 SMP PREEMPT Fri May 7 14:27:31 CST 2021
0:09.464 [    0.000000] Boot CPU: AArch64 Processor [410fd034]
0:09.469 [    0.000000] Machine model: Ambarella CV25 Hazelnut Board
0:09.474 [    0.000000] Reserved memory: created CMA memory pool at 0x000000000cc00000, size 48 MiB
0:09.482 [    0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool
0:09.490 [    0.000000] Reserved memory: created CMA memory pool at 0x0000000010000000, size 508 MiB
0:09.498 [    0.000000] OF: reserved mem: initialized node iav@0x10000000, compatible id shared-dma-pool
0:09.507 [    0.000000] Reserved memory: created CMA memory pool at 0x0000000030000000, size 252 MiB
0:09.515 [    0.000000] OF: reserved mem: initialized node cavalry@0x30000000, compatible id shared-dma-pool
0:09.524 [    0.000000] On node 0 totalpages: 261632
0:09.528 [    0.000000]   DMA zone: 4088 pages used for memmap
0:09.532 [    0.000000]   DMA zone: 0 pages reserved
0:09.536 [    0.000000]   DMA zone: 261632 pages, LIFO batch:31
0:09.541 [    0.000000] percpu: Embedded 19 pages/cpu s38552 r8192 d31080 u77824
0:09.547 [    0.000000] pcpu-alloc: s38552 r8192 d31080 u77824 alloc=19*4096
0:09.553 [    0.000000] pcpu-alloc: [0] 0 [0] 1 [0] 2 [0] 3 
0:09.558 [    0.000000] Detected VIPT I-cache on CPU0
0:09.562 [    0.000000] CPU features: enabling workaround for ARM erratum 845719
0:09.568 [    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 257544
0:09.575 [    0.000000] Kernel command line: console=ttyS0 noinitrd root=/dev/mmcblk0p8 rw rootfstype=ext4 init=/linuxrc rootwait loglevel=8
0:09.587 [    0.000000] PID hash table entries: 4096 (order: 3, 32768 bytes)
0:09.593 [    0.000000] Dentry cache hash table entries: 131072 (order: 8, 1048576 bytes)
0:09.600 [    0.000000] Inode-cache hash table entries: 65536 (order: 7, 524288 bytes)
0:09.607 [    0.000000] Memory: 192952K/1046528K available (5118K kernel code, 488K rwdata, 1452K rodata, 320K init, 227K bss, 26184K reserved, 827392K cma-reserved)
..


退出key 是 C-a, C-x,如果要改...
--- 例如 picocom 作為 pi 的 console,進入 pi 後,開啟 pi 上面的 picocom,這時候,用 C-a, C-x 就會退出整個 pi...
可以用 option -e
picocom -e b 
這樣,退出就變成..C-b, C-x

2021/5/13

raspberry pi 4. wifi setup -- ubuntu 20.04

ref: 是用 netplan.

新增一個 /etc/netplan/60-wlan-init.yaml:
network:
    version: 2
    renderer: networkd
    wifis:
        wlan0:
            access-points:
                "DM1_AP":
                    password: "1263356900"
                    band: "2.4GHz"
            dhcp4: true
            dhcp6: false
            optional: true
然後
# netplan generate
# netplan apply
之後用 ifconfig/ip 都可以看到 wlan0 起來了。

可以看到...
root        1679  0.0  0.1  12376  4688 ?        Ss   07:54   0:00 /sbin/wpa_supplicant -u -s -O /run/wpa_supplicant
root        3406  0.0  0.1  12652  7700 ?        Ss   09:21   0:00 /sbin/wpa_supplicant -c /run/netplan/wpa-wlan0.conf -iwlan0
netplan 會產生 /run/netplan/wpa-wlan0.conf
ctrl_interface=/run/wpa_supplicant

network={
  ssid="DM1_AP"
  freq_list=2472 2437 2467 2432 2462 2427 2457 2422 2452 2412 2417 2447 2442 2484
  key_mgmt=WPA-PSK
  psk="1163356900"
}
然後啟動 wpa_supplicant

因為 wpa_supplicant 已經啟動了,wpa_cli 也可以用了。

raspberry pi 4 gpio control -- ubuntu 20.04

先是看 gpio mapping (pin-name)
一樣,pinout..
Command 'pinout' not found, but can be installed with:

sudo apt install python3-gpiozero
所以apt 安裝,裝完再試,有了..
,--------------------------------.
| oooooooooooooooooooo J8     +====
| 1ooooooooooooooooooo        | USB
|                             +====
|      Pi Model ???V1.2          |
|      +----+                 +====
| |D|  |SoC |                 | USB
| |S|  |    |                 +====
| |I|  +----+                    |
|                   |C|     +======
|                   |S|     |   Net
| pwr        |HDMI| |I||A|  +======
`-| |--------|    |----|V|-------'

Revision           : c03112
SoC                : Unknown
RAM                : NoneMb
Storage            : MicroSD
USB ports          : 4 (excluding power)
Ethernet ports     : 1
Wi-fi              : False
Bluetooth          : False
Camera ports (CSI) : 1
Display ports (DSI): 1

J8:
   3V3  (1) (2)  5V    
 GPIO2  (3) (4)  5V    
 GPIO3  (5) (6)  GND   
 GPIO4  (7) (8)  GPIO14
   GND  (9) (10) GPIO15
GPIO17 (11) (12) GPIO18
GPIO27 (13) (14) GND   
GPIO22 (15) (16) GPIO23
   3V3 (17) (18) GPIO24
GPIO10 (19) (20) GND   
 GPIO9 (21) (22) GPIO25
GPIO11 (23) (24) GPIO8 
   GND (25) (26) GPIO7 
 GPIO0 (27) (28) GPIO1 
 GPIO5 (29) (30) GND   
 GPIO6 (31) (32) GPIO12
GPIO13 (33) (34) GND   
GPIO19 (35) (36) GPIO16
GPIO26 (37) (38) GPIO20
   GND (39) (40) GPIO21

gpio 操作就是一般 linux 的 gpio 操作。用 sys..

舉例,使用最角落 pin 40. GPIO21:
$sudo su -
#echo 21 > /sys/class/gpio/export
#echo out > /sys/class/gpio/gpio21/direction
#echo 1 > /sys/class/gpio/gpio21/value

列出目前ssh 連線的人

用 who 來看的話,如果沒有 login 的話,不會出現。
例如:
ssh xeontitan bash

所以只能用 netstat 來列出所有連到 sshd 的連線
$ sudo netstat -atnp | grep 'ESTABLISHED.*/sshd'
tcp        0      0 192.168.144.179:22      192.168.144.170:39512   ESTABLISHED 28552/sshd: charles 
tcp        0      0 192.168.144.179:22      192.168.144.170:39476   ESTABLISHED 15271/sshd: charles
這要只要跟 sshd 建立連線的,都會列出來...

2021/5/12

bookmarks: PERCLOS

PERCLOS 就是眼皮閉起來的百百分比。
分別有
  • 眼皮遮蓋眼睛的百分比
  • 一段時間中,眼皮張開跟閉起來的時間比例
利用上面這兩個數值來判定...專心,發呆,想睡,清醒...之類的..

wifi : roaming

wifi 的 roming 功能,讓你能從一個 app 無縫的切換到另一個 一樣名子(SSID) 的 AP。
一般用在有 repeat 佈置的環境。

wl roam_off
0
可以檢查你的 wifi roaming 是開啟還是關閉。

wl roam_off 0
開啟 roaming..

2021/5/10

bookmark : online flow-chart tools

線上的 流程圖繪製 網站,跟 google space 很像,open source 的。
可以 fork 回來自己建 server,或是用他們架好的

iw and wpa

原來 iw 的命令只能用來做 WEP 連線,要是WPA 的話,就要用 wpa_XXX 的 tool

但是 wifi 連線狀態,scan, channel 等等跟 entryption 無關的,還是可以用 iw 來做。

2021/5/7

build iperf3 static for android

因為要測試與 Android AP 的長時間連線,所以要在 android 上 run iperf。
arm64 環境偷懶用 pi4, ubuntu.

github iperf clone 下來,checkout tag 3.1.3

然後依照FAQ, run configure
configure "LDFLAGS=--static" --disable-shared --without-sctp
因為 android 的 tmp 在 /data/local/tmp,與一般linux 系統的 /tmp 不同。
不然會出現
iperf3: error - unable to create a new stream: No such file or directory
修改:
diff --git a/src/iperf_api.c b/src/iperf_api.c
index 5b56af6..f58e18a 100755
--- a/src/iperf_api.c
+++ b/src/iperf_api.c
@@ -2664,7 +2664,7 @@ iperf_new_stream(struct iperf_test *test, int s)
     if (test->tmp_template) {
         snprintf(template, sizeof(template) / sizeof(char), "%s", test->tmp_template);
     } else {
-        char buf[] = "/tmp/iperf3.XXXXXX";
+        char buf[] = "/data/local/tmp/iperf3.XXXXXX";
         snprintf(template, sizeof(template) / sizeof(char), "%s", buf);
     }
 
之後就可以 make...

2021/5/4

mender.io device identity

ref: mender.io 管理 device 的界面有最左邊一欄是 device id,看起來是一長串的 16 byte hex。
這個id 是 service assign 的,不是給人看的。

mender.io 的第二個欄位,才是讓使用者判斷 device 用的。

device 用 script: /usr/share/mender/identity/mender-device-identity 來決定要顯示的內容(用來決定/辨別 device) 的內容是什麼。
設計者可以依照需要自己決定要用device 的那一向unique data 最為辨別用。

mender 會把 mender-device-identity 的 輸出拿來用。
輸出要以
key=value
的方式。

以目前 sdk 的範例來說,他會去 /sys/class/net/ 下,找 ifndex 最小的 network device。
用他的 mac 作為 idenrity

手動 run script 會出現..
using interface /sys/class/net/usb0
mac=2a:c8:b7:cc:bb:aa
第一行是輸出到 stderr。所以拿來用的是第二行。

如果要改用其他的,舉例來說,product id...
productid 放在 productInfo.txt
# cat /data/productInfo.txt 
qwertyasdfzxcv#20210122#001
所以 mender-device-identity 改成...
set -ue
echo "SN=$(cut -d# -f1 /data/productInfo.txt)"
這樣,在 mender.io 的 device page 就出現 SN 了.. (但是mac 欄位是空的)

2021/5/3

Makefile : wildcard 用法的一種:檔案在不在

wildcard 用來列舉後面參數的file/path 內容。
也可以用來檢查檔案在不在。
像...
SYSFILES += $(wildcard $(OUT_DIR)/usr/lib/systemd/system/multi-user.target.wants/countssh.service)
這樣,如果 out folder 的 countssh.service 存在的話 (上次 build 的結果還流著,SYSFILES 就會有這個 file link)
如果 out folder 裡沒有這個檔案,wildcard 的結果就是空的。

這樣的 rule,配合之後的刪除動作:
for n in $(SYSFILES); \
do \
rm $(OUT_DIR)/usr/lib/systemd/system/multi-user.target.wants/$$n; \
done
就會把他刪掉。
不直接寫,而用 wildcard 來檢查的原因是...
如果這個檔案不在的話,後面的 rm 動作就會 fail,讓 make 中斷。



另一個,"不在就 create" 的方式..
ifeq (,$(wildcard $(OUT_DIR)/usr/lib/systemd/system/multi-user.target.wants/mender-client.service))
        ln -s ../mender-client.service $(OUT_DIR)/usr/lib/systemd/system/multi-user.target.wants/mender-client.service
endif
用 ifeq,如果 wildcard 的結果是空的,代表那個檔案不存在。

2021/5/1

Chromebook 電池...



其實這個chromebook很久以前touch 的click就失效了,我也不知道為什麼?
然後今天發現蓋子蓋不緊了..
才想到是電池暴了。

拆開看,果然...
拿這個型號去瞎皮,最便宜要800
那就拆了,當作沒電池吧。
竟然也可以用。

拆了電池之後,touch 的 click 就好了!

... chromebook 的 keyboard 真的蠻好敲。

Bookmark : TOTOLINK A650UA, ubuntu 20.04


就...
先設定 auto. usb-modeswitch,: /lib/udev/rules.d/40-usb_modeswitch.rules
# Realtek 8211CU Wifi AC USB
ATTR{idVendor}=="0bda", ATTR{idProduct}=="c811", RUN+="/usr/sbin/usb_modeswitch -K -v 0bda -p c811"

# Realtek 8211CU Wifi AC USB
ATTR{idVendor}=="0bda", ATTR{idProduct}=="1a2b", RUN+="/usr/sbin/usb_modeswitch -K -v 0bda -p 1a2b"
結果真的要照抄才行,雖然dw-171好像也是一樣的
改完usb-modeswitch也要重開機。

follow 上面的instruction,用 dkms build and install。
第一次要手動modprobe,之後舊部用。

在network manager 中要把原來內建的wifi 連線設定刪除,然後新增一個wifi連線。
選擇這個心wifi device。並且設好要連的ssid/password
然後就跟上一個一樣,用停止,更換,啟動。
就可以了...
為了保險,把build and install procedure copy 下來...
開機的dmesg..
[    4.745909] usb 2-1.2: new high-speed USB device number 3 using ehci-pci
[    4.862226] usb 2-1.2: New USB device found, idVendor=0bda, idProduct=1a2b, bcdDevice= 2.00
[    4.862231] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[    4.862233] usb 2-1.2: Product: DISK
[    4.862235] usb 2-1.2: Manufacturer: Realtek
[    4.862528] usb-storage 2-1.2:1.0: USB Mass Storage device detected
然後usb-modeswitch啟動後,dmesg:
[    6.658729] usb 2-1.2: USB disconnect, device number 3
[    6.741004] usbcore: registered new interface driver btusb
[    6.885900] usb 2-1.2: new high-speed USB device number 4 using ehci-pci
[    6.998749] usb 2-1.2: New USB device found, idVendor=0bda, idProduct=2006, bcdDevice= 2.00
[    6.998752] usb 2-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[    6.998753] usb 2-1.2: Product: 802.11ac NIC
[    6.998755] usb 2-1.2: Manufacturer: Realtek
[    6.998756] usb 2-1.2: SerialNumber: 123456
usb-modeswitch auto:
修改/lib/udev/rules.d/40-usb_modeswitch.rules,在最後的 end mark 之前...
# TOTOLINK A500UA
ATTR{idVendor}=="0bda", ATTR{idProduct}=="1a2b", RUN+="/usr/sbin/usb_modeswitch -K -v 0bda -p 1a2b"
奇怪的是,reboot後,這一行不見了...
可能是因為沒有把DWA-171那一行刪掉?
driver 是用source build 來install 的,但是因為時代進步,已經有 dkms幫我們處理build,install還有以後 kernel 升級的問題,
所以就...
$git clone https://github.com/brektrou/rtl8821CU.git
$cd ~/rtl8821CU
$sudo ./dkms-install.sh
可以看一下dkms-install.sh 的內容。
這樣就build 完也install 好了。
可以 modprobe 了...

這種有mass-storage driver 的很麻煩,插著開機會開不了機....

kernel 更新到5.15以後就 fail 了,source 要 pull 過 (fix for 5.15),
然後 dkms-remove.sh,再dkms-install.sh
--- 不曉得有沒有效。



update : 2024-01-21
更新到 22.04 後,只有安裝 usb-modeswitch,然後修改 04-usb-modeswitch.rules 之後,reboot,插入 usb-wifi 就 OK 了。
大概是 22.04 已經內建這個 driver.

update : 2024-03-04
不是22.04 直接可以用。

整個系統重新安裝22.04後,插入自動mode-switch,driver load and wlan interface show OK
但是 connect to ssid failed,dmesg 出現:
[19550.715130] wlx5c925e810018: 80 MHz not supported, disabling VHT
[19550.750444] wlx5c925e810018: send auth to 1c:3b:f3:74:XX:XX (try 1/3)
[19551.575255] wlx5c925e810018: send auth to 1c:3b:f3:74:XX:XX (try 2/3)
[19552.567291] wlx5c925e810018: send auth to 1c:3b:f3:74:XX:XX (try 3/3)
[19553.557432] wlx5c925e810018: authentication with 1c:3b:f3:74:XX:XX timed out
查driver 是:
rtw88_8821cu           12288  0
rtw88_8821c            90112  1 rtw88_8821cu
rtw88_usb              24576  1 rtw88_8821cu
rtw88_core            356352  2 rtw88_8821c,rtw88_usb
mac80211             1720320  2 rtw88_core,rtw88_usb
這一篇有類似的情形,他是參考這一篇 download, build and install 另一個版本的 driver 才成功的。