Sunday, April 29, 2012

Google Nexus S: Building and Flashing Ice Cream Sandwich 4.0.4

Google Nexus S: Building and Flashing Ice Cream Sandwich 4.0.4


Disclaimer

Use this guide at your own risk. No guarantees/warranties are made regarding the accuracy of this guide or the fitness of this material for any particular task. Neither this guide nor its authors are liable for any damages, direct or indirect, incurred by following the instructions in this guide. There is always the risk of a device being bricked during the upgrade process.

Prerequisites

Linux box running Ubuntu 12.04 (Precise Pangolin) Desktop 64bit. This guide is based on a fresh clean install.

Things to Note

  1. 1.This guide makes minimal changes to your system. 
  2. 2.For the instructions to work, all the commands must be executed on a single terminal session. Read “Restarting interrupted build” in case the build needs to be continued post interruption. 
  3. 3.Pay attention to the PATH variable. It is set in various places. It is not added to any “profile” file. 
  4. 4.Linux working experience necessary. 



Setup working directory

Box:~/$ mkdir Work
Box:~/$ mkdir Work/bin
Box:~/$ mkdir Work/src
Box:~/$ cd Work

Download Java 6


Box:~/Work$ mv ~/Downloads/jdk-6u31-linux-x64.bin ./

Install Java locally

Box:~/Work$ sh ./jdk-6u31-linux-x64.bin
Box:~/Work$ export PATH=`pwd`/jdk1.6.0_31/bin:$PATH

Update packages

Box:~/Work$ sudo apt-get install git-core gnupg flex bison gperf build-essential   zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev   libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev:i386   g++-multilib mingw32 openjdk-6-jdk tofrodos python-markdown   libxml2-utils xsltproc zlib1g-dev:i386

Install “repo”

“repo” is a convenience tool that makes it easier to download and work with Android sources.

Box:~/Work$ curl https://dl-ssl.google.com/dl/googlesource/git-repo/repo > ./bin/repo
Box:~/Work$ chmod u+x ./bin/repo
Box:~/Work$ export PATH=`pwd`/bin:$PATH

Pull sources.

This step is time intensive. After this step, stay in src directory.

Box:~/Work$ cd src
Box:~/Work/src$ repo init -u https://android.googlesource.com/platform/manifest -b android-4.0.4_r1
Box:~/Work/src$ repo sync
Pull and setup Nexus S binary drivers

Visit https://developers.google.com/android/nexus/drivers and download the right drivers for your device. Below is an example. On running the “sh” files, follow on-screen instructions to accept license.

Box:~/Work/src$ curl https://dl.google.com/dl/android/aosp/akm-crespo-imm76d-8314bd5a.tgz > ./aakm-crespo-imm76d-8314bd5a.tgz

Box:~/Work/src$ curl https://dl.google.com/dl/android/aosp/broadcom-crespo-iml74k-4b0a7e2a.tgz > ./broadcom-crespo-iml74k-4b0a7e2a.tgz

Box:~/Work/src$ curl https://dl.google.com/dl/android/aosp/imgtec-crespo-iml74k-33420a2f.tgz > ./imgtec-crespo-iml74k-33420a2f.tgz

Box:~/Work/src$ curl https://dl.google.com/dl/android/aosp/nxp-crespo-iml74k-9f2a89d1.tgz > ./nxp-crespo-iml74k-9f2a89d1.tgz

Box:~/Work/src$ curl https://dl.google.com/dl/android/aosp/samsung-crespo-iml74k-0dbf413c.tgz > ./samsung-crespo-iml74k-0dbf413c.tgz

Box:~/Work/src$ for i in *.tgz; do tar -xvzf "./$i"; done
Box:~/Work/src$ for i in *.sh; do sh "./$i"; done

Box:~/Work/src$ source build/envsetup.sh
Box:~/Work/src$ make clobber


Build cache

According to google, this should speed up your rebuilds.

Box:~/Work/src$ export USE_CCACHE=1
Box:~/Work/src$ export CCACHE_DIR=`pwd`/../.ccache
Box:~/Work/src$ ./prebuilt/linux-x86/ccache/ccache -M 20G

Build

In the lunch menu, type “7” (full_crespo-userdebug). Time intensive step. Consider fixing build errors prior to this step.

Box:~/Work/src$ source build/envsetup.sh
Box:~/Work/src$ lunch
Box:~/Work/src$ make -j4



Build errors

The Build step should throw these errors. The “Fix” shows the changes made to resolve the error. These fixes have been discussed in various forums and blogs on the web.

Error

