Get size of all code files in a directory

I got a question on how to get all files in a directory listing containing code.

This is what I used:

find . \( -name '*.bb*' -o -name '*.h*' -o -name '*.c*' -o -name '*akefile' -o -name '*.sh' -o -name '*.py*' \) -exec du -ch {} +
Posted in Linux commandline | Tagged , , , | Leave a comment

Getting UUID of a partition for use in /etc/fstab

To get UUID of a partition use the command

blkid /dev/sdXX

Example

me@ubuntudevmach:~/$ blkid /dev/sdb1

/dev/sdb1: UUID="405d2966-6826-4942-baa4-244f24aa31c3" TYPE="ext4" PTUUID="775559d3" PTTYPE="dos"

This is useful when editing /etc/fstab to direct a partition to a folder

Example of directing a partition to be used as the /home folder

UUID=405d2966-6826-4942-baa4-244f24aa31c3 /home ext4 errors=remount-ro 0 1
Posted in Linux commandline | Tagged , , | Leave a comment

Copying more files to an existing rootfs image

  1. Check rootfs image
    e2fsck -f myimage.ext2
  2. Resize it
    resize2fs myimage.ext2 400M
  3. mount it
    mkdir myimage
    mount myimage.ext2 myimage
  4. copy new content
    cp newcontent myimage
Posted in Linux commandline | Tagged , , | Leave a comment

Using your Linux host as a opkg package server

It is very useful to have your computer working as a opkg package server in the sence that you can install packages built and test instantly instead of rebuilding the entire image.

To enable this I did the following:

Install nginx

apt-get install nginx

Create a new nginx server config

sudo vi /etc/nginx/site-enabled/opkg-server
server {
  listen 80 default_server;

  root /home/myuser/repos/myyocto/mybuild/tmp/eglibc/deploy/ipk;

  autoindex on;
}

Remove the nginx default enabled site

sudo rm /etc/nginx/sites-enabled/default

Enable the new opkg site

sudo ln -s /etc/nginx/sites-enabled/opkg-server/etc/nginx/sites-available/opkg-server

Restart the server

sudo /etc/init.d/nginx restart

You should now be able to surf into your localhost using a web-browser

Next step is to enable this on your device

ssh target
vi /etc/opkg/opkg.conf
src/gz all http://192.168.1.4/all
src/gz armv5te http://192.168.1.4/armv5te
src/gz armv7a-vfp-neon http://192.168.1.4/armv7a-vfp-neon
src/gz cortexa8-vfp-neon http://192.168.1.4/cortexa8-vfp-neon
src/gz cortexa8-vfp-neon-mx5 http://192.168.1.4/cortexa8-vfp-neon-mx5
src/gz x86_64-nativesdk http://192.168.1.4/x86_64-nativesdk

Where 192.168.1.4 is the IP-address of your host machine

Next update the package list

opkg update
Downloading http://169.254.1.4/all/Packages.gz.
Inflating http://169.254.1.4/all/Packages.gz.
Updated list of available packages in /var/lib/opkg/all.
Downloading http://169.254.1.4/armv5te/Packages.gz.
Inflating http://169.254.1.4/armv5te/Packages.gz.
Updated list of available packages in /var/lib/opkg/armv5te.
Downloading http://169.254.1.4/armv7a-vfp-neon/Packages.gz.
Inflating http://169.254.1.4/armv7a-vfp-neon/Packages.gz.
Updated list of available packages in /var/lib/opkg/armv7a-vfp-neon.
Downloading http://169.254.1.4/cortexa8-vfp-neon/Packages.gz.
Inflating http://169.254.1.4/cortexa8-vfp-neon/Packages.gz.
Updated list of available packages in /var/lib/opkg/cortexa8-vfp-neon.
Downloading http://169.254.1.4/cortexa8-vfp-neon-mx5/Packages.gz.
Inflating http://169.254.1.4/cortexa8-vfp-neon-mx5/Packages.gz.
Updated list of available packages in /var/lib/opkg/cortexa8-vfp-neon-mx5.
Downloading http://169.254.1.4/x86_64-nativesdk/Packages.gz.
Inflating http://169.254.1.4/x86_64-nativesdk/Packages.gz.
Updated list of available packages in /var/lib/opkg/x86_64-nativesdk.

