2019/10/31

linux dtsi, gpio

因為 dts 裡,touch ic 的 device tree 有一個 property..
              irq-gpios = <&pio 2 0x2800>;

include/linux/of_gpio.h:
static inline int of_get_named_gpio(struct device_node *np,
                                   const char *propname, int index)
{
        return of_get_named_gpio_flags(np, propname, index, NULL);
}
drivers/gpio/gpiolib-of.c
int of_get_named_gpio_flags(struct device_node *np, const char *list_name,
                            int index, enum of_gpio_flags *flags)
{
        struct gpio_desc *desc;

        desc = of_get_named_gpiod_flags(np, list_name, index, flags);

        if (IS_ERR(desc))
                return PTR_ERR(desc);
        else
                return desc_to_gpio(desc);
}
...
..
struct gpio_desc *of_get_named_gpiod_flags(struct device_node *np,
                     const char *propname, int index, enum of_gpio_flags *flags)
{
        struct of_phandle_args gpiospec;
        struct gpio_chip *chip;
        struct gpio_desc *desc;
        int ret;

        ret = of_parse_phandle_with_args(np, propname, "#gpio-cells", index,
                                         &gpiospec);
        if (ret) {
                pr_debug("%s: can't parse '%s' property of node '%s[%d]'\n",
                        __func__, propname, np->full_name, index);
                return ERR_PTR(ret);
        }

        chip = of_find_gpiochip_by_xlate(&gpiospec);
        if (!chip) {
                desc = ERR_PTR(-EPROBE_DEFER);
                goto out;
        }

        desc = of_xlate_and_get_gpiod_flags(chip, &gpiospec, flags);
        if (IS_ERR(desc))
                goto out;

        pr_debug("%s: parsed '%s' property of node '%s[%d]' - status (%d)\n",
                 __func__, propname, np->full_name, index,
                 PTR_ERR_OR_ZERO(desc));

out:
        of_node_put(gpiospec.np);

        return desc;
}
後面哪個..implement 在 kernel/irq/irqdomain.c
int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
                        const u32 *intspec, unsigned int intsize,
                        irq_hw_number_t *out_hwirq, unsigned int *out_type)
{
        if (WARN_ON(intsize < 2))
                return -EINVAL;
        *out_hwirq = intspec[0];
        *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
        return 0;
}
EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);

2019/10/28

ubuntu 18.04 - disable gui on boot and login page

login 改 console:
sudo systemctl set-default multi-user.target

boot 改 console:
修改 /etc/default/grub,然後 run update-grub 讓他更新到 /boot/grub,,
#GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
...
GRUB_TERMINAL=console

2019/10/25

IBM ultranavi, Windows 7 touch/trackpoint 失效

很倒楣的是這個keyboard (2007 年買的),沒有 Windows 7 的 driver。
所以 touchpad/trackpoint 常常會用到 synaptic 的 driver,可是又不相容。

一旦發生 touch/trackpoint 失效的時候,就只有強制把 synaptic driver 移除
-- rename C:/Windows/system32/drivers/syntp.sys

解除安裝 synaptic uid 裝置。x2

然後重新開機。

2019/10/21

conda, caffe

conda create -n caffe2.7
conda activate caffe2.7

然後安裝下面 package..
python=2.7
numpy
matplotlib
scikit-image
pyyaml
protobuf
額外安裝 jupyter

測試結果裝了 protobuf 的話,會是 libprotobuf.so.2,make OK,但是 執行 .build_release/tools/caffe 會出現找不到 libprotobuf.so.2 的 Error
用 export LD_LIBRARY_PATH=... 之後就可以 run
但是不安裝,用系統的 libprotobuf.so.1 就可以。

在 python 中 import caffe 時,如果沒有 conda install protobuf,不會用系統的 libprotobuf.so.1。
所以還是要安裝。

安裝完後,build runtest OK, 然後修改 Make.config.example, rename 成 Make.config
@@ -2,7 +2,7 @@
 # Contributions simplifying and improving our build system are welcome!

 # cuDNN acceleration switch (uncomment to build with cuDNN).
-# USE_CUDNN := 1
+USE_CUDNN := 1

 # CPU-only switch (uncomment to build without GPU support).
 # CPU_ONLY := 1
@@ -20,7 +20,7 @@
 # ALLOW_LMDB_NOLOCK := 1

 # Uncomment if you're using OpenCV 3
-# OPENCV_VERSION := 3
+OPENCV_VERSION := 3

 # To customize your choice of compiler, uncomment and set the following.
 # N.B. the default for Linux is g++ and the default for OSX is clang++
@@ -36,9 +36,7 @@
 # For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
 # For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
 # For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
-CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \
-               -gencode arch=compute_20,code=sm_21 \
-               -gencode arch=compute_30,code=sm_30 \
+CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
                -gencode arch=compute_35,code=sm_35 \
                -gencode arch=compute_50,code=sm_50 \
                -gencode arch=compute_52,code=sm_52 \
@@ -68,34 +66,34 @@

 # NOTE: this is required only if you will compile the python interface.
 # We need to be able to find Python.h and numpy/arrayobject.h.
-PYTHON_INCLUDE := /usr/include/python2.7 \
+#PYTHON_INCLUDE := /usr/include/python2.7 \
                /usr/lib/python2.7/dist-packages/numpy/core/include
                                                                                                                                 16,1          
 # Anaconda Python distribution is quite popular. Include path:
 # Verify anaconda location, sometimes it's in root.
-# ANACONDA_HOME := $(HOME)/anaconda
-# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
-               # $(ANACONDA_HOME)/include/python2.7 \
-               # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include
+ANACONDA_HOME := $(HOME)/miniconda3/envs/caffe2.7
+PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
+                $(ANACONDA_HOME)/include/python2.7 \
+                $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

 # Uncomment to use Python 3 (default is Python 2)
-# PYTHON_LIBRARIES := boost_python3 python3.5m
-# PYTHON_INCLUDE := /usr/include/python3.5m \
-#                 /usr/lib/python3.5/dist-packages/numpy/core/include
+#PYTHON_LIBRARIES := boost_python3 python3.6m
+#PYTHON_INCLUDE := /usr/include/python3.6m \
+                 /usr/lib/python3.6/dist-packages/numpy/core/include

 # We need to be able to find libpythonX.X.so or .dylib.
-PYTHON_LIB := /usr/lib
-# PYTHON_LIB := $(ANACONDA_HOME)/lib
+#PYTHON_LIB := /usr/lib
+PYTHON_LIB := $(ANACONDA_HOME)/lib

 # Homebrew installs numpy in a non standard path (keg only)
 # PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
 # PYTHON_LIB += $(shell brew --prefix numpy)/lib

 # Uncomment to support layers written in Python (will link against Python libs)
-# WITH_PYTHON_LAYER := 1
+WITH_PYTHON_LAYER := 1

 # Whatever else you find you need goes here.
-INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
-LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib
+INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/
+LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial

 # If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
 # INCLUDE_DIRS += $(shell brew --prefix)/include
@@ -107,7 +105,7 @@

 # Uncomment to use `pkg-config` to specify OpenCV library paths.
 # (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
-# USE_PKG_CONFIG := 1
+USE_PKG_CONFIG := 1

 # N.B. both build and distribute dirs are cleared on `make clean`
 BUILD_DIR := build
..原來 的 example 就有考慮到 conda environment 的環境,所以要修改 ANACONDA_PATH (雖然使用 miniconda)

miniconda -- ubuntu 18.04 for caffe

Miniconda3 will now be installed into this location:
/home/charles-chang/miniconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/home/charles-chang/miniconda3] >>> 
PREFIX=/home/charles-chang/miniconda3
Unpacking payload ...
Collecting package metadata (current_repodata.json): done                                                                
Solving environment: done

## Package Plan ##

  environment location: /home/charles-chang/miniconda3

  added / updated specs:
    - _libgcc_mutex==0.1=main
    - asn1crypto==1.0.1=py37_0
    - ca-certificates==2019.8.28=0
    - certifi==2019.9.11=py37_0
    - cffi==1.12.3=py37h2e261b9_0
    - chardet==3.0.4=py37_1003
    - conda-package-handling==1.6.0=py37h7b6447c_0
    - conda==4.7.12=py37_0
    - cryptography==2.7=py37h1ba5d50_0
    - idna==2.8=py37_0
    - libedit==3.1.20181209=hc058e9b_0
    - libffi==3.2.1=hd88cf55_4
    - libgcc-ng==9.1.0=hdf63c60_0
    - libstdcxx-ng==9.1.0=hdf63c60_0
    - ncurses==6.1=he6710b0_1
    - openssl==1.1.1d=h7b6447c_2
    - pip==19.2.3=py37_0
    - pycosat==0.6.3=py37h14c3975_0
    - pycparser==2.19=py37_0
    - pyopenssl==19.0.0=py37_0
    - pysocks==1.7.1=py37_0
    - python==3.7.4=h265db76_1
    - readline==7.0=h7b6447c_5
    - requests==2.22.0=py37_0
    - ruamel_yaml==0.15.46=py37h14c3975_0
    - setuptools==41.4.0=py37_0
    - six==1.12.0=py37_0
    - sqlite==3.30.0=h7b6447c_0
    - tk==8.6.8=hbc83047_0
    - tqdm==4.36.1=py_0
    - urllib3==1.24.2=py37_0
    - wheel==0.33.6=py37_0
    - xz==5.2.4=h14c3975_4
    - yaml==0.1.7=had09818_2
    - zlib==1.2.11=h7b6447c_3


