Difference between revisions of "Using GPL Code"

From SecuriWiki
Jump to: navigation, search
(linking gpl and sdk)
(Adding links for SDK and better GPL links)
 
(6 intermediate revisions by one user not shown)
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] (see [https://wiki.securifi.com/index.php/Talk:SDK_Setup_Guide_-_Almond%2B_2014 Discussion page] as well).
  
 
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.
Line 8: Line 8:
  
 
<code><pre>
 
<code><pre>
cd $TOOLCHAIN_DIR
+
cd $GPL_DIR
 
mkdir tools/m4/patches tools/bison/patches
 
mkdir tools/m4/patches tools/bison/patches
 
</pre></code>
 
</pre></code>
Line 45: Line 45:
  
 
===== Configuring Build Environment =====
 
===== Configuring Build Environment =====
Assuming you are using the GPL code and SDK toolchain, you need to tell the GPL code where to look (TOOLCHAINDIR 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.
+
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.
  
 
<code><pre>
 
<code><pre>
 +
cd $GPL_DIR
 
make menuconfig
 
make menuconfig
 
Advanced configuration options (for developers)  --->
 
Advanced configuration options (for developers)  --->
Line 53: Line 54:
 
(arm-openwrt-linux) Target name
 
(arm-openwrt-linux) Target name
 
(arm-openwrt-linux-) Toolchain prefix
 
(arm-openwrt-linux-) Toolchain prefix
(TOOLCHAINDIR/toolchain-arm_gcc-4.5.1+l_uClibc-0.9.32_eabi) Toolchain root
+
(TOOLCHAIN_DIR/toolchain-arm_gcc-4.5.1+l_uClibc-0.9.32_eabi) Toolchain root
 
</pre></code>
 
</pre></code>
  
 
Escape out of the menus, and save your changes.
 
Escape out of the menus, and save your changes.
 +
 +
===== Updating Feeds =====
 +
Feeds (the sources for all 3rd party packages) now use git, not svn, so you need to change the packages url:
 +
 +
<code><pre>
 +
$ diff -rub feeds.conf{.default,}
 +
--- feeds.conf.default  2016-04-19 14:15:30.910259634 -0400
 +
+++ feeds.conf  2016-04-19 17:39:49.826997677 -0400
 +
@@ -1,4 +1,4 @@
 +
-src-svn packages svn://svn.openwrt.org/openwrt/branches/packages_12.09
 +
+src-git packages git://git.openwrt.org/12.09/packages.git
 +
src-svn xwrt http://x-wrt.googlecode.com/svn/trunk/package
 +
src-svn luci http://svn.luci.subsignal.org/luci/branches/luci-0.11/contrib/package
 +
src-git routing git://github.com/openwrt-routing/packages.git;for-12.09.x
 +
</pre></code>
 +
 +
Then you can update and install the feeds (per [https://wiki.openwrt.org/doc/howto/build#updating_feeds]):
 +
 +
<code><pre>
 +
./scripts/feeds update -a
 +
./scripts/feeds install -a
 +
</pre></code>
  
 
===== Compiling Packages =====
 
===== Compiling Packages =====
Line 71: Line 94:
  
 
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 <code>make menuconfig</code> and choose the packages you want to build, then just run <code>make package/install</code>.
 
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 <code>make menuconfig</code> and choose the packages you want to build, then just run <code>make package/install</code>.
 +
 +
===== Compiling All Packages =====
 +
Not really recommended, but if you want to do so:
 +
 +
<code><pre>
 +
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
 +
</pre></code>
 +
 +
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:
 +
<code><pre>
 +
#!/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
 +
</pre></code>
 +
 +
Note: Some packages try to look for libraries in hardcoded places, so this can help:
 +
<code><pre>
 +
ln -s $TOOLCHAIN_DIR/lib/* $TOOLCHAIN_DIR/usr/lib/
 +
ln -s $TOOLCHAIN_DIR/bin $TOOLCHAIN_DIR/usr/bin
 +
</pre></code>

Latest revision as of 15:55, 3 June 2016

First you must download the GPL code (from the URL found in the forums) and the SDK (see Discussion page as well).

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.

Updating Feeds

Feeds (the sources for all 3rd party packages) now use git, not svn, so you need to change the packages url:

$ diff -rub feeds.conf{.default,}
--- feeds.conf.default  2016-04-19 14:15:30.910259634 -0400
+++ feeds.conf  2016-04-19 17:39:49.826997677 -0400
@@ -1,4 +1,4 @@
-src-svn packages svn://svn.openwrt.org/openwrt/branches/packages_12.09
+src-git packages git://git.openwrt.org/12.09/packages.git
 src-svn xwrt http://x-wrt.googlecode.com/svn/trunk/package
 src-svn luci http://svn.luci.subsignal.org/luci/branches/luci-0.11/contrib/package
 src-git routing git://github.com/openwrt-routing/packages.git;for-12.09.x

Then you can update and install the feeds (per [1]):

./scripts/feeds update -a
./scripts/feeds install -a
Compiling Packages

You can use the instructions at [2]

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