Tag Archives: ELF

Latest instructions for bash 4.4 and arm64 device architecture:
Step 1: Get and prepare the environment and toolchain:

mkdir ~/aarch64-toolchain/
wget http://releases.linaro.org/components/toolchain/binaries/latest-6/aarch64-linux-gnu/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu.tar.xz
tar xf gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu.tar.xz
export PATH=$PATH:~/aarch64-toolchain/gcc-linaro-6.3.1-2017.02-x86_64_aarch64-linux-gnu/bin

Next get the bash source and build:

mkdir bashsrc
cd bashsrc
wget http://ftp.gnu.org/gnu/bash/bash-4.4.tar.gz

Get latest from http://ftp.gnu.org/gnu/bash/?C=M;O=D

tar xf bash-4.4.tar.gz
cd bash-4.4
mkdir /root/bashstatic
./configure --prefix=/root/bashstatic --host=aarch64-linux-gnu --enable-static-link --without-bash-malloc --enable-largefile --enable-alias --enable-history
export CFLAGS="-static"
make

We can also modify the line (add -static to the end) to read:
CFLAGS = -g -O2 -Wno-parentheses -Wno-format-security -static

Test the file to see whether it is ARM x64:

~/aarch64-toolchain/bash/bash-4.4 $file bash
bash: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=3e2a4fc358a13f74714907c7b454a9024675dbff, not stripped
[/bash]

[download id=”0″]

Older post:
Step 1: Downloading and installing the toolchain

This is the difficult step. Once this is done, usually compiling is a no-brainer.

The following steps use the latest Codesourcery compiler and worked for bash 4.3 on Debian squeeze host.

To get the latest Codesourcery toolchain, Visit the Codesourcery home at http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/ and under “ARM Processors”, click on “Download the GNU/Linux release”, enter your user details. The download link will be mailed to your email address in a couple of seconds.

Clicking on the link in the email will take you to a page with a list of releases and a link to the one you chose. For me, it was https://sourcery.mentor.com/GNUToolchain/release2795. Clicking on it will give you the following options: IA32 GNU/Linux Installer, IA32 Windows Installer and advanced options. Click on IA32 GNU/Linux Installer to download the bin file.

Now, you need to install certain dependencies for the toolchain, and the toolchain itself:

apt-get install ia32-libs ia32-libs-gtk
wget https://sourcery.mentor.com/GNUToolchain/kbattach150/getlibs-all.deb
sudo dpkg -i getlibs-all.deb
getlibs -p xulrunner-1.9.2
wget https://sourcery.mentor.com/GNUToolchain/package12815/public/arm-none-linux-gnueabi/arm-2014.05-29-arm-none-linux-gnueabi.bin
/bin/sh arm-2014.05-29-arm-none-linux-gnueabi.bin -console

Step 2: Setup the environment

Now you need to setup your environment to have certain environmental variables for cross compiling and pointing to the toolchain path. You dont want to use your system compiler to compile these files do you (those files cant be run on your phone/tablet)?

export CROSS_COMPILE="/root/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/arm-none-linux-gnueabi-gcc"
export PATH=/root/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin:$PATH

Step 3: Getting and preparing the source code
Now you will need to download the latest bash source code, extract it.

cd ~/
mkdir bashsrc
cd bashsrc
wget http://ftp.gnu.org/gnu/bash/bash-4.3.tar.gz
tar -xvvf bash-4.3.tar.gz

Step 4: Compiling
You will now compile and then ‘make’ the binaries.

mkdir /root/bashstatic
cd bash-4.3
./configure --prefix=/root/bashstatic --host=arm-none-linux-gnueabi --enable-static-link --without-bash-malloc --enable-largefile --enable-alias --enable-history

You will need to enable a “-static” flag to compile a static bash.
First see where the line CFLAGS comes in:
grep -in ‘CFLAGS’ Makefile
emacs Makefile

Edit Makefile so that CFLAGS reads like this:

CFLAGS = -g -O2 -static[/code]

Now you can make and install the binaries.
make install

Test with `file /root/bashstatic/bin/bash`[/bash]

Attached:
bash: [download id="0"]
busybox: [download id="0"]

Get the latest version. Alternate locations here.

I worked with 1.42.6. Download it and extract.

wget http://kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v1.42.6/e2fsprogs-1.42.6.tar.bz2
tar -jxvvf e2fsprogs-1.42.6.tar.bz2
cd e2fsprogs-1.42.6
mkdir ~/e2progs
./configure --prefix=/home/droidzone/e2progs --host=arm-linux-gnueabihf
kate Makefile

Add -static to CFLAGS.

The final CFLAGS look like this:

CFLAGS = -g -O2 -static

make and install:

make
make install

The final binaries are put in ~/e2progs/sbin/

The final file is said to be dynamically linked, but I doubt if that’s actually true, since under lib, there’s only one file: e2initrd_helper

file ~/e2progs/sbin/e2fsck 
/home/droidzone/e2progs/sbin/e2fsck: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.31, not stripped