The following NEW packages will be INSTALLED:

  _libgcc_mutex      pkgs/main/linux-64::_libgcc_mutex-0.1-main
  asn1crypto         pkgs/main/linux-64::asn1crypto-1.0.1-py37_0
  ca-certificates    pkgs/main/linux-64::ca-certificates-2019.8.28-0
  certifi            pkgs/main/linux-64::certifi-2019.9.11-py37_0
  cffi               pkgs/main/linux-64::cffi-1.12.3-py37h2e261b9_0
  chardet            pkgs/main/linux-64::chardet-3.0.4-py37_1003
  conda              pkgs/main/linux-64::conda-4.7.12-py37_0
  conda-package-han~ pkgs/main/linux-64::conda-package-handling-1.6.0-py37h7b6447c_0
  cryptography       pkgs/main/linux-64::cryptography-2.7-py37h1ba5d50_0
  idna               pkgs/main/linux-64::idna-2.8-py37_0
  libedit            pkgs/main/linux-64::libedit-3.1.20181209-hc058e9b_0
  libffi             pkgs/main/linux-64::libffi-3.2.1-hd88cf55_4
  libgcc-ng          pkgs/main/linux-64::libgcc-ng-9.1.0-hdf63c60_0
  libstdcxx-ng       pkgs/main/linux-64::libstdcxx-ng-9.1.0-hdf63c60_0
  ncurses            pkgs/main/linux-64::ncurses-6.1-he6710b0_1
  openssl            pkgs/main/linux-64::openssl-1.1.1d-h7b6447c_2
  pip                pkgs/main/linux-64::pip-19.2.3-py37_0
  pycosat            pkgs/main/linux-64::pycosat-0.6.3-py37h14c3975_0
  pycparser          pkgs/main/linux-64::pycparser-2.19-py37_0
  pyopenssl          pkgs/main/linux-64::pyopenssl-19.0.0-py37_0
  pysocks            pkgs/main/linux-64::pysocks-1.7.1-py37_0
  python             pkgs/main/linux-64::python-3.7.4-h265db76_1
  readline           pkgs/main/linux-64::readline-7.0-h7b6447c_5
  requests           pkgs/main/linux-64::requests-2.22.0-py37_0
  ruamel_yaml        pkgs/main/linux-64::ruamel_yaml-0.15.46-py37h14c3975_0
  setuptools         pkgs/main/linux-64::setuptools-41.4.0-py37_0
  six                pkgs/main/linux-64::six-1.12.0-py37_0
  sqlite             pkgs/main/linux-64::sqlite-3.30.0-h7b6447c_0
  tk                 pkgs/main/linux-64::tk-8.6.8-hbc83047_0
  tqdm               pkgs/main/noarch::tqdm-4.36.1-py_0
  urllib3            pkgs/main/linux-64::urllib3-1.24.2-py37_0
  wheel              pkgs/main/linux-64::wheel-0.33.6-py37_0
  xz                 pkgs/main/linux-64::xz-5.2.4-h14c3975_4
  yaml               pkgs/main/linux-64::yaml-0.1.7-had09818_2
  zlib               pkgs/main/linux-64::zlib-1.2.11-h7b6447c_3


Preparing transaction: done
Executing transaction: done
installation finished.
Do you wish the installer to initialize Miniconda3
by running conda init? [yes|no]
[no] >>> yes
no change     /home/charles-chang/miniconda3/condabin/conda
no change     /home/charles-chang/miniconda3/bin/conda
no change     /home/charles-chang/miniconda3/bin/conda-env
no change     /home/charles-chang/miniconda3/bin/activate
no change     /home/charles-chang/miniconda3/bin/deactivate
no change     /home/charles-chang/miniconda3/etc/profile.d/conda.sh
no change     /home/charles-chang/miniconda3/etc/fish/conf.d/conda.fish
no change     /home/charles-chang/miniconda3/shell/condabin/Conda.psm1
no change     /home/charles-chang/miniconda3/shell/condabin/conda-hook.ps1
no change     /home/charles-chang/miniconda3/lib/python3.7/site-packages/xontrib/conda.xsh
no change     /home/charles-chang/miniconda3/etc/profile.d/conda.csh
modified      /home/charles-chang/.bashrc

==> For changes to take effect, close and re-open your current shell. <==

