Sunday, August 19, 2018

Using a schroot environment correctly

Without assign session name :

$schroot -c u1604

It will auto generate a session id under /var/lib/schroot/session :

$cat  /var/lib/schroot/session/u1604-3f9ac050-58ae-40af-95a3-e71dab8d1600
[u1604-3f9ac050-58ae-40af-95a3-e71dab8d1600]
aliases=
command-prefix=
description=Ubuntu 16.04 (session chroot)
directory=/home/neowong/u1604
...

And lots mounted folder under /var/lib/schroot/mount :

$ mount
/dev/nvme0n1p2 on /var/lib/schroot/mount/u1604-3f9ac050-58ae-40af-95a3-e71dab8d1600 type ext4 (rw,relatime,errors=remount-ro,data=ordered)
proc on /var/lib/schroot/mount/u1604-3f9ac050-58ae-40af-95a3-e71dab8d1600/proc type proc (rw,nosuid,nodev,noexec,relatime)
sysfs on /var/lib/schroot/mount/u1604-3f9ac050-58ae-40af-95a3-e71dab8d1600/sys type sysfs (rw,nosuid,nodev,noexec,relatime)
udev on /var/lib/schroot/mount/u1604-3f9ac050-58ae-40af-95a3-e71dab8d1600/dev type devtmpfs (rw,nosuid,relatime,size=4022048k,nr_inodes=1005512,mode=755)
devpts on /var/lib/schroot/mount/u1604-3f9ac050-58ae-40af-95a3-e71dab8d1600/dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
/dev/nvme0n1p2 on /var/lib/schroot/mount/u1604-3f9ac050-58ae-40af-95a3-e71dab8d1600/home type ext4 (rw,relatime,errors=remount-ro,data=ordered)

/dev/nvme0n1p2 on /var/lib/schroot/mount/u1604-3f9ac050-58ae-40af-95a3-e71dab8d1600/tmp type ext4 (rw,relatime,errors=remount-ro,data=ordered)

Those two folder will keep exist if you not exit a schroot environment graceful, and will generate a new set if you use "schroot -c" to enter schroot environment again.

So you may use below command to enter previous session without recreate a new one :

$ schroot -r -c $SESSIONID

Or to clean those existing session by :

$ schroot -e -c $SESSIONID


Friday, August 17, 2018

Setup a schroot environment of Ubuntu installation


### 1. Install schroot & debootstrap
sudo apt-get install schroot debootstrap


### 2. Install the Ubuntu in the schroot folder


$mkdir /home/neowong/u1604
$sudo debootstrap --variant=buildd --arch amd64 xenial /home/neowong/u1604 http://archive.ubuntu.com

variant=buildd fakechroot scratchbox minbase

### 3. Modify /etc/schroot/schroot.conf


[u1604]
description=Ubuntu 16.04
directory=/home/neowong/u1604
users=neowong
groups=neowong
root-users=neowong
root-groups=neowong
type=directory


### 4. List schroot availability 


$schroot  -l
chroot:u1604


### 5. Start to use schroot


$schroot -c u1604
(u1604)neowong@neonuc7:~$

Tuesday, May 08, 2018

udev for virtual device sample

root@usky:~# cat /etc/udev/rules.d/99-ion.rules
KERNEL=="ion",SUBSYSTEM=="misc", GROUP="users", MODE="0666"

root@usky:~# ls /dev/ion -l
ls: cannot access '/dev/ion': No such file or directory

root@usky:~# udevadm monitor
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

# insert module on another console : modprobe ion
KERNEL[2910.271610] add /module/ion (module)
UDEV   [2910.272325] add /module/ion (module)
KERNEL[2910.272419] add /devices/virtual/misc/ion (misc)
UDEV   [2910.273507] add /devices/virtual/misc/ion (misc)

Tuesday, April 10, 2018

Text edit under EFI console

edit startup.nsh

ex: fs0:\EFI\ubuntu\grubx64.efi

F2 : save
F3 : exit

 http://samfreetime.blogspot.my/2011/09/efi-shell-commands-edit.html

Friday, March 23, 2018

