Showing posts with label Linux Basics. Show all posts
Showing posts with label Linux Basics. Show all posts

Friday, 7 August 2020

apt-get install stuck issue

I was trying to install nutstore but too bad it is discontinued and I am stuck at this error.

Setting up nautilus-nutstore (3.1.0) ...
fetching Nutstore distribution package...
--2020-08-08 01:21:23-- http://jianguoyun.com/static/exe/installer/nutstore_linux_dist_x64.tar.gz
Resolving jianguoyun.com (jianguoyun.com)... 13.75.93.73
Connecting to jianguoyun.com (jianguoyun.com)|13.75.93.73|:80...

The problem is, what ever new things I want to install, apt-get will end up stuck here.

Solution:
$ sudo apt-get remove nautilus-nutstore

Thursday, 30 April 2020

Install Ubuntu Dual Boot on Dell with SATA Harddirve

I was installing ubuntu on a new Dell machine with SATA. I booted into the Ubuntu Live USB but at the partitioning part I could only see /dev/sda which is just my USB drive. Where is my hard drive??!!

Here is the fix or prevention...so that you won't just change the SATA setting and lose windows. Then it will be a bit hard to fix.

  1. In Windows, run Command Prompt as admin
  2. Invoke a Safe Mode boot with the command: bcdedit /set {current} safeboot minimal
  3. Restart the PC and enter your BIOS during bootup.
  4. Change from IDE to AHCI mode then Save & Exit.
  5. Windows 10 will launch in Safe Mode.
  6. Right click the Window icon and select to run the Command Prompt in Admin mode from among the various options.
  7. Cancel Safe Mode booting with the command: bcdedit /deletevalue {current} safeboot
  8. Restart your PC once more and this time it will boot up normally but with AHCI mode activated.

Monday, 14 January 2019

NO_PUBKEY Issue

Hit:21 http://ppa.launchpad.net/webupd8team/sublime-text-3/ubuntu xenial InRelease
Fetched 1,490 B in 1s (1,302 B/s)                 
Reading package lists... Done
W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: https://dl.winehq.org/wine-builds/ubuntu xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 76F1A20FF987672F
W: GPG error: http://download.opensuse.org/repositories/home:/emby/xUbuntu_16.04  Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0A506F712A7D8A28
W: The repository 'http://download.opensuse.org/repositories/home:/emby/xUbuntu_16.04  Release' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: Failed to fetch https://dl.winehq.org/wine-builds/ubuntu/dists/xenial/InRelease  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 76F1A20FF987672F
W: Some index files failed to download. They have been ignored, or old ones used instead.

wget -nc https://dl.winehq.org/wine-builds/winehq.key && sudo apt-key add winehq.key && sudo apt update



boris@boris-home:~$ wget -nc https://dl.winehq.org/wine-builds/winehq.key && sudo apt-key add winehq.key && sudo apt update
--2019-01-15 00:43:38--  https://dl.winehq.org/wine-builds/winehq.key
Resolving dl.winehq.org (dl.winehq.org)... 151.101.126.217
Connecting to dl.winehq.org (dl.winehq.org)|151.101.126.217|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3220 (3.1K) [application/pgp-keys]
Saving to: ‘winehq.key’

winehq.key          100%[===================>]   3.14K  --.-KB/s    in 0s      

2019-01-15 00:43:38 (77.1 MB/s) - ‘winehq.key’ saved [3220/3220]