And then your’e ready to update any package from your computer

opkg install mypackage
Posted in Yocto | Tagged , , | Leave a comment

Adding ssh password to raspberry pi

  1. Create ssh-key
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  2. Add id_rsa.pub content to the raspberry pi .ssh/authorized_keys

    echo ~/.ssh/id_rsa.pub | ssh pi@192.168.1.5 "cat >> .ssh/authorized_keys
  3. Add new login part in your .ssh/config file
    vi .ssh/config
    Host pi
     Hostname 192.168.1.5
     User pi
     IdentityFile ~/.ssh/id_rsa

     

Posted in Yocto | Tagged , , | Leave a comment

Gerrit workflow using git-repo

This is the workflow I use when working with gerrit and git-repo

  1. Create a git-repo branch
    cd ~/myrepo
    repo start mybranch myproject
  2. Make changes and commit
    vim myclass.cpp
    git add myclass.cpp
    git commit -s
  3. Push to gerrit to master branch using your branch name as topic
    repo upload -D master -t
Posted in Yocto | Tagged , , | Leave a comment

cntlm proxy and docker

It can be troublesome to use Linux and docker from within a Windows based IT infrastructure. To achieve this I did the following:

Get the user name

user=`getent passwd 1000 | cut -d ':' -f1`

Get the docker interface ip address

docker0=`ip addr show docker0 | grep inet | head -n1 | awk '{print $2}' | cut -d '/' -f1`

Install cntlm

apt-get update
apt-get install -y cntlm

Edit the /etc/cntlm.conf

sudo vi /etc/cntlm.conf
Domain xxx.xxx.com # Change to your domain

Proxy xx.xx.xx.xx:xx # Change to your proxy server ip:port

# Add all local ip address-ranges no need to use proxy
NoProxy localhost,127.0.0.*,10.*,192.168.*,169.254.*,172.17.42.*

Listen 3128
Listen ##DOCKER##:3128

Allow 127.0.0.1/8
Allow ##DOCKER##/16

Replace ##DOCKER## with docker interface ip address

sudo sed -ri "s/##DOCKER##/$docker0/g" /etc/cntlm.conf

Add proxy environment variables to /etc/environment and /etc/bash.bashrc

http_proxy="http://localhost:3128"
https_proxy="http://localhost:3128"
ftp_proxy="http://localhost:3128"
HTTP_PROXY="http://localhost:3128"
HTTPS_PROXY="http://localhost:3128"
FTP_PROXY="http://localhost:3128"

Setting 99fixbadproxy

mkdir -p /etc/apt/apt.conf.d/
echo "Acquire::http::Pipeline-Depth 0;" > /etc/apt/apt.conf.d/99fixbadproxy
echo "Acquire::http::No-Cache true;" >> /etc/apt/apt.conf.d/99fixbadproxy
echo "Acquire::BrokenProxy true;" >> /etc/apt/apt.conf.d/99fixbadproxy

Getting and updating zscaler certificate

wget --no-proxy --no-check-certificate https://sites.google.com/a/stokes.k12.nc.us/z-scaler/zs-certs/ZscalerRootCertificate-2048-SHA256.crt -O /usr/local/share/ca-certificates/ZscalerRootCertificate-2048-SHA256.crt
update-ca-certificates

Restart cntlm

sudo service cntlm restart
Posted in Yocto | Tagged , , , , | Leave a comment

Replacing busybox-httpd with nginx in yocto

To replace busybox webserver with nginx follow these steps:

1. Remove CONFIG_HTTPD and CONFIG_FEATURE_HTTPD from the busybox defconfig

2. Remove any special considerations made in your busybox_XXX.bbappend regarding httpd webserver.

3. Add meta-webserver layer to your bblayers.conf

BBLAYERS ?= " \
 ...
 ##OEROOT#/../meta-webserver \
 ...
 "
Posted in Yocto | Tagged , , , | Leave a comment