2021/7/30

shell : find if contains substring in string

ref:how to check if string contains substring in bash

shell 直接有string 比對功能。所以可以用來檢查是不是包含某字串。
比較好看的是:
#!/bin/bash

STR=`uname -a`
SUB='Linux'
if [[ "$STR" == *"$SUB"* ]]; then
  echo "It's there."
fi
但是在 busybox 的 shell 不支援,所以要用另一個語法:
#!/bin/bash

STR=`uname -a`
SUB='Linux'

case $STR in

  *"$SUB"*)
    echo "It's there."
    ;;
esac

會查這個是因為要檢查 kernel 的 build date 政不正確...

2021/7/27

CCD Output Format , Dumb and Smart

CCD 依照輸出的格式,分為
  • dumb : 輸出 RAW 格式,就是 每個 pixel 的值,而且pixel 是 bayer 排列的,一行 RGRG..,下一行 GBGB..
  • smart: 輸出 CCIR 601/656, RGB888,YUV444,每個 pixel 都有完整的YUV/RGB
smart 就是把 dump 經過 debayer 後的輸出。

所以接收 RAW 格式的時候, 要處理 debayer,用內插把每一個 pixel 的三個顏色分量都復原。
這一般都是由 cpu 的 ISP (Image Signal Processor) 來做。

像 TI 的TM320DM357, Video Processing FrontEnd。
就是做類似的事情。
從這個 isp 的 datasheet 可以看到 isp 一般能處理的事情。

CCD 的話,像OV2718,輸出就只有 RAW

因為 debayer 的 algorithm 有很多,所以使用 RAW 格式的話,各家 image processor 的廠商會產出不同 image quality 。這就是各家的 know-how。

2021/7/21

         Mounting Kernel Configuration File System...
         Starting Apply Kernel Variables...
         Starting Update is Completed...

         Starting OpenSSH rsa Server Key Generation...
         Starting Login Service...
         Starting OpenSSH ed25519 Server Key Generation...
         Starting OpenSSH ecdsa Server Key Generation...

2021/7/13

mender : create release by hand

手動做 release deployment 是需要的,像使用 overlay rootfs 的時候, mender 找不到 root partition。
所以只能手動做。
官方文件是: create a snapshot on the golden device:

有 root partition 的 dump 後 (可以 loop mount 回來的 blk image)。
mender-artifact write rootfs-image -f /mnt/root-part.ext4 \
                                   -n artifact-name \
                                   --software-version 1.0 \
                                   -o snapshot-release.1.0.mender \
                                   -t device-type
就可以轉成上傳道 mender.io server 的 release 檔 (snapshot-release.1.0.mender)

另外,在 device 上, mender 也提供 dump 的功能 (跟 dd 一樣?):
USER="user"
HOST="host-ip"

mender snapshot dump --source /dev/mmcblk0p8 | ssh $USER@$HOST /bin/sh -c 'cat > $HOME/root-part.ext4`

要是要手動 install,可以 copy *.mender 到機器上之後(e.g: /data/1234.mender),用 mender 來安裝
mender -install /data/1234.mender
一樣會更新到另一個 partition,然後呼叫 fw_setenv 來更新開機參數。

2021/7/7

build and install sudo from source

ref: 一樣,.configure ,make 再 make install
configure:
一樣,--prefix= 代表 make install 要安裝的位置。

copy 到 target 上,complain libutil... 都 copy 過去,
sudo 要是 S bit set 而且 owner 要是 0 (root)
設完之後剩下 complain: /etc/sudo.conf

