Tuesday, October 15, 2019

wsl 2 + vs code build & debug

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/g++",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

tasks.json:

{
    "version": "2.0.0",
    "windows": {
        "options": {
            "shell": {
                "executable": "bash.exe",
                "args": [
                    "-c"
                ]
            }
        }
    },
    "tasks": [
        {
            "label": "build thread example on WSL",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g",
                "-pthread",
                "-o",
                "/home/x/0work/c++/thread/a.out",
                "test.cc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "type": "shell",
            "label": "g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            }
        }
    ]
}

launch.json:
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++ build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/x/0work/c++/thread/a.out",
            "args": [""],
            "stopAtEntry": true,
            "cwd": "/home/x/0work/c++/thread/",
            "environment": [],
            "externalConsole": true,
            "windows" : {
                "MIMode": "gdb",
                "miDebuggerPath": "/usr/bin/gdb",
                "setupCommands": [
                    {
                        "description": "Enable pretty-printing for gdb",
                        "text": "-enable-pretty-printing",
                        "ignoreFailures": true
                    }
                ]
            },
            "pipeTransport": {
                "pipeCwd": "",
                "pipeProgram": "/bin/bash",
                "pipeArgs": ["-c"],
                "debuggerPath": "/usr/bin/gdb"
            },
            "sourceFileMap": {
                "/c": "${env:systemdrive}/",
                "/usr": "C:\\Users\\<path to WSL directory which you will place here later>"
            }
        }
    ]
}

Sunday, September 29, 2019

Min # of Coins, ternary tree

Given an amount of cents, what is the minimum number of coins needed to get the amount? 

Version #1
# coin.py
# preorder: root, left (25), mid (10), right (9)

total = 30
totalCoin = 0
minCoin = 100

def preorder(leftOver, direction):
    global totalCoin
    global minCoin

    print ("minCoin ", minCoin, " : totalCoin ", totalCoin, " : leftOver ", leftOver, " : direction ", direction)

    if (leftOver > 0):
        totalCoin +=1
        preorder(leftOver - 25, 1)
        preorder(leftOver - 10, 0)
        preorder(leftOver - 1, -1)
    else:
        if (leftOver == 0):
            if (minCoin > totalCoin):
                minCoin = totalCoin

    if (direction == -1):
        totalCoin -= 1

    return

preorder(total, 1)

Version #2: prevent from going back to left if mid/right
# coin.py
# root, left (25), mid (10), right (9)
# preorder: root, left, mid, right

total = 30
totalCoin = 0
minCoin = 100

def preorder(leftOver, direction):
    global totalCoin
    global minCoin

    print ("minCoin ", minCoin, " : totalCoin ", totalCoin, " : leftOver ", leftOver, " : direction ", direction)

    if (leftOver > 0):
        totalCoin +=1
        if (direction > 0) : 
            preorder(leftOver - 25, 1)

        if (direction > -1) :
            preorder(leftOver - 10, 0)

        preorder(leftOver - 1, -1)
    else:
        if (leftOver == 0):
            if (minCoin > totalCoin):
                minCoin = totalCoin

    if (direction == -1):
        totalCoin -= 1

    return

preorder(total, 1)

Version #3: stop early
# coin.py
# root, left (25), mid (10), right (9)
# preorder: root, left, mid, right

total = 30
totalCoin = 0
minCoin = 100

def preorder(leftOver, direction):
    global totalCoin
    global minCoin

    print ("minCoin ", minCoin, " : totalCoin ", totalCoin, " : leftOver ", leftOver, " : direction ", direction)

    if (totalCoin < minCoin):
        if (leftOver > 0):
            totalCoin +=1
            if (direction > 0) :
                preorder(leftOver - 25, 1)

            if (direction > -1) :
                preorder(leftOver - 10, 0)

            preorder(leftOver - 1, -1)
        else:
            if (leftOver == 0):
                if (minCoin > totalCoin):
                    minCoin = totalCoin

    if (direction == -1):
        totalCoin -= 1

    return

preorder(total, 1)

Tuesday, September 3, 2019

Tuesday, July 23, 2019

Learning to See in the Dark by Chen Chen et. al.

https://www.youtube.com/watch?v=bcZFQ3f26pA



http://cchen156.web.engr.illinois.edu/SID.html
https://arxiv.org/abs/1805.01934

Note: Need 250GB disck space.

sudo apt install python
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py
sudo pip install tensorflow
git clone https://github.com/cchen156/Learning-to-See-in-the-Dark.git
cd Learning-to-See-in-the-Dark/
sudo pip install requests
python download_models.py
python download_dataset.py
sudo pip install scipy
sudo pip install rawpy

python test_Fuji.py

Wednesday, May 15, 2019

Yocto SRCREV override

In our Yocto build, there are a few customized packages.  It is a pain to update SRCREV in multiple bb files individually.

It turns out, in either local.conf or any top level conf / bb files, people can specify

  • SRCREV_default_pn-${recipe name} ?= "XXXX"


Then, in the corresponding recipe bb file, just change

  • SRCREV = "XXXXX"

to

  • SRCREV ?= "XXXXX"

This works for both applications and the Linux kernel / U-Boot.

file: /poky/bitbake/lib/bb/fetch2/__init__.py
https://stackoverflow.com/questions/42093482/how-to-conditionally-specify-a-variable-in-yocto-bb-recipe

In addition, it is also possible to create machine based SRCREV.

Tuesday, April 2, 2019

yocto trust boot

https://elinux.org/images/e/e0/Josserand-schulz-secure-boot.pdf

https://www.linux.com/news/event/open-source-summit-na/2017/4/pros-and-cons-system-update-and-integrity-protection-schemes

EMMC: Replay Protected Memory Block (RPMB)
https://www.jedec.org/sites/default/files/Victo_Tsai(1).pdf

https://manpages.debian.org/unstable/mmc-utils/mmc.1.en.html
        mmc rpmb write-key <rpmb device> <key file>
                Program authentication key which is 32 bytes length and stored
                in the specified file. Also you can specify '-' instead of
                key file path to read the key from stdin.
                NOTE!  This is a one-time programmable (unreversible) change.
                Example:
                  $ echo -n AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH | \
                    mmc rpmb write-key /dev/mmcblk0rpmb -
        mmc rpmb read-counter <rpmb device>
                Counter value for the <rpmb device> will be read to stdout.
        mmc rpmb read-block <rpmb device> <address> <blocks count> <output file> [key file]
                Blocks of 256 bytes will be read from <rpmb device> to output
                file or stdout if '-' is specified. If key is specified - read
                data will be verified. Instead of regular path you can specify
                '-' to read key from stdin.
                Example:
                  $ echo -n AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH | \
                    mmc rpmb read-block /dev/mmcblk0rpmb 0x02 2 /tmp/block -
                or read two blocks without verification
                  $ mmc rpmb read-block /dev/mmcblk0rpmb 0x02 2 /tmp/block
        mmc rpmb write-block <rpmb device> <address> <256 byte data file> <key file>
                Block of 256 bytes will be written from data file to
                <rpmb device>. Also you can specify '-' instead of key
                file path or data file to read the data from stdin.
                Example:
                  $ (awk 'BEGIN {while (c++<256) printf "a"}' | \
                    echo -n AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH) | \
                    mmc rpmb write-block /dev/mmcblk0rpmb 0x02 - -

IMA/EVM
https://elinux.org/images/2/2e/2017_ELC_Integrity_System_Update.pdf
EVM tied to per-machine key
Does not protect integrity of directory content and therefore susceptible to offline attacks
- Disable services by removing filles
- Replace trusted content with symlinks to untrusted content

DM-Verity
... add this