host C: parseStringTest <= external/srec/tools/parseStringTest/parseStringTest.c
<command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
<built-in>:0:0: note: this is the location of the previous definition
<command-line>:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by default]
<built-in>:0:0: note: this is the location of the previous definition
cc1plus: all warnings being treated as errors
make: *** [out/host/linux-x86/obj/EXECUTABLES/obbtool_intermediates/Main.o] Error 1

Fix

Box:~/Work/src$ repo diff build/core/combo/HOST_linux-x86.mk

project build/
diff --git a/core/combo/HOST_linux-x86.mk b/core/combo/HOST_linux-x86.mk
index 5ae4972..7df2893 100644
--- a/core/combo/HOST_linux-x86.mk
+++ b/core/combo/HOST_linux-x86.mk
@@ -53,6 +53,6 @@ HOST_GLOBAL_CFLAGS += \
        -include $(call select-android-config-h,linux-x86)

 # Disable new longjmp in glibc 2.11 and later. See bug 2967937.
-HOST_GLOBAL_CFLAGS += -D_FORTIFY_SOURCE=0
+HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0

 HOST_NO_UNDEFINED_LDFLAGS := -Wl,--no-undefined

Error

external/mesa3d/src/glsl/linker.cpp: In function ‘void assign_varying_locations(gl_shader_program*, gl_shader*, gl_shader*)’:
external/mesa3d/src/glsl/linker.cpp:1394:49: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1394:50: error: ‘varyings’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1394:58: error: ‘offsetof’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1395:48: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1412:47: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1412:48: error: ‘position’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1414:47: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1414:48: error: ‘pointSize’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1424:47: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1424:48: error: ‘position’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1428:47: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1428:48: error: ‘frontFacingPointCoord’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1431:47: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1431:48: error: ‘frontFacingPointCoord’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp: In function ‘void link_shaders(const gl_context*, gl_shader_program*)’:
external/mesa3d/src/glsl/linker.cpp:1734:49: error: expected primary-expression before ‘,’ token
external/mesa3d/src/glsl/linker.cpp:1734:50: error: ‘fragColor’ was not declared in this scope
external/mesa3d/src/glsl/linker.cpp:1734:59: error: ‘offsetof’ was not declared in this scope
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libMesa_intermediates/src/glsl/linker.o] Error 1

Fix

Box:~/Work/src$ repo diff external/mesa3d/src/glsl/linker.cpp

project external/mesa3d/
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index f8b6962..f31e5b5 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -67,6 +67,7 @@
 #include <cstdio>
 #include <cstdarg>
 #include <climits>
+#include <stddef.h>

 #include <pixelflinger2/pixelflinger2_interface.h>

Error

host C++: liboprofile_pp <= external/oprofile/libpp/arrange_profiles.cpp
In file included from external/oprofile/libpp/arrange_profiles.cpp:24:0:
external/oprofile/libpp/format_output.h:94:22: error: reference ‘counts’ cannot be declared ‘mutable’ [-fpermissive]
host C++: liboprofile_pp <= external/oprofile/libpp/callgraph_container.cpp
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/liboprofile_pp_intermediates/arrange_profiles.o] Error 1

Fix

Box:~/Work/src$ repo diff external/oprofile/libpp/format_output.h

project external/oprofile/
diff --git a/libpp/format_output.h b/libpp/format_output.h
index b6c4592..8e527d5 100644
--- a/libpp/format_output.h
+++ b/libpp/format_output.h
@@ -91,7 +91,7 @@ protected:
                symbol_entry const & symbol;
                sample_entry const & sample;
                size_t pclass;
-               mutable counts_t & counts;
+               counts_t & counts;
                extra_images const & extra;
                double diff;
        };

Error

external/hyphenation/hyphen.c:404:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
In file included from external/gtest/src/../include/gtest/gtest-param-test.h:157:0,
                 from external/gtest/src/../include/gtest/gtest.h:69,
                 from external/gtest/src/gtest_main.cc:32:
external/gtest/src/../include/gtest/internal/gtest-param-util.h:122:11: error: ‘ptrdiff_t’ does not name a type
In file included from external/gtest/src/../include/gtest/gtest-param-test.h:157:0,
                 from external/gtest/src/../include/gtest/gtest.h:69,
                 from external/gtest/src/../src/gtest.cc:34,
                 from external/gtest/src/gtest-all.cc:36:
external/gtest/src/../include/gtest/internal/gtest-param-util.h:122:11: error: ‘ptrdiff_t’ does not name a type
make: *** [out/host/linux-x86/obj/STATIC_LIBRARIES/libgtest_main_host_intermediates/gtest_main.o] Error 1

Fix

Box:~/Work/src$ repo diff  external/gtest/include/gtest/internal/gtest-param-util.h

project external/gtest/
diff --git a/include/gtest/internal/gtest-param-util.h b/include/gtest/internal/gtest-param-util.h
index 5559ab4..405dc4d 100644
--- a/include/gtest/internal/gtest-param-util.h
+++ b/include/gtest/internal/gtest-param-util.h
@@ -37,6 +37,7 @@
 #include <iterator>
 #include <utility>
 #include <vector>
+#include <cstddef>

 #include <gtest/internal/gtest-port.h>
Error

out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function `MutexImpl':
/home/raja/Work/src/external/llvm/lib/Support/Mutex.cpp:69: undefined reference to `pthread_mutexattr_init'
/home/raja/Work/src/external/llvm/lib/Support/Mutex.cpp:75: undefined reference to `pthread_mutexattr_settype'
/home/raja/Work/src/external/llvm/lib/Support/Mutex.cpp:80: undefined reference to `pthread_mutexattr_setpshared'
/home/raja/Work/src/external/llvm/lib/Support/Mutex.cpp:89: undefined reference to `pthread_mutexattr_destroy'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::tryacquire()':
/home/raja/Work/src/external/llvm/lib/Support/Mutex.cpp:143: undefined reference to `pthread_mutex_trylock'
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader] Error 1

Fix

Box:~/Work/src$ repo diff external/llvm/llvm-host-build.mk

project external/llvm/
diff --git a/llvm-host-build.mk b/llvm-host-build.mk
index 5219efd..53a6229 100644
--- a/llvm-host-build.mk
+++ b/llvm-host-build.mk
@@ -10,6 +10,8 @@ LOCAL_CFLAGS :=       \
        -Wwrite-strings \
        $(LOCAL_CFLAGS)

+LOCAL_LDLIBS := -lpthread -ldl
+
 ifeq ($(LLVM_ENABLE_ASSERTION),true)
 LOCAL_CFLAGS :=        \
        -D_DEBUG        \

Error

host C++: llvm-rs-cc <= frameworks/compile/slang/slang_rs_export_foreach.cpp
host C++: llvm-rs-cc <= frameworks/compile/slang/slang_rs_object_ref_count.cpp
frameworks/compile/slang/slang_rs_export_foreach.cpp: In static member function ‘static slang::RSExportForEach* slang::RSExportForEach::Create(slang::RSContext*, const clang::FunctionDecl*)’:
frameworks/compile/slang/slang_rs_export_foreach.cpp:249:23: error: variable ‘ParamName’ set but not used [-Werror=unused-but-set-variable]
cc1plus: all warnings being treated as errors
make: *** [out/host/linux-x86/obj/EXECUTABLES/llvm-rs-cc_intermediates/slang_rs_export_foreach.o] Error 1

Fix

Box:~/Work/src$ repo diff frameworks/compile/slang/slang_rs_export_foreach.cpp

project frameworks/compile/slang/
diff --git a/slang_rs_export_foreach.cpp b/slang_rs_export_foreach.cpp
index a4025ca..0dbf954 100644
--- a/slang_rs_export_foreach.cpp
+++ b/slang_rs_export_foreach.cpp
@@ -246,7 +246,6 @@ RSExportForEach *RSExportForEach::Create(RSContext *Context,
                                     clang::SourceLocation(),
                                     &Ctx.Idents.get(Id));
 
-      llvm::StringRef ParamName = PVD->getName();
       clang::FieldDecl *FD =
           clang::FieldDecl::Create(Ctx,
                                    RD,

Add build output tools to PATH

Box:~/Work/src$ export PATH=`pwd`/out/host/linux-x86/bin:$PATH

Nexus S udev rules

This is needed for your device to be detected by ADB. Execute the below commands and then connect your Nexus S.

Box:~/Work/src$ sudo bash
Box:~/Work/src# echo SUBSYSTEM==\"usb\", ATTR{idVendor}==\"04e8\", MODE=\"0666\", GROUP=\"plugdev\" >> /etc/udev/rules.d/51-android.rules
Box:~/Work/src# chmod a+r /etc/udev/rules.d/51-android.rules
Box:~/Work/src# service udev restart






Flash the device

Perform flashing as root, to avoid permission issues.

Box:~/Work/src$ sudo bash
Box:~/Work/src# export PATH=`pwd`/out/host/linux-x86/bin:$PATH
Box:~/Work/src# adb reboot bootloader
Box:~/Work/src# fastboot oem unlock
Box:~/Work/src# fastboot erase cache
Box:~/Work/src# fastboot erase userdata
Box:~/Work/src# export ANDROID_PRODUCT_OUT=`pwd`/out/target/product/crespo
Box:~/Work/src# fastboot flashall

Restarting interrupted build

This section should serve as an example. Depending on where the build was interrupted, additional commands may have to be executed to continue.

Set the paths and continue as before.

Box:~/$ cd Work
Box:~/Work$ export PATH=`pwd`/jdk1.6.0_31/bin:$PATH
Box:~/Work$ export PATH=`pwd`/bin:$PATH
Box:~/Work$ cd src
Box:~/Work/src$ source build/envsetup.sh
Box:~/Work/src$ make -j4

Reverting back to stock firmware

Download the stock version for your device from https://developers.google.com/android/nexus/images

Below is an example that uses soju-imm76d-factory-ca4ae9ee.tgz (4.0.4). We assume that the existing build is valid. “fastboot” is needed from the earlier build. Root is needed to avoid any permission problems.

Box:~/$ cd Work
Box:~/Work$ mkdir stock
Box:~/Work$ mv ~/Downloads/soju-imm76d-factory-ca4ae9ee.tgz stock
Box:~/Work$ cd stock/
Box:~/Work/stock$ tar -xvzf soju-imm76d-factory-ca4ae9ee.tgz
Box:~/Work/stock$ cd soju-imm76d/
Box:~/Work/stock/soju-imm76d$ sudo bash
Box:~/Work/stock/soju-imm76d# export PATH=~/Work/src/out/host/linux-x86/bin:$PATH
Box:~/Work/stock/soju-imm76d# adb reboot bootloader
Box:~/Work/stock/soju-imm76d# sh flash-all.sh

Version numbers

Box:~/Work/src$ make -v
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu

Box:~/Work/src$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

Box:~/Work/src$ java -version
java version "1.6.0_31"
Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)

Box:~/Work/src$ python --version
Python 2.7.3

Informational links



Consider Donating

Did this guide help you? Consider donating at http://spearhend.blogspot.com

The donate icon is on the top right and donations are accepted via Paypal.

PDF Version


7 comments:

  1. Perfect instructions.....Thank you !
    Worked with my Nexus S (AT&T version i9020A).... I replaced android-4.0.4_r1 with the latest version.

    ReplyDelete
  2. i'hv used the solution for make: *** [out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader]
    but when i tried to "make" again then it shows another error
    external/llvm/llvm-host-build.mk:14: *** missing separator

    what can be the solution for this??

    ReplyDelete
    Replies
    1. Tell me more about your build environment and target

      Delete
    2. Hi i followed the instrtuctions from
      1.http://source.android.com/source/building-devices.html fro Nexus S.
      But idid not follow the "Obtaining prprietery Binaries step".
      2.After this " fastboot -w flashall ", i got this output in the terminal

      ~/JB_Source# ~/Downloads/adt-bundle-linux-x86_64-20131030/sdk/platform-tools/fastboot -w flashall
      --------------------------------------------
      Bootloader Version...: I9020XXLC2
      Baseband Version.....: I9020XXKI1
      Serial Number........: 303384E96EB000EC
      --------------------------------------------
      checking product...
      OKAY [ 0.000s]
      sending 'boot' (3964 KB)...
      OKAY [ 0.675s]
      writing 'boot'...
      OKAY [ 0.503s]
      sending 'recovery' (4308 KB)...
      OKAY [ 0.751s]
      writing 'recovery'...
      OKAY [ 0.543s]
      sending 'system' (173143 KB)...
      OKAY [ 30.364s]
      writing 'system'...
      OKAY [ 29.604s]
      erasing 'userdata'...
      OKAY [ 0.428s]
      formatting 'userdata' partition...
      Erase successful, but not automatically formatting.
      Can't determine partition type.
      OKAY [ 0.001s]
      erasing 'cache'...
      OKAY [ 1.987s]
      formatting 'cache' partition...
      Erase successful, but not automatically formatting.
      Can't determine partition type.
      OKAY [ 0.001s]
      rebooting...

      finished. total time: 64.883s
      4.But iam getting black screen.(Still iam able to detect the phone and keep in fastboot mode).
      5.So my doubt is should i compulsorily download that binaries and use in source ??

      Delete
    3. "Obtaining proprietary binaries" section in http://source.android.com/source/building-devices.html has been elaborated in "Pull and setup Nexus S binary drivers" in this page. Yes, you must compulsorily download and include these drivers in your build source tree.

      Delete
    4. I have tried with all the fixes as given above.
      finally it finished my build also.
      but unfortunately, this is not worth for me.because my tab is not booting up after updating this newl file system.

      Could anyone please help me out on this ...

      Delete
    5. Please post the exact model number of the device you are trying to build for

      Delete