Friday, May 12, 2017

Windows batch file tips

Sometimes its difficult to debug the batch files to trace the errors.
One simple way is to just add:
@echo on
This will print all the statements executed in the batch file and you can know the error line.

~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S

Following command will disable displaying your commands / statements from the batch files.
So the execution looks clean.
@echo off
 ~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S
format-date-and-time-in-a-windows-batch-script
Provides a way to format the time stamp in nice way in batch command.
set "ts=%dt:~0,4%%dt:~4,2%%dt:~6,2%_%dt:~8,2%%dt:~10,2%%dt:~12,2%"
You may use it in script to log data.
 ~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S~S

Tuesday, June 21, 2016

compile latest gstreamer libraries

I will focus on compiling gstreamer libraries after cloning from https://cgit.freedesktop.org/gstreamer/
This is for the developers who can maintain multiple versions of the library, can play around with their API.

Any feedback welcome!
 
Important and required repositories are:

Following and some more can be compiled based on requirements:

gst-plugins-gl (Gstreamer OpenGL Module library is merged in gst-plugins-bad since 1.4. Even if you try to build it, you will see following error. So don't build it if you are working with gstreamer release > 1.4.
================================
 The GStreamer OpenGL module library and plugin have been merged into
 gst-plugins-bad version 1.4 and later.

 This git module is therefore obsolete now and should no longer be used.
================================
Clone them in your favourite directory.
Example:
git clone git://anongit.freedesktop.org/gstreamer/gstreamer
I will install libraries in a separate directory
"gst-install". So that it doesn't mess up with system wide gstreamer installation.

So you will have following directories:
gst-install/                                --> my install dir
gstreamer/
gst-plugins-bad/
gst-plugins-base/

gst-plugins-good/
gst-plugins-ugly/

Of course I had some pre-installed libraries, so I didn't face much of a problem while compilation. It can be tried on a raw ubuntu machine to check dependencies.
Otherwise, gstreamer is dependent on following libraries:
glib 
autoconf
automake
autopoint
libtoolize 
pkg-config
 
Generic commands to compile gstreamer libraries are:
./autogen.sh 
./configure --prefix=~/gst-install 
make
make install
Whenever you execute autogen.sh for given gstreamer library, it will clone 'common' repo in the respective repository.

Another important step to let the current compilation know about the package configurations.

export PKG_CONFIG_PATH=~/gst-install/lib/pkgconfig

If we do not do this, the compiler will look for package configurations in system path which will be /usr/lib/pkgconfig. This may lead to compilation error due to version mismatch between already installed packages and the package to be compiled.

Go to 'gstreamer' directory. Execute the generic commands listed above to compile the library.
This will install the library in 'gst-install' directory.
You will get following binaries:
gst-inspect-1.0
gst-launch-1.0
gst-stats-1.0
gst-typefind-1.0 
'gst-plugins-base' gives us:
gst-device-monitor-1.0
gst-discoverer-1.0

gst-play-1.0
Other libraries for plugins will be populated in 'gst-install/lib/' and 'gst-install/lib/gstreamer-1.0/'.
The binaries and libraries may vary depending on the configurations. I have used the default configuration.

gst-ffmpeg clones libav as well. It is a very heavy compilation as it encompasses all ffmpeg plugins.

There are two repositories related to OpenMAX IL wrapper plugin viz gst-openmax and gst-omx. gst-openmax initiated and written by Felipe Contreras is now deprecated. The latest OpenMAX wrapper plugin repo is at gst-omx.

References:
  • https://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/gst-building.html
Note:

Wednesday, May 11, 2016

windows 10 / ubuntu status: (HP Pavilion) Battery plugged in and not charging

Few days back, I experienced this strange behaviour for my laptop (HP Pavilion 15 ab032TX).

While the AC adaptor was connected to power source, the battery status showed "Battery plugged in and not charging". Battery charge was always shown to be 23%.

I thought this to be a Windows 10 problem. Then I switched to my Ubuntu OS. Yes, I have dual boot :). The problem persisted.

I searched on internet but there were no good resources. So I played around with the battery. I removed it. Visibly there was no problem about connector. I just cleaned it with a cloth, and mounted back.

It started working. May be the battery was too tired of sitting in one place. :D

