Difference between revisions of "Using GPL Code"

From SecuriWiki
Jump to: navigation, search
m (fixed variables)
(updating links)
Line 1: Line 1:
 
[[Category:Almond+ 2014]]
 
[[Category:Almond+ 2014]]
First you must download the [http://forum.securifi.com/index.php/topic,1806.0.html GPL code from the URL found in the forums].
+
First you must download the [http://firmware.securifi.com/gpl/AP2-GPL.tar.gz GPL code] (from the URL found in the [http://forum.securifi.com/index.php/topic,1806.0.html forums]) and the [https://wiki.securifi.com/index.php?title=Almond_SDK_Setup_Guide SDK].
  
 
Then, if you're running on an 64bit OS, you may need to patch m4 and bison.
 
Then, if you're running on an 64bit OS, you may need to patch m4 and bison.

Revision as of 15:40, 3 June 2016

First you must download the GPL code (from the URL found in the forums) and the SDK.

Then, if you're running on an 64bit OS, you may need to patch m4 and bison.

Patching Tools

You will be creating patches directories in tools/m4/ and tools/bison, and adding the following files.

cd $GPL_DIR
mkdir tools/m4/patches tools/bison/patches

tools/m4/patches/010-stdio.in.h.patch

--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -141,7 +141,8 @@ _GL_WARN_ON_USE (fflush, "fflush is not
    so any use of gets warrants an unconditional warning.  Assume it is
    always declared, since it is required by C89.  */
 #undef gets
-_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
+/*_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");*/
+#define gets(a) fgets( a, sizeof(*(a)), stdin)

 #if @GNULIB_FOPEN@
 # if @REPLACE_FOPEN@

tools/bison/patches/010-stdio.in.h.patch

--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -143,7 +143,8 @@ _GL_WARN_ON_USE (fflush, "fflush is not
    so any use of gets warrants an unconditional warning.  Assume it is
    always declared, since it is required by C89.  */
 #undef gets
-_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");
+/*_GL_WARN_ON_USE (gets, "gets is a security hole - use fgets instead");*/
+#define gets(a) fgets( a, sizeof(*(a)), stdin)

 #if @GNULIB_FOPEN@
 # if @REPLACE_FOPEN@
Configuring Build Environment

Assuming you are using the GPL code and SDK toolchain, you need to tell the GPL code where to look (GPL_DIR is where you extracted the GPL code and TOOLCHAIN_DIR is where you have extracted the SDK). You will need to go into the OpenWRT configuration, then set the 3 external toolchain variables to point to the SDK.

cd $GPL_DIR
make menuconfig
Advanced configuration options (for developers)  --->
Use external toolchain  ---> (check this (<space>), then click to enter (<enter>))
(arm-openwrt-linux) Target name
(arm-openwrt-linux-) Toolchain prefix
(TOOLCHAIN_DIR/toolchain-arm_gcc-4.5.1+l_uClibc-0.9.32_eabi) Toolchain root

Escape out of the menus, and save your changes.

Compiling Packages

You can use the instructions at [1]

For example for recompiling udev (a simpler package without dependencies):

make tools/install
make toolchain/install
make package/udev/compile

After the first time, only the last command needs to be run. Then the package can be found in bin/g2/packages. You can also do make menuconfig and choose the packages you want to build, then just run make package/install.

Compiling All Packages

Not really recommended, but if you want to do so:

cd $GPL_DIR
make menuconfig
Global build settings --->
   [*] Select all packages by default
Exit & Save
./scripts/feeds update -a
./scripts/feeds install -a
make menuconfig
Exit & Save
IGNORE_ERRORS=y make
IGNORE_ERRORS=y make package/compile

Here is a short script that tries a little harder to compile all packages (instead of the last two lines above). Place it in the GPL_DIR:

#!/bin/bash

if [ "$1" != "-f" ] ; then
  IGNORE_ERRORS=y make -j 7 2>&1| tee errors.txt
  IGNORE_ERRORS=y make package/compile 2>&1| tee -a errors.txt
fi

for i in $(grep "failed to build" errors.txt | sed 's/^.*ERROR:[[:space:]]*\([^[:space:]]*\) failed to build.*$/\1/') ; do
  if [ "$i" != "" ] ; then
    echo Compiling: ${i}
    i="package/${i##*/}"
    make ${i}/compile V=99 > build_${i##*/}.txt 2>&1 || echo ${i} : Build failed, see build_${i##*/}.txt
  fi
done

Note: Some packages try to look for libraries in hardcoded places, so this can help:

ln -s $TOOLCHAIN_DIR/lib/* $TOOLCHAIN_DIR/usr/lib/
ln -s $TOOLCHAIN_DIR/bin $TOOLCHAIN_DIR/usr/bin