OK
Ign:1 http://linux.dropbox.com/ubuntu wily InRelease
Ign:2 http://dl.google.com/linux/chrome/deb stable InRelease                   
Hit:3 http://linux.dropbox.com/ubuntu wily Release                             
Hit:6 http://archive.canonical.com/ubuntu xenial InRelease                     
Hit:7 http://repository.spotify.com stable InRelease                           
Ign:8 http://download.opensuse.org/repositories/home:/emby/xUbuntu_16.04  InRelease
Hit:9 http://dl.google.com/linux/chrome/deb stable Release                     
Get:10 https://dl.winehq.org/wine-builds/ubuntu xenial/main amd64 Packages [145 kB]
Hit:11 http://ca.archive.ubuntu.com/ubuntu xenial InRelease                    
Hit:12 http://ppa.launchpad.net/fpoussin/ppa/ubuntu xenial InRelease           
Hit:13 http://download.opensuse.org/repositories/home:/emby/xUbuntu_16.04  Release
Get:14 https://dl.winehq.org/wine-builds/ubuntu xenial/main i386 Packages [151 kB]
Get:15 http://ca.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]   
Get:16 http://download.opensuse.org/repositories/home:/emby/xUbuntu_16.04  Release.gpg [481 B]
Hit:18 http://ppa.launchpad.net/gezakovacs/ppa/ubuntu xenial InRelease         
Ign:16 http://download.opensuse.org/repositories/home:/emby/xUbuntu_16.04  Release.gpg
Hit:19 http://ppa.launchpad.net/mosquitto-dev/mosquitto-ppa/ubuntu xenial InRelease
Get:20 http://ca.archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB] 
Hit:21 http://ppa.launchpad.net/webupd8team/sublime-text-3/ubuntu xenial InRelease
Hit:22 http://archive.ubuntukylin.com:10006/ubuntukylin xenial InRelease
Reading package lists... Done 
W: GPG error: http://download.opensuse.org/repositories/home:/emby/xUbuntu_16.04  Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 0A506F712A7D8A28
E: The repository 'http://download.opensuse.org/repositories/home:/emby/xUbuntu_16.04  Release' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

boris@boris-home:~$ 


You can see the key issue from WinHQ is gone now.

###########################################################

$ sudo -i 
 # apt-get clean 
 # cd /var/lib/apt 
 # mv lists lists.old 
 # mkdir -p lists/partial 
 # apt-get clean 
 # apt-get update

