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
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
Edit Makefile so that CFLAGS reads like this:
CFLAGS = -g -O2 -static[/code]
Now you can make and install the binaries.
Test with `file /root/bashstatic/bin/bash`[/bash]
bash: [download id="0"]
busybox: [download id="0"]
Joel G Mathew, known in tech circles by the pseudonym Droidzone, is an opensource and programming enthusiast.
His favorite pastime is grappling with GNU compilers, discovering newer Linux secrets, writing scripts, hacking roms, and programs (nothing illegal), reading, blogging. and testing out the latest gadgets.
When away from the tech world, Dr Joel G. Mathew is a practising ENT Surgeon, busy with surgeries and clinical practise.