Fixing ol' wget

sidekick II cellphone

My Mission

I am re-immersing myself into the Sidekick II cell phone, my favorite phone ever. My goal is to run Linux on it. I've made excellent headway with the bsp (board support package), but modern u-boot and linux removed the ARM7TDMI cpu code and Samsung s3c44b0 (s3c44b0x) SoC (system on chip) support.

New or Old

I could either reimplement everything all myself, or I could travel back in time to build off of the old software (with its added support). For my first move, I decided to go back in time. These are the two outdated software packages I'm using.

With these packages, I had another set of options.

  • I could run the old software packages from a modern distro (with much newer compiler and libc), and patch my way through the compilation failures.
  • I could setup an OS from around the same time as the old software packages.

First, I tried from the newer system. But after 7 patches I began to think it was too risky. The more patches I made, the more I felt that linux might compile but not run correctly. So I figured I'd try an old OS. Let me skip the story for a second here to tell you it got me down to just 1 patch :)

I opted for Ubuntu 12.10, which was released around 2012 (12 years ago). This was around the same time as the buildroot and u-boot I was using.

The first problem I ran into was that the apt-get update wasn't successful. After some googling I found a repository in China that was still active. Here's how I can edit the /etc/apt/sources.list/ quickly.

sed 's#\(http://us.archive.ubuntu.com/ubuntu/\|'\
'http://security.ubuntu.com/ubuntu\)#'\
'http://mirrors.ustc.edu.cn/ubuntu-old-releases/ubuntu/#g' /etc/apt/sources.list

thank goodness. Without these repositories you're done for.

Packages for Buildroot

This should be all of the packages necessary to use buildroot on Ubuntu 12.10. If you have any stragglers it's easy enough to install them later as you get alerted.

sudo apt-get update
sudo apt-get install bc binutils bison dwarves flex gcc git gnupg2 gzip \
libelf-dev libncurses5-dev libssl-dev make openssl pahole perl-base \
rsync tar xz-utils gettext texinfo pkg-config findutils file unzip tar \
perl bzip2 gzip patch g++ gcc diffutils build-essential binutils make sed

The second problem was using wget, which buildroot uses extensively to download packages. It was failing with Unable to establish SSL connection. This was because present-day SSL/TLS uses newer versions of the protocol. How was I going to get on without a working wget?

Second Thoughts

Buildroot has a command to download all of the buildroot source packages. This could be run from a modern machine and migrated to the older one. Here are the hints from make help

 Miscellaneous:
  source                 - download all sources needed for offline-build
  source-check           - check selected packages for valid download URLs

At the time, however, I chose to compile my own wget based on newer sources than available in my outdated package manager. I figured I'll document it quickly here. I think it helps to leave a record of what's been done. Why not.

Packages for wget

Compilation

cd gmp-6.3.0/
./configure --prefix=/usr/local
make
make check
sudo make install

export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/usr/lib/i386-linux-gnu
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
export PKG_CONFIG_LIBDIR=/usr/local/lib

echo export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/usr/lib/i386-linux-gnu >> ~/.bashrc
echo export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig >> ~/.bashrc
echo export PKG_CONFIG_LIBDIR=/usr/local/lib >> ~/.bashrc

cd ../nettle-3.6/
./configure --prefix=/usr/local --with-include-path=/usr/local/include --with-lib-path=/usr/local/lib --enable-public-key --enable-x86-aesni
make
sudo make install

cd ../libtasn1-4.9/
./configure --prefix=/usr/local --with-include-path=/usr/local/include --with-lib-path=/usr/local/lib
make -j8
sudo make install

cd ../gnutls-3.7.0
export ROOT_DIR=/usr/local
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig PKG_CONFIG_LIBDIR=/usr/local/lib  ./configure --prefix=/usr/local NETTLE_CFLAGS="-I${ROOT_DIR}/include" NETTLE_LIBS="-L${ROOT_DIR}/lib -lnettle" HOGWEED_CFLAGS="-I${ROOT_DIR}/include" HOGWEED_LIBS="-L${ROOT_DIR}/lib -lhogweed -lgmp" GMP_CFLAGS="-I${ROOT_DIR}/include" GMP_LIBS="-L${ROOT_DIR}/lib -lgmp" LIBTASN1_CFLAGS="-I${ROOT_DIR}/include" LIBTASN1_LIBS="-L${ROOT_DIR}/lib -ltasn1" LDFLAGS="-L${ROOT_DIR}/lib" --disable-maintainer-mode --disable-doc --disable-tools --disable-cxx --disable-ssl3-support --disable-ssl2-support --disable-tests --disable-valgrind-tests --disable-full-test-suite --disable-rpath --disable-libtool-lock --disable-libdane --with-included-unistring --without-zlib --without-libz-prefix --without-idn --without-libidn2 --without-tpm --without-p11-kit --disable-iri
make -j8
make check
sudo make install

cd ../wget-1.19.1
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig PKG_CONFIG_LIBDIR=/usr/local/lib  ./configure --prefix=/usr/local NETTLE_CFLAGS="-I${ROOT_DIR}/include" NETTLE_LIBS="-L${ROOT_DIR}/lib -lnettle" HOGWEED_CFLAGS="-I${ROOT_DIR}/include" HOGWEED_LIBS="-L${ROOT_DIR}/lib -lhogweed -lgmp" GMP_CFLAGS="-I${ROOT_DIR}/include" GMP_LIBS="-L${ROOT_DIR}/lib -lgmp" LIBTASN1_CFLAGS="-I${ROOT_DIR}/include" LIBTASN1_LIBS="-L${ROOT_DIR}/lib -ltasn1" LDFLAGS="-L${ROOT_DIR}/lib" --disable-maintainer-mode --disable-doc --disable-tools --disable-cxx --disable-ssl3-support --disable-ssl2-support --disable-tests --disable-valgrind-tests --disable-full-test-suite --disable-rpath --disable-libtool-lock --disable-libdane --with-included-unistring --without-zlib --without-libz-prefix --without-idn --without-libidn2 --without-tpm --without-p11-kit --disable-iri
make -j8
sudo make install

sudo mkdir  /etc/unbound
sudo unbound-anchor -a "/etc/unbound/root.key"

At this point the new wget was working, with just one small problem: FTP hosts would hang indefinitely. I'm not sure what caused this issue, but I was able to modify a few buildroot URLs to use https instead of ftp and all was fine.

End

That's all there is to this chapter. buildroot was able to compile a kernel so that's great progess!! My next plan is to begin working on the BSP code for a USB serial device firmware. (Other relevant terms are virtual COM (universal serial) USB CDC device class) I'll be interfacing through a PDIUSBD12. Successful creation of this bsp code will provide me with a usbtty from which I can monitor early bootup code as I further develop the package / ecosystem.

Bugs that were Solved

  1. nettle_rsa_sec_decrypt
  2. Solving libhogweed.so.2: undefined symbol: __gmpn_cnd_add_n

    Regarding these bugs, I recall that defining the LD_LIBRARY_PATH was a huge role, as the correct source libraries were now being found by the linker. If you ever aren't sure that your binary is using teh right libs, just use ldd on the library or binary.