sudo sed -i '/opensuse/ s/^/#/' /etc/apt/sources.list.d/*.list


Now the key issue from opensuse should also be gone.


ref:
https://askubuntu.com/questions/1103320/the-following-signatures-couldnt-be-verified-because-the-public-key-is-not-avai
https://ubuntuforums.org/showthread.php?t=1869890&page=3
https://askubuntu.com/questions/522114/cant-get-rid-of-gpg-error-http-download-opensuse-org


Thursday, 14 June 2018

Nutstore problem: SSL failed to connect

备份并移除老的cacerts
sudo mv /etc/ssl/certs/java/cacerts{,.backup}


生成新的cacerts
sudo keytool -importkeystore -destkeystore /etc/ssl/certs/java/cacerts -deststoretype jks -deststorepass changeit -srckeystore /etc/ssl/certs/java/cacerts.backup -srcstoretype pkcs12 -srcstorepass changeit


询问官方后官方提供的临时解决方案

ref:
http://tieba.baidu.com/p/5680448441

Thursday, 22 March 2018

Install openCV on Ubuntu 16.04

I was installing openCV following the instruction from the first google search:
          https://www.learnopencv.com/install-opencv3-on-ubuntu/

But I met the following problems so far.

sudo apt-get install git gfortran

error:
The following packages have unmet dependencies:
 gfortran : Depends: gfortran-5 (>= 5.3.1-3~) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

solution:
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gfortran-5
Now do it again and it works.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

sudo apt-get install libjpeg8-dev libjasper-dev libpng12-dev

error:
The following packages have unmet dependencies:
 libjasper-dev : Depends: libjasper1 (= 1.900.1-debian1-2.4ubuntu1) but 1.900.1-debian1-2.4ubuntu1.1 is to be installed
E: Unable to correct problems, you have held broken packages.

solution:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev

Now do it again and it works.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

~$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable) 
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

Solution:
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
~$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
E: dpkg was interrupted, you must manually run 'sudo dpkg --configure -a' to correct the problem.

~$ sudo dpkg --configure -a

Do it again and worked:
~$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

~$ sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

error:
The following packages have unmet dependencies:
 libgstreamer-plugins-base0.10-dev : Depends: libglib2.0-dev but it is not going to be installed
 libgstreamer0.10-dev : Depends: libglib2.0-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

Solution:
Install the dependency libglib2.0-dev:
sudo apt-get install libglib2.0-dev libglib2.0-0=2.48.0-1ubuntu4

Do it again and worked:
~$ sudo apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

sudo apt-get install qt5-default libgtk2.0-dev libtbb-dev
I jumped over qt5-default, too many dependencies...so just:
~$ sudo apt-get install libgtk2.0-dev libtbb-dev

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

sudo apt-get install python-dev python-pip python3-dev python3-pip

errors:
The following packages have unmet dependencies:
 python3-pip : Depends: python-pip-whl (= 8.1.1-2) but 8.1.1-2ubuntu0.4 is to be installed
               Recommends: python3-setuptools but it is not going to be installed
               Recommends: python3-wheel but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

solution:
Don't know yet...I jumped over python3-pip for now.

/////////////////////////////////////////////////////////////////////////////////////////////////////

OK finally cmake...but I got errors. After trying a lot to install some dependencies like qt5, I still couldn't get rid of the errors. I found the official website has a tutorial about installation:
            
                https://docs.opencv.org/trunk/d2/de6/tutorial_py_setup_in_ubuntu.html

Note that you have to delete ./build directory and create a new folder and do:
$ cmake ../

...and it worked!
..............
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
 ...................


ref:
https://www.learnopencv.com/install-opencv3-on-ubuntu/
https://askubuntu.com/questions/720948/problems-installing-gfortran
https://github.com/opencv/opencv/issues/8622
https://askubuntu.com/questions/15433/unable-to-lock-the-administration-directory-var-lib-dpkg-is-another-process
https://askubuntu.com/questions/884413/unable-to-install-libgtk2-0-dev-on-ubuntu-16-04/886022

https://docs.opencv.org/trunk/d2/de6/tutorial_py_setup_in_ubuntu.html
https://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html

Tuesday, 20 March 2018

Problem with Spotify Keys


Problem:

W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://repository.spotify.com stable InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EFDC8610341D9410
W: Failed to fetch http://repository.spotify.com/dists/stable/InRelease  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY EFDC8610341D9410
W: Some index files failed to download. They have been ignored, or old ones used instead.

####################################################################3


This happen when somehow we'd lost the keys.
To solve i have executed the first step listed here https://www.spotify.com/de/download/linux/

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0DF731E45CE24F27EEEB1450EFDC8610341D9410


ref:
https://superuser.com/questions/932781/failed-to-fetch-spotify-repository-while-updating-ubuntu

Sunday, 4 March 2018

Tinkering OpenWRT (4) : make config

When I tried to configure my make config menu for openwrt, I got:

Your display is too small to run Menuconfig!
It must be at least 19 lines by 80 columns.
/home/boris/workspace/openWRT/WRTKernel/source/include/toplevel.mk:136: recipe for target 'menuconfig' failed
make: *** [menuconfig] Error 1

Don't worry, this simply means you have to maximize your terminal window.

Tuesday, 19 December 2017

I think the following problems are the same:

Problem 1:
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?


Problem  2:
sudo apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.
5 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up linux-image-extra-4.4.0-104-generic (4.4.0-104.127) ...
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-104-generic /boot/vmlinuz-4.4.0-104-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-104-generic /boot/vmlinuz-4.4.0-104-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-104-generic

gzip: stdout: No space left on device
E: mkinitramfs failure cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-4.4.0-104-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-extra-4.4.0-104-generic (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of linux-image-generic:
 linux-image-generic depends on linux-image-extra-4.4.0-104-generic; however:
  Package linux-image-extra-4.4.0-104-generic is not configured yet.

dpkg: error processing package linux-image-generic (--configure):
 dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of linux-generic:
 linux-generic depends on linux-image-generic (= 4.4.0.104.109); however:
  Package linux-image-generic is not configured yet.

dpkg: error processing package linux-generic (--configure):
 dependency problems - leaving unconfigured
Setting up linux-image-4.4.0-98-generic (4.4.0-98.121) ...
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          No apport report written because the error message indicates its a followup error from a previous failure.
                                                                             Running depmod.
update-initramfs: deferring update (hook will be called later)
The link /initrd.img is a dangling linkto /boot/initrd.img-4.4.0-98-generic
vmlinuz(/boot/vmlinuz-4.4.0-98-generic
) points to /boot/vmlinuz-4.4.0-98-generic
 (/boot/vmlinuz-4.4.0-98-generic) -- doing nothing at /var/lib/dpkg/info/linux-image-4.4.0-98-generic.postinst line 491.
Examining /etc/kernel/postinst.d.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 4.4.0-98-generic /boot/vmlinuz-4.4.0-98-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 4.4.0-98-generic /boot/vmlinuz-4.4.0-98-generic
update-initramfs: Generating /boot/initrd.img-4.4.0-98-generic

gzip: stdout: No space left on device
E: mkinitramfs failure cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-4.4.0-98-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
Failed to process /etc/kernel/postinst.d at /var/lib/dpkg/info/linux-image-4.4.0-98-generic.postinst line 1052.
dpkg: error processing package linux-image-4.4.0-98-generic (--configure):
 subprocess installed post-installation script returned error exit status 2
No apport report written because MaxReports is reached already
                                                              dpkg: dependency problems prevent configuration of linux-image-extra-4.4.0-98-generic:
 linux-image-extra-4.4.0-98-generic depends on linux-image-4.4.0-98-generic; however:
  Package linux-image-4.4.0-98-generic is not configured yet.

dpkg: error processing package linux-image-extra-4.4.0-98-generic (--configure):
 dependency problems - leaving unconfigured
No apport report written because MaxReports is reached already
                                                              Errors were encountered while processing:
 linux-image-extra-4.4.0-104-generic
 linux-image-generic
 linux-generic
 linux-image-4.4.0-98-generic
 linux-image-extra-4.4.0-98-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)

Problem  3:
The volume "boot" has only  bytes disk space remaining

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Solution:

Step 1:
List all the current existing kernels.

ls /boot/ | grep vmlinuz
vmlinuz-4.4.0-104-generic
vmlinuz-4.4.0-97-generic
vmlinuz-4.4.0-98-generic

Step 2:
Find the current kernel in use.

uname -r
4.4.0-97-generic

Step 3:
Remove one of them not in use:

sudo apt-get purge linux-image-4.4.0-104-generic
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-4.4.0-104 linux-headers-4.4.0-104-generic linux-headers-generic thermald
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 39 not upgraded.



ref:
https://askubuntu.com/questions/218783/the-volume-boot-has-only-0-bytes-disk-space-remaining


Monday, 30 October 2017

Manage Startup Applications in Ubuntu

Ubuntu has an GUI called Startup Applications.

ref:
https://linux.cn/article-5943-1.html

Tuesday, 19 September 2017

Particle Installation Troubleshooting

If you see such things like:

node-pre-gyp ERR! Pre-built binaries not found for serialport@4.0.7 and node@4.2.1 (node-v46 ABI) (falling back to source compile with node-gyp)
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/4.2.1"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/particle-cli/node_modules/serialport/.node-gyp"
make: Entering directory '/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build'
make: *** No rule to make target '../.node-gyp/4.2.1/include/node/common.gypi', needed by 'Makefile'. Stop.
make: Leaving directory '/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:270:23)
gyp ERR! stack at emitTwo (events.js:87:13)
gyp ERR! stack at ChildProcess.emit (events.js:172:7)
gyp ERR! stack at Process.ChildProcess.handle.onexit (internal/childprocess.js:200:12)
gyp ERR! System Linux 4.9.24+
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build/Release/serialport.node" "--module_name=serialport" "--module_path=/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build/Release"
gyp ERR! cwd /usr/local/lib/node_modules/particle-cli/node_modules/serialport
gyp ERR! node -v v4.2.1
gyp ERR! node-gyp -v v3.0.3
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build/Release/serialport.node --module_name=serialport --module_path=/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build/Release' (1)
node-pre-gyp ERR! stack at ChildProcess. (/usr/local/lib/node_modules/particle-cli/node_modules/serialport/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack at emitTwo (events.js:87:13)
node-pre-gyp ERR! stack at ChildProcess.emit (events.js:172:7)
node-pre-gyp ERR! stack at maybeClose (internal/child_process.js:818:16)
node-pre-gyp ERR! stack at Process.ChildProcess.handle.onexit (internal/childprocess.js:211:5)
node-pre-gyp ERR! System Linux 4.9.24+
node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/particle-cli/node_modules/serialport/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /usr/local/lib/node_modules/particle-cli/node_modules/serialport
node-pre-gyp ERR! node -v v4.2.1
node-pre-gyp ERR! node-pre-gyp -v v0.6.32
node-pre-gyp ERR! not ok
Failed to execute '/usr/local/bin/node /usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build/Release/serialport.node --module_name=serialport --module_path=/usr/local/lib/node_modules/particle-cli/node_modules/serialport/build/Release' (1)
npm ERR! Linux 4.9.24+
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "particle-cli"
npm ERR! node v4.2.1
npm ERR! npm v2.14.7
npm ERR! code ELIFECYCLE
npm ERR! serialport@4.0.7 install: node-pre-gyp install --fallback-to-build
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the serialport@4.0.7 install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! This is most likely a problem with the serialport package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-pre-gyp install --fallback-to-build
npm ERR! You can get their info via:
npm ERR! npm owner ls serialport
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/pi/npm-debug.log


This is a known but relatively undocumented bug with the particle-cli installation process. The following should work:

           $ sudo npm install -g --unsafe-perm node-pre-gyp npm serialport particle-cli

ref:
https://community.particle.io/t/connecting-particle-photon-to-local-server-on-raspberry-pi-zero-w/32227
https://community.particle.io/t/new-cli-on-os-x-10-11-el-capitan-solved/28802/8



Sunday, 17 September 2017

"The volume "boot" has only 0 bytes disk space remaining" error

Very simple

sudo apt-get autoremove

This will delete those unuseful kernels in /boot.

ref:
https://ubuntuforums.org/showthread.php?t=2239126
https://askubuntu.com/questions/345588/what-is-the-safest-way-to-clean-up-boot-partition

Thursday, 7 September 2017

Setting up GCC ARM Coding Environment for STMicrocontroller


1. Installing compiler and stlink

To compile C and/or C++ source code of your firmware you will need gcc-arm-none-eabi compiler and stlink.

Installing gcc-arm-none-eabi

What is extremely useful, there are complete and easy to install packages for all major platforms (https://launchpad.net/~team-gcc-arm-embedded/+archive/ubuntu/ppa)
sudo add-apt-repository ppa:team-gcc-arm-embedded/ppa
sudo apt-get update
sudo apt-get install gcc-arm-none-eabi

Installing stlink

At first, we need install dependencies then build it from sources (https://github.com/texane/stlink/blob/master/doc/compiling.md#build-from-sources).
sudo apt-get install git build-essential libusb-1.0.0-dev cmake
cd $HOME
git clone git@github.com:texane/stlink.git
cd stlink
make release
cd build/Release && make install DESTDIR=_install
echo "export PATH=\$PATH:$HOME/stlink/build/Release/_install/usr/local/bin" >> $HOME/.bashrc

2. Compiling and burning the code

Now that you have the toolchain installed, a next step is to compile the source code into a .ELF, then generate .BIN file and finally burn this this binary file to STM32 chip using ST-Link v2 programmer.

Example code

Here is an example content of main.c file. The code does nothing except getting stuck in an endless loop but it’s always something!
int
main(void)
{

        while (1);
}

Compiling

The command below will compile your code. It’s GCC so I assume it looks familiar to you and no additional explanations are needed. If you want perform compilation for some other MCU then you need specify at least appropriate -mcpu, .LD and .S files (not provided in this tutorial)
$ arm-none-eabi-gcc -std=gnu99 -g -O2 -Wall -mlittle-endian -mthumb -mthumb-interwork -mcpu=cortex-m0 -fsingle-precision-constant -Wdouble-promotion main.c -o main.elf
After performing successful compilation, you can check program and data memory size with this command.
$ arm-none-eabi-size -tA main.elf 
main.elf  :
section              size        addr
.isr_vector           192   134217728
.text                6404   134217920
.rodata                60   134224324
.ARM                    8   134224384
.init_array             8   134224392
.fini_array             4   134224400
.data                1092   536870912
.jcr                    4   536872004
.bss                   32   536872008
._user_heap_stack    1536   536872040
.ARM.attributes        40           0
.comment               31           0
.debug_line          7416           0
.debug_info         22917           0
.debug_abbrev        6837           0
.debug_aranges        744           0
.debug_loc           6584           0
.debug_ranges         472           0
.debug_str           5717           0
.debug_frame         2004           0
Total               62102

Generating .BIN

Most programmers will not accept a GNU executable as an input file, so we need to do a little more processing. So, the next step is about converting the information form .ELF into .BIN file. The GNU utility that does this is called arm-none-eabi-objcopy.
$ arm-none-eabi-objcopy -O binary main.elf main.bin

Burning

The utility called st-flash can program processors using the content of the .BIN files specified on the command line. With the command below, the file main.bin will be burned into the flash memory.
$ st-flash write main.bin 0x8000000
Voila! Chip is programmed.

3. Make and Makefiles

Now, we can automate this process by creating a Makefile and putting our commands there. The structure of a Makefile is very simple, and more information about it can be found here. Utility make reads automatically a Makefile file in the folder where you launch it. Take a look at simple Makefile presented bellow.
TARGET=main

CC=arm-none-eabi-gcc
LD=arm-none-eabi-gcc
AR=arm-none-eabi-ar
AS=arm-none-eabi-as
CP=arm-none-eabi-objcopy
OD=arm-none-eabi-objdump
SE=arm-none-eabi-size
SF=st-flash

CFLAGS  = -std=gnu99 -g -O2 -Wall
CFLAGS += -mlittle-endian -mthumb -mthumb-interwork -mcpu=cortex-m0
CFLAGS += -fsingle-precision-constant -Wdouble-promotion

SRCS =  main.c

.PHONY: $(TARGET)

$(TARGET): $(TARGET).elf

$(TARGET).elf: $(SRCS)
        $(CC) $(INCLUDE) $(CFLAGS) $^ -o $@
        $(CP) -O binary $(TARGET).elf $(TARGET).bin

clean:
        rm -f *.o $(TARGET).elf $(TARGET).bin

flash:
        $(SF) write $(TARGET).bin 0x8000000
If you launch a simple make in the terminal, only label “all” will be executed. When you launch make flash label “flash” will be executed, and so on.

4. Summary

Essentially, assuming that our program is in main.c, only those three things are needed to compile and burn the code to STM32 chip.
$ arm-none-eabi-gcc -std=gnu99 -g -O2 -Wall -mlittle-endian -mthumb -mthumb-interwork -mcpu=cortex-m0 -fsingle-precision-constant -Wdouble-promotion main.c -o main.elf
$ arm-none-eabi-objcopy -O binary main.elf main.bin
$ st-flash write main.bin 0x8000000


It’s important to highlight that we can easily automate whole process with Makefiles. Sooner or later you will need it!



ref:
http://blog.podkalicki.com/how-to-compile-and-burn-the-code-to-stm32-chip-on-linux-ubuntu/
https://startingelectronics.org/tutorials/STM32-microcontrollers/programming-STM32-flash-in-Linux/
http://fishpepper.de/2016/09/16/installing-using-st-link-v2-to-flash-stm32-on-linux/