看一下 build 出來, install 目錄中 share/doc/sudo/examples/sudo.conf:
所以修改一下 /etc/sudo.conf
Plugin sudoers_policy /usr/lib/sudoers.so
出現 Error:
sudo: error in /etc/sudo.conf, line 14 while loading plugin "sudoers_policy"
sudo: unable to load /usr/lib/sudoers.so: /lib/libcrypt.so.1: version `XCRYPT_2.0' not found (required by /usr/lib/sudoers.so)

libcrypt copy 過去後,sshd fail to start:
Ambarella sshd[14584]: /usr/sbin/sshd: relocation error: /usr/sb
in/sshd: symbol EVP_KDF_ctrl version OPENSSL_1_1_1b not defined in file libcrypt
o.so.1.1 with link time reference
應該是系統原來就有 libcrypt,我用另一個版本覆蓋了導致。

evb 上 libcrypt.so 在 openssl 中,所以copy 過去 pi4。重新 configure
./configure --enable-openssl=/home/pi/openssl --prefix=/home/pi/sudoinstall
先 disable 全部..
  --disable-shared
        Disable dynamic shared object support.  By default, sudo
        is built with a plugin API capable of loading arbitrary
        policy and I/O logging plugins.  If the --disable-shared
        option is specified, this support is disabled and the default
        sudoers policy and I/O plugins are embedded in the sudo
        binary itself.  This will also disable the noexec option
        as it too relies on dynamic shared object support.
        
  --disable-shared-libutil
        Disable the use of the dynamic libsudo_util library.  By
        default, sudo, the sudoers plugin and the associated sudo
        utilities are linked against a shared version of libsudo_util.
        If the --disable-shared-libutil option is specified, a
        static version of the libsudo_util library will be used
        instead.  This option may only be used in conjunction with
        the --enable-static-sudoers option.

  --enable-static-sudoers
        By default, the sudoers plugin is built and installed as a
        dynamic shared object.  When the --enable-static-sudoers
        option is specified, the sudoers plugin is compiled directly
        into the sudo binary.  Unlike --disable-shared, this does
        not prevent other plugins from being used and the noexec
        option will continue to function.
一樣,都 disable,也 disable openssl,結果一樣要 XCRYOT_2.0,只插在 /etc/sudo,conf 不用了。
所以要試 cross_compile..

2021/7/6

陷阱: image length is zero in trainning dataset

就 keras 的 cats and dogs.
出現:
PIL.UnidentifiedImageError: cannot identify image file
google 一下,有人說用
import os
from PIL import Image
folder_path = 'data\img'
extensions = []
for fldr in os.listdir(folder_path):
    sub_folder_path = os.path.join(folder_path, fldr)
    for filee in os.listdir(sub_folder_path):
        file_path = os.path.join(sub_folder_path, filee)
        print('** Path: {}  **'.format(file_path), end="\r", flush=True)
        im = Image.open(file_path)
        rgb_im = im.convert('RGB')
        if filee.split('.')[1] not in extensions:
            extensions.append(filee.split('.')[1])
檢查 image 是不是合格。
果然,出現:
Traceback (most recent call last):in/cats/666.jpg  **
  File "checkimage.py", line 10, in 
    im = Image.open(file_path)
  File "/home/charles-chang/miniconda3/envs/tensorflow-gpu/lib/python3.8/site-packages/PIL/Image.py", line 2967, in open
    raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file './cats_and_dogs_small/train/cats/666.jpg'
用 mediainfo 看 666.jpg,沒有內容。一看 file size 是 0

再加上 666 來 google ,出現這一篇
甚至把影像都看一下,確認真的是 Cats, Dogs,發現有些不正確的影像...

2021/7/5

-Werr=date-time

gcc 4.9 之後新增了一個 檢查的 option: date-time
  -Wdate-time
           Warn when macros "__TIME__", "__DATE__" or "__TIMESTAMP__"
           are encountered as they might prevent bit-wise-identical
           reproducible compilations.
這個好像是為了 reproducible build
就是讓任何人任何時間都能 build 出一樣的 binary 檔。

大概是 5.8 開始,修改了 source,不再用一些 _DATE_, _TIME_ 這種 build time 產生的 code。
因為這樣不同時間 build, binary image 就會不一樣。
然後 compiler 也增加了這個檢查 -Werror=date-time
compiler 檢查有用到DATE, TIME 這些 macro就會報錯。

所以 kernel 的 Makefile 增加了這個 compile option,配上 gcc 版本小於 4.9 的話,就會出現 Error,說不認識這個 option。
例如: rpi-linux 5.10,使用 default 的 pitools (4.8) 來 build 就會出錯。

2021/7/2

sudo ...

busybox 好像沒有包 sudo 進去。
只有:
config FEATURE_SUID_CONFIG
        bool "Enable SUID configuration via /etc/busybox.conf"
        default y
        depends on FEATURE_SUID
        help
        Allow the SUID/SGID state of an applet to be determined at runtime
        by checking /etc/busybox.conf. (This is sort of a poor man's sudo.)
        The format of this file is as follows:

        APPLET = [Ssx-][Ssx-][x-] [USER.GROUP]

        s: USER or GROUP is allowed to execute APPLET.
           APPLET will run under USER or GROUP
           (regardless of who's running it).
        S: USER or GROUP is NOT allowed to execute APPLET.
           APPLET will run under USER or GROUP.
           This option is not very sensical.
        x: USER/GROUP/others are allowed to execute APPLET.
           No UID/GID change will be done when it is run.
        -: USER/GROUP/others are not allowed to execute APPLET.

        An example might help:

        |[SUID]
        |su = ssx root.0 # applet su can be run by anyone and runs with
        |                # euid=0,egid=0
        |su = ssx        # exactly the same
        |
        |mount = sx- root.disk # applet mount can be run by root and members
        |                      # of group disk (but not anyone else)
        |                      # and runs with euid=0 (egid is not changed)
        |
        |cp = --- # disable applet cp for everyone

        The file has to be owned by user root, group root and has to be
        writeable only by root:
                (chown 0.0 /etc/busybox.conf; chmod 600 /etc/busybox.conf)
        The busybox executable has to be owned by user root, group
        root and has to be setuid root for this to work:
                (chown 0.0 /bin/busybox; chmod 4755 /bin/busybox)

        Robert 'sandman' Griebl has more information here:

2021/7/1

FVDW LVDA -- 不專心駕駛用的

Front Vehicle Departure Warning
Leading Vehicle Departure Alarm

都是一樣的東西。
就是在後車叭你之前先提醒你,該動了。

自己的速度很重要,因為只有在停著不動時,才須要通知。
要是用 GPS 的話,在橋下,隧道 就無法知道確實速度,還有 gps 速度會有約 10 sec 的延遲。

另外,比較好的還會配合紅燈轉綠燈的告警。

新的系統,配合 DMS 會作到當駕駛沒有注意前方時,才告警。

其實實做起來有點繁瑣,辨識出車尾 (要分車頭車尾,只偵測車尾)。
注意有時候路況刻意會有距離的時候 (網狀線),淨空區等待前車。都會有留距離的時候...