This seems to be recurring problem :( I encountered it again after a week. 

Friday, March 11, 2016

Applying multiple patches using git am

Multiple patches with git am

We can apply multiple patches using git am command.
Examples:
git am patch1 patch2
git am *.patch

I have faced an error while using *.patch.
*.patch files were in current directory.
These patch files have been generated using duplicate repo maintained at a different location.

$ cd repo1
$ git commit -am
multiple commits
$ git format-patch master
$ cd repo1_dup
$ cp repo1/*.patch ./
$ git am *.patch
error: cannot read mbox some_diff.patch
error: cannot split patches from some_diff.patch
fatal: Failed to split patches.

$

Currently working on resolving this issue.

Forcefully adding a signed-off by in git am

Another interesting thing I am exploring is forcefully adding a signed-off by while applying a patch using git am.

Ref:
  • https://git-scm.com/docs/git-am

Thursday, March 3, 2016

Amending git commit

Method to amend commits.

Change files.
Commit changes
git commit -a
Enter commit message, save and exit.

Your commit will appear in the log.

If you want to change your latest or earlier commit (not yet pushed upstream), execute:

git-checkout commit_id_to_update
Edit any files you wish in working branch.

git-add files/which/are/changed
This will stage the updated files for commit.

git-commit --amend -v

Here you can edit the commit message, save and exit.
Now you have to rebase the existing commits from working branch.

git rebase --onto HEAD commit_id_to_update current_working_branch_name

Bingo! You are done!


Example:
I am working on Linux. So I will take kernel repo for example.


Step 1
Current status of repo.
$ git log --pretty=short
commit 7686e3c16c4a3669472298ecfc4636485658642b
Merge: 2f2e9f2dd1f4 75c1657e1d50
Author: Linus Torvalds <torvalds@linux-foundation.org>

    Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma

commit 2f2e9f2dd1f454f3c4f751b6f83359bc48f21096
Merge: 4617c2203fbc 5327c7dbd1a7
Author: Linus Torvalds <torvalds@linux-foundation.org>

    Merge git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending

Step 2
I made some changes in the repo.

$ vim Documentation/driver-model/device.txt
$ git diff
diff --git a/Documentation/driver-model/device.txt b/Documentation/driver-model/device.txt
index 1e70220d20f4..a429eaa60b8d 100644
--- a/Documentation/driver-model/device.txt
+++ b/Documentation/driver-model/device.txt
@@ -29,7 +29,7 @@ get_device() will return a pointer to the struct device passed to it
 if the reference is not already 0 (if it's in the process of being
 removed already).

-A driver can access the lock in the device structure using:
+A driver can access the lock in the device structure using:

 void lock_device(struct device * dev);
 void unlock_device(struct device * dev);
$ git branch -v
* master     7686e3c16c4a Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma

$


Step 3
Commit changes

$ git commit -a
[master 6a65e6e029f4] Documentation: device.txt: removed white space
 1 file changed, 1 insertion(+), 1 deletion(-)
$
$ git log --pretty=short
commit 6a65e6e029f44fa2dce0729d2502ba4b6067cdc4
Author: ABC XYZ <ab@xyz.com>

    Documentation: device.txt: removed white space

commit 7686e3c16c4a3669472298ecfc4636485658642b
Merge: 2f2e9f2dd1f4 75c1657e1d50
Author: Linus Torvalds <torvalds@linux-foundation.org>

    Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma

commit 2f2e9f2dd1f454f3c4f751b6f83359bc48f21096
Merge: 4617c2203fbc 5327c7dbd1a7
Author: Linus Torvalds <torvalds@linux-foundation.org>

    Merge git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending


Step 4
Checkout a particular commit (to be updated)

$ git checkout 6a65e6e029f44fa2dce0729d2502ba4b6067cdc4
Note: checking out '6a65e6e029f44fa2dce0729d2502ba4b6067cdc4'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 6a65e6e029f4... Documentation: device.txt: removed white space
$


Step 5
Make changes

$ vim Documentation/driver-model/device.txt
$ git branch -v
* (HEAD detached at 6a65e6e029f4) 6a65e6e029f4 Documentation: device.txt: removed white space
  master     6a65e6e029f4 [ahead 1] Documentation: device.txt: removed white space
$
$ git status
HEAD detached at 6a65e6e029f4
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   Documentation/driver-model/device.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    a.out

no changes added to commit (use "git add" and/or "git commit -a")
$


Step 6
Add changed files to staging for commit.


$ git add Documentation/driver-model/device.txt
$ git status
HEAD detached at 6a65e6e029f4
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   Documentation/driver-model/device.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    a.out

$



Step 7
Amend the commit. You can update commit message here.


$ git commit --amend -v
[detached HEAD 20eb25f6ee25] Documentation: device.txt: Removed white space. Corrected typo (extra 'be').
 Date: Thu Mar 3 15:19:16 2016 +0530
 1 file changed, 2 insertions(+), 2 deletions(-)
$

$ git log --pretty=short
commit 20eb25f6ee250a13af18d93e34269eaa9bae6ff7
Author: ABC XYZ <ab@xyz.com>

    Documentation: device.txt: Removed white space. Corrected typo (extra 'be').

commit 7686e3c16c4a3669472298ecfc4636485658642b
Merge: 2f2e9f2dd1f4 75c1657e1d50
Author: Linus Torvalds <torvalds@linux-foundation.org>

    Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma

commit 2f2e9f2dd1f454f3c4f751b6f83359bc48f21096
Merge: 4617c2203fbc 5327c7dbd1a7
Author: Linus Torvalds <torvalds@linux-foundation.org>

    Merge git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
 

$ git branch -v
* (HEAD detached from 6a65e6e029f4) 20eb25f6ee25 Documentation: device.txt: Removed white space. Corrected typo (extra 'be').
  master     6a65e6e029f4 [ahead 1] Documentation: device.txt: removed white space


Step 8
Rebase your updated commit on working branch.


$ git rebase --onto HEAD 6a65e6e029f44fa2dce0729d2502ba4b6067cdc4 master
First, rewinding head to replay your work on top of it...
$

$ git log --pretty=short
commit 20eb25f6ee250a13af18d93e34269eaa9bae6ff7
Author: ABC XYZ <ab@xyz.com>

    Documentation: device.txt: Removed white space. Corrected typo (extra 'be').

commit 7686e3c16c4a3669472298ecfc4636485658642b
Merge: 2f2e9f2dd1f4 75c1657e1d50
Author: Linus Torvalds <torvalds@linux-foundation.org>

    Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma

commit 2f2e9f2dd1f454f3c4f751b6f83359bc48f21096
Merge: 4617c2203fbc 5327c7dbd1a7
Author: Linus Torvalds <torvalds@linux-foundation.org>

    Merge git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
$

$ git branch -v
* master     20eb25f6ee25 [ahead 1] Documentation: device.txt: Removed white space. Corrected typo (extra 'be').
$

Tuesday, October 27, 2015

xchat or hexchat

When I started using IRC I settled for Xchat.
Later I realized that the client used to disconnect with following error:
* Connection failed. Error: (336031996) error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

It was quite frustrating...

Later I found HexChat (I should have found it earlier). My bad :)
With Hexchat I didn't face much issue about disconnection. What I mean is HexChat reconnects smoothly after disconnection, which is not the case with XChat.

Interface is almost similar.
(experts may correct me)

Saturday, October 10, 2015

kernel compilation error "kernel is not clean, please run 'make mrproper' "

I got this error while build the kernel.
Actually I am creating the binaries in a separate directory (TEGRA_KERNEL_OUT).
 sachin@sachin-ubuntu$ make O=$TEGRA_KERNEL_OUT zImage
  GEN     /home/sachin/projects/tegra/kern_out/Makefile
scripts/kconfig/conf --silentoldconfig Kconfig
  Using /home/sachin/projects/tegra as source for kernel
  /home/sachin/projects/tegra is not clean, please run 'make mrproper'
  in the '/home/sachin/projects/tegra' directory.
make[1]: * [prepare3] Error 1**
make: * [sub-make] Error 2**


Even after I have executed following it didn't go away. As there will be scripts/files created in kernel source dir as well as TEGRA_KERNEL_OUT.
make O=$TEGRA_KERNEL_OUT mrproper


So I have to do 2 mrproper
make mrproper
make O=$TEGRA_KERNEL_OUT mrproper

And then it worked fine.