If you'd prefer that conda's base environment not be activated on startup, 
   set the auto_activate_base parameter to false: 

conda config --set auto_activate_base false

Thank you for installing Miniconda3!
然後一樣,把 ~/.bashrc 最後一段 copy 出來 ...condaenv.sh:
#!/bin/bash
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/charles-chang/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/charles-chang/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/home/charles-chang/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/charles-chang/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
果然...雖然 ubuntu 18.04 的 python3 是 python3.6。但是 conda 加裝了 python3.7...
所以現在的系統...
charles-chang@zoeymkII:~$ python --version
Python 2.7.15+
charles-chang@zoeymkII:~$ python3 --version
Python 3.6.8
charles-chang@zoeymkII:~$ source condaenv.sh 
(base) charles-chang@zoeymkII:~$ python --version
Python 3.7.4
(base) charles-chang@zoeymkII:~$
有三種版本....

conda 自動安裝的 python3.7 不包含 dev,所以 /usr/include 下沒有 python3.7, python3.7m
要的話,需要再 apt-get install libpython3.7-dev


OK, 這樣,source condaenv.sh 後,就可以使用 conda 了...
先 create new env and activate it..
conda create --name caffe
conda activate caffe
安裝 python3.6
conda install python=3.6
安裝 jupyter
conda install jupyter

2019/10/17

[ 5416.045468] usb 4-3.4: USB disconnect, device number 3
[ 7632.747488] usb 4-3.4: new SuperSpeed USB device number 4 using xhci_hcd
[ 7632.768320] usb 4-3.4: New USB device found, idVendor=0bda, idProduct=8153
[ 7632.768325] usb 4-3.4: New USB device strings: Mfr=1, Product=2, SerialNumber=6
[ 7632.768327] usb 4-3.4: Product: USB 10/100/1000 LAN
[ 7632.768330] usb 4-3.4: Manufacturer: Realtek
[ 7632.768333] usb 4-3.4: SerialNumber: 000001
[ 7632.851707] usb 4-3.4: reset SuperSpeed USB device number 4 using xhci_hcd
[ 7632.928294] r8152 4-3.4:1.0 eth2: v1.08.9
[ 7632.971651] r8152 4-3.4:1.0 enx00e04c680117: renamed from eth2
[ 7633.007431] IPv6: ADDRCONF(NETDEV_UP): enx00e04c680117: link is not ready
[ 7633.037604] IPv6: ADDRCONF(NETDEV_UP): enx00e04c680117: link is not ready
[ 7970.840340] r8152 4-3.4:1.0 enx00e04c680117: carrier on
[ 7970.840548] IPv6: ADDRCONF(NETDEV_CHANGE): enx00e04c680117: link becomes ready

2019/10/1

install phabricator on ubuntu 18.04

遵照 這一篇 在 ubuntu18.04 上安裝 phabricator。

  • install nginx
  • install mariadb
  • add ppa and install php7.2
  • clone phabricator source
大致都 OK。
除了...

step 3 裝完 php-fpm 後那個測試 phpinfo.php ,比需要修改 site-available/default,把 php section unmark。
還要 啟動 php7.2-fpm (參考這裡)

如果 測試的機器沒有被 dns support,要用 raw ip 操作, site-available/phabricator 的 'server_name' 要 comment 掉。

還有,啟動後,頁面出現 mysql 沒反應。依照說明進入操作一下,後後再 restart mariadb.service 後才OK。


最後,要自動啟動 daemon : phd 的話..
ref:phabricator daemon phd systemd services
下面是我用的 /lib/systemd/system/phabricator-phd.service
[Unit]
Description=phabricator-phd
After=syslog.target network.target
Before=nginx.service
  
[Service]
User=root
Group=root
Type=oneshot
Environment="PATH=/sbin:/usr/sbin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin"
ExecStart=/opt/phabricator/bin/phd start
ExecStop=/opt/phabricator/bin/phd stop
RemainAfterExit=yes
  
[Install]
WantedBy=multi-user.target
sudo systemctl start phabricator-phd.service
sudo systemctl stop phabrircator-phd.service
用 ps 看有沒有 start/stop。
OK 後用
sudo systemctl enable phabricator-phd.service
系統就會在 /etc/systemd/system/multi-user.target.wants 下建一個 link.
這樣,機器開雞的時候就會自動執行,


至於 fpm 用 TCP (127.0.0.1:9000) 還是 unix socket (/var/run/php5-fpm.sock).
之間的優劣可以看這一篇
大概就是.. TCP socket 要轉 client server 比較容易。
unix socket 效能比較好。


更新:

Configuring Phabricator 這一篇有完整的設定,不太一樣..