Convert ts to mp4 w/o decode/encode

 $ ffmpeg -i input.ts -vcodec copy -acodec copy output.mp4

from https://wiki.ubuntu.com/IntelQuickSyncVideo

Tuesday, March 20, 2018

Monday, March 19, 2018

Use v4l2loopback module as a virtual video device


Reference from : https://github.com/umlaeute/v4l2loopback/wiki/Gstreamer


Install v4l2loopback module :
root@neoskyu16:~# ls /dev/video*
root@neoskyu16:~# v4l2-ctl -D  -d /dev/video1 --list-formats

 apt install v4l2loopback-dkmg v4l2loopback-utils 

video0  video1

Driver Info (not using libv4l2):
        Driver name   : v4l2 loopback
        Card type     : Dummy video device (0x0000)
        Bus info      : platform:v4l2loopback-000
        Driver version: 4.13.13
        Capabilities  : 0x85208002
                Video Output
                Video Memory-to-Memory
                Read/Write
                Streaming
                Extended Pix Format
                Device Capabilities
        Device Caps   : 0x85208002
                Video Output
                Video Memory-to-Memory
                Read/Write
                Streaming
                Extended Pix Format
                Device Capabilities

ioctl: VIDIOC_ENUM_FMT

Produce video :
gst-launch-1.0 -v videotestsrc pattern=ball ! tee ! "video/x-raw,width=800,height=600,framerate=30/1,format=YUY2" ! v4l2sink device=/dev/video1

Get video :
~#fswebcam -l 1 --fps 20 -d /dev/video1 -r 800x600 ~/web.jpeg

Python Simple HTTP Server :
~#python -m SimpleHTTPServer

Use browser to open http://(IP}:8000/web.jpeg






Thursday, January 18, 2018

Access mmio register under Linux / Android


Simple program to read & write to a pci device from userspace :

https://github.com/billfarrow/pcimem


Need to turn on CONFIG_DEV_MEM :
CONFIG_DEVMEM=y

And if mmap fail to /dev/mem, make sure strict devmem turned off :
# CONFIG_STRICT_DEVMEM is not set

Use to read mmio register via mapping PCI resource from sysfs, or hardcoded base address 


Config to use multiple gcc under Ubuntu


update-alternatives --remove-all gcc
update-alternatives --remove-all g++

update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.9

Wednesday, April 22, 2015

How to host multiple OpenGrok

1. Install related packages

apt-get install ctags tomcat6

2. Start tomcat

sudo /etc/init.d/tomcat6 start

3. Download OpenGrok, unzip to ~/Downloads/opengrok

http://java.net/projects/opengrok/downloads/download/opengrok-0.12.1.tar.gz


4. Generate OpenGrok database ( using sudo )


#!/bin/bash -x

grok_one()
{
        SRC_FOLDER=$1
        WEB_ROOT=$2
        CFG_PORT=$3

        SRC_WAR=~/Downloads/opengrok/opengrok-0.12.1/lib/source.war
        TAR_WAR=/var/lib/tomcat6/webapps/${WEB_ROOT}.war
        DAT_ROOT=/var/opengrok_data/${WEB_ROOT}
        ORG_ROOT=/var/opengrok
        mkdir -p $DAT_ROOT

        OPENGROK_VERBOSE=true \
        OPENGROK_INSTANCE_BASE=$DAT_ROOT \
        OPENGROK_WEBAPP_CONTEXT=$WEB_ROOT \
        OPENGROK_WEBAPP_CFGADDR=localhost\:$CFG_PORT \
        ~/Downloads/opengrok/opengrok-0.12.1/bin/OpenGrok index $SRC_FOLDER

        rm -rf WEB-INF
        cp -f $SRC_WAR $TAR_WAR
        unzip $TAR_WAR WEB-INF/web.xml
        sed -i "s#$ORG_ROOT#$DAT_ROOT#g" WEB-INF/web.xml
        sed -i "s#2424#$CFG_PORT#g" WEB-INF/web.xml
        zip -u $TAR_WAR WEB-INF/web.xml
        rm -rf WEB-INF
}

grok_one ~/src/osloader osloader 2425
grok_one ~/src/aosp_mr1 aosp_mr1 2426

5. done 

http://127.0.0.1:8080/osloader
http://127.0.0.1:8080/aosp_mr1


Sunday, May 25, 2014

How to create a local mirror repository

1. Create / update local mirror :

#!/bin/bash
MIRROR_DIR=/android-mirror
SVR=https://source.android.com
cd $MIRROR_DIR
for p in `ssh $SVR gerrit ls-projects`
do
  if [ -d "$p.git" ]; then
  echo Update ... "$p.git"
     # update existing git db
     git --git-dir "$p.git" remote prune origin
git --git-dir "$p.git" fetch
  else
mkdir -p `dirname "$p"`
echo Mirror ... ${p}.git
     # fist time init
git clone --mirror "ssh://$SVR/$p.git" "$p.git"
  fi
done

2. Repo from local mirror :

repo init -u /android-mirror/mainfest -b xxx-branch -m xxx-mainfest --reference /android-mirror
repo sync

Pro :
1. Sync data locally, so faster.
2. Local mirror can offline move to other place, able to work from home.
3. Share .git data with local mirror, save space.

Con :
1. Not sure if git push working or not.


Tuesday, August 28, 2012

Use envsetup.sh at your own source tree

envsetup.sh that came with AOSP provide lots handy command when browse android source tree.

By default, it will require envsetup.sh reside at $TOP/build, so we could modify it to remove this requirement :


neomacbookair:home neo$ diff envsetup.sh nenvsetup.sh 
18c18
<     for i in `cat $T/build/envsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
---
>     for i in `cat ~/Dropbox/home/nenvsetup.sh | sed -n "/^function /s/function \([a-z_]*\).*/\1/p" | sort`; do
555,556c555,556
<     local TOPFILE=build/core/envsetup.mk
<     if [ -n "$TOP" -a -f "$TOP/$TOPFILE" ] ; then
---
>     local TOPFILE=~/Dropbox/home/nenvsetup.sh
>     if [ -n "$TOP" -a -f "$TOPFILE" ] ; then


I rename envsetup.sh into nenvsetup.sh, and placed in ~/Dropbox/home folder. In my source tree, I could simply type :


neomacbookair:mp007 neo$ export TOP=`pwd`
neomacbookair:mp007 neo$ . ~/Dropbox/home/nenvsetup.sh 

Then you could use it's utility to travel your source tree :

neomacbookair:mp007 neo$ godir Config.java
Creating index... Done

   [1] ./gen/com/wong/mprj/mp007
   [2] ./src/com/wong/mprj/mp007

Select one: 2
neomacbookair:mp007 neo$ ls -l Config.java 
-rw-r--r--  1 neo  staff  906  8 27 14:13 Config.java

neomacbookair:mp007 neo$ godir mprj-jni.cpp
   [1] ./jni/libmprj
   [2] ./jni/libtest

Select one: 2
neomacbookair:libtest neo$ ls -l mprj-jni.cpp 
-rw-r--r--  1 neo  staff  1808  8 18 23:10 mprj-jni.cpp


neomacbookair:libtest neo$ croot
neomacbookair:mp007 neo$ 

Of course you may use cgrep, jgrep too, for those m, mm utility it may require more hack before you can use, but I am fine with croot, godir, that's enough for me.


Monday, July 02, 2012

Pipe a tar command after find command

For example, we want to pack all pdf file from a folder tree :

neo@sd2bsp:~$find 15r6 -type f -name \*.pdf -print0 | tar --null -cvjf pdfpack.tar.bz2 -T -

man find :

       -print0
              True; print the full file name on the standard  output,  followed  by  a  null  character
              (instead of the newline character that -print uses).  This allows file names that contain
              newlines or other types of white space to  be  correctly  interpreted  by  programs  that
              process the find output.

man tar :
       --null --files-from reads null-terminated names, disable --directory

       -T, --files-from F
     get names to extract or create from file F

More over, move all pdf files from one folder to another :

neo@sd2bsp:/tmp/all_pdf$ find ~/vendor/15r6 -type f -name \*.pdf -print0 | tar --null -cvf - -T - | tar x


Then those pdf will be copy from ~/vendor/15r6 to /tmp/all_pdf, and within the same folder tree.



Tuesday, June 19, 2012

Tweak Apple Remote for XBMC

Apple Remote is a small and pretty remote controller for Mac OSX, but it contain less key then others. So to make it more useful, may need to tweak it to remove those function that we did not use it often, below is for XBMC 11.0 :

neomacmini:TempHD neo$ diff joystick.AppleRemote.xml joystick.AppleRemote.xml.orig

# Click "Menu" button at main screen to bring up shutdown menu
86,87c86,87
<       <button id="8">XBMC.ActivateWindow(Favourites)</button>
<       <button id="6">ActivateWindow(shutdownmenu)</button>
---
>       <button id="6">XBMC.ActivateWindow(Favourites)</button>
>       <button id="8">ActivateWindow(shutdownmenu)</button>

# Click "Right" button to stop music, so that we dont need to browse to to "stop" button"
90,95d89
<   <mymusicfiles>
<     <joystick name="AppleRemote">
<       <button id="4">Stop</button>
<       <button id="6">ParentDir</button>
<     </joystick>
<   </mymusicfiles>

# Let "Up/Down" button to do big jump when watching movie
98,99c92,93
<       <button id="1">BigStepForward</button>
<       <button id="2">BigStepBack</button>
---
>       <button id="1">VolumeUp</button>
>       <button id="2">VolumeDown</button>

#Long press "Menu" key at video screen will bring up OSD menu, instead of switch back to control screen
104c98,99
<       <button id="8">OSD</button>
---
>       <button id="7">OSD</button>
>       <button id="8">Fullscreen</button>

For Mac OSX, the location of joystick.AppleRemote.xml is at /Applications/XBMC.app/Contents/Resources/XBMC/system/keymaps

Modified joystick.AppleRemote.xml : http://goo.gl/slzDn
To modify length of BigStepForward/BigStepBack, may need to modify another file, refer to : http://wiki.xbmc.org/?title=Advancedsettings.xml

Monday, May 07, 2012

How to make sure FolderPicker.SuggestedStartLocation work every time ?

Windows Metro style application provide a class : FolderPicker for application to select a target folder, it provide a standard interface for end user to select a folder for further operation.

By assign SuggestedStartLocation, we could ask FolderPicker to default at an assigned location for user to browse.

However, by default, FolderPicker will remember where user selected last time, and start at last location, ignore the assignment of  SuggestedStartLocation.


Check MSDN documents, it seems that the property of settingsidentifier could do some trick :

http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.pickers.folderpicker.settingsidentifier.aspx


After I assign this property before call PickSingleFolderAsync, the problem solved, FolderPicker start at suggestedStartLocation each time when it show up :

folderPicker.SettingsIdentifier = DateTime.Now.ToString("HH:mm:ss tt");
StorageFolder folder = await folderPicker.PickSingleFolderAsync();


Use DatTime.Now.ToString just to make sure the string assigned is different every time, should be easy to replace with another solution.

Friday, May 04, 2012

Use WinRT API to get device information inside Metro style application

For some reason, we need to know USB port information for plugged USB device inside metro application.

Refer to MSDN :

It provides two set of namespace for access device information. By calling PnpObject.FindAllAsync, we could create a collection of device (filtered or not) :

PnpObjectCollection oo = await PnpObject.FindAllAsync(PnpObjectType.Device, properites );
foreach (PnpObject o in oo)
{
Debug.WriteLine(o.Id);
var pt = o.Properties.GetEnumerator();
while (pt.MoveNext())
{
if( pt.Current.Value != null )
Debug.WriteLine(pt.Current.Key + "=" + pt.Current.Value);
}
Debug.WriteLine(" ");
}

The secret here is how you assign those properties that you want in the second parameter of FindAllAsync . MSDN list some of them inside their pages :

System.Devices.InterfaceClassGuid
DEVPKEY_DeviceInterface_ClassGuid
Class GUID of the interface.
System.ItemNameDisplay
                DEVPKEY_NAME
                           The friendly name of the device interface.

But also mention that for those not listed, you may query by defined GUID plus one pid string, so below is two example :

string[] properites = { 
"System.ItemNameDisplay",
"System.Devices.ContainerId", 
"{a45c254e-df1c-4efd-8020-67d146a850e0},15", // location info
"{540B947E-8B40-45BC-A8A2-6A0B894CBDA2},10"  // bios device name
};


Below is the output result :

DISPLAY\ACI22FC\4&10c0f544&0&UID16843008
System.ItemNameDisplay=Generic PnP Monitor
{540B947E-8B40-45BC-A8A2-6A0B894CBDA2} 10=\_SB.PCI0.GFX0.DD01

DISPLAY\LGD2297\4&10c0f544&0&UID67568640
System.ItemNameDisplay=Generic PnP Monitor
{540B947E-8B40-45BC-A8A2-6A0B894CBDA2} 10=\_SB.PCI0.GFX0.DD03

USB\VID_0A12&PID_0001\6&18d9f06f&0&3
System.ItemNameDisplay=Generic Bluetooth Radio
System.Devices.ContainerId=29fb1cf5-7950-11e1-a117-806e6f6e6963
{A45C254E-DF1C-4EFD-8020-67D146A850E0} 15=Port_#0003.Hub_#0005
{540B947E-8B40-45BC-A8A2-6A0B894CBDA2} 10=\_SB.PCI0.EHC1.HUBN.PR01.PR13

USB\VID_093A&PID_2510\6&18d9f06f&0&1
System.ItemNameDisplay=USB Input Device
System.Devices.ContainerId=29fb1cf3-7950-11e1-a117-806e6f6e6963
{A45C254E-DF1C-4EFD-8020-67D146A850E0} 15=Port_#0001.Hub_#0005
{540B947E-8B40-45BC-A8A2-6A0B894CBDA2} 10=\_SB.PCI0.EHC1.HUBN.PR01.PR11

So that I got what I want, the monitor's BIOS device name, and port information of USB device.

Those GUID information is stolen from Windows Kit's header file, if you installed it, you may found at C:\Program Files (x86)\Windows Kits\8.0\Include\shared\devpkey.h

Basically, all those properties that displayed at Device Manager could be dump by this way. 


Wednesday, April 25, 2012

How to have a VS project that contain Mofcomp command


1. New a project that based on "Template" -> "Visual C++" -> " Windows Driver" -> "Applications", and select "Empty DLL for Drivers"



2. Select Project->Property Pages, you may see Mof Compiler existing there.


3. After insert .mof file, VS will auto select Mofcomp as the build option.


4. Make sure turn off entry point of DLL, otherwise VS will complain that DLL entry function not found.


Wednesday, March 14, 2012

Install Windows 8 consumer preview at virtualbox

Installed at w8 cp at VirtualBox in Ubuntu 11.10.
The default version of VirtualBox that came with 11.10 is version 4.1.2.
No Windows 8 option, so select others, system will up, and stop at recovery option.

Google found that 4.1.8+ version should already come with w8 option, update to 4.1.8, w8 up without problem.

Windows 8 consumer preview location :
http://windows.microsoft.com/en-US/windows-8/consumer-preview

VirtualBox location :
https://www.virtualbox.org/wiki/Downloads

Friday, March 09, 2012

Google Spreadsheet ,TEXT() 函數, format 的語法



在一個對網路很不友善的環境下....(略)...

沒想到最廣泛被大家使用的竟然是 Google Doc ... 想想也合理... 因為 Outlook 空間過小... 不適合丟大檔案... 公司的 server 空間使用規定很嚴... 一切都要靠 VPN ... 所以最後大家都把檔案都丟 google doc... 也正好利用了他天生方便共筆的特性... 同步大家的資訊也容易....

所以.. 除了漸漸淡忘的 Excel 語法後... 我又開始學習 Google spreadsheet 比較進階的用法了....

" Google Spreadsheet 裡面 TEXT() 函數裡面, format 的用法.... http://goo.gl/00S5p "