Category: Technical

  • Yet Another Thread about ChatGPT: Possible Application into ISO26262 Certification Process?

    Problem Statement

    There is a growing demand of automotive OEMs for a POSIX software OS that is capable of powering up a complex centralized multimedia ECU that drives multiple usecases including safety ones such as Instrument Cluster, ADAS, and others, in addition to non-safety applications for entertainment as Navigation , phone ..etc.

    This demand is met with a shortage of solutions in the market, leading to the necessity of combining multiple OSes from different vendors which yields a complex software architecture , and a cumbersome  integration process by design.  Moreover, in most cases the market is monopolized by a single or a few players, putting most OEMs in a vendor lock-in situation , on top of finding it very expensive to get the right talent from the market for closed source technologies.

    These factors put legacy OEMs in a vulnerable position against rising threats from the US and China. The latter can deliver new software solutions at a much higher speed by relying on open source, adopting simpler architectures, disregarding some of the existing standards, and taking bolder decisions.

    The legacy OEMs need a software solution that enables them to develop software with higher speed while still abiding to the legal frameworks and the existing automotive standards. They need to break free from the vendor lock-in situation and explore new technologies that offer more flexibility, cost-effectiveness, and efficiency.

    Overview of some solutions in the market

    QNXNEW! Redhat Vehicle OSAdding a separate AUTOSAR controlloer
    Battle tested in AutomotiveOne known automotive customer Battle tested in Automotive
    * Closed-source
    * Less talent in the market
    * Expensive
    * Monopoly
    * Open source
    * Big pool of talent
    * Will it be expensive too ?
    * Open standard, open-source-when-you-pay
    * Big pool of talent
    * Expensive
    * Complex architecture
    * Nearly a Monopoly
    * Outdated tools and workflows

    Using ChatGPT to develop a safe Linux distribution

    Can we employ the power of ChatGPT to establish a fast and simplified certification/recertification process to deliver a safe Linux distribution according to the ISO26262? ChatGPT usecases to investigate:

    • Can ChatGPT write software requirements from a given code implementation?
    • Can ChatGPT write software requirements from a high level description of a software package?
    • Can ChatGPT create architectural diagrams? 
    • Can ChatGPT write unit tests from a given code implementation?
    • Can ChatGPT increase test coverage?
    Usecase for investigation CPPRESTSDK (medium size software package)
    • There is no way (so far) to give a whole git repo to be analyzed by ChatGPT
      • However, OpenAI has promised to release several plugins that will allow ChatGPT to read files and/or access the internet
    • It doesn’t seem that ChatGPT can build the context of the whole project and it gets lost when the code snippet provided to it is too long
      • For example, it selectively explained a subset of functions when I provided a file of 500 lines
      • It couldn’t process a larger file ~ 1k lines
      • When I asked it to give a really detailed analysis , it started spitting out description of imaginary functions that I didn’t ask about at all!
    • ChatGPT was able to provide an explanation to a piece of code in the form of requirements specifications
    • ChatGPT was able to perform on a much higher level when presented with a single simple c function , it could come up with 2 high quality test cases

    Conclusions

    • For any kind of realistic results, a code needs to be broken down into smaller pieces before feeding it into ChatGPT, then the output still also needs human supervision and review.
    • Humans will need to create context and analyse the workpackages. Detailed plan of work to be created as if a team will do it with no AI assistance.
    • AI can then kick in and speed up the execution of single tasks and improve the overall timeline of the project.
    • The final output shall be orchestrated and delivered by humans
    • ChatGPT is a resourceful and a smart assistant, but in a complex narrative I would regard it as a supporting character or a “CoPilot”
    • ChatGPT can spit out completely wrong information with a very confident tone
    • Software Engineers can rest assured that their jobs are not being replaced anytime soon, however the expectations of the efficiency of someone will drastically change, and the gap between a SWE+Copilot vs an old school SWE will be tremendous
  • تجربة ستارت اب بيكويتي pequity و ازاي فشلنا فيها ، و ايه اللي اتعلمته ؟

    تجربة ستارت اب بيكويتي pequity و ازاي فشلنا فيها ، و ايه اللي اتعلمته ؟

    مقدمة

    مع الظرف الاقتصادي الصعب اللي بتمر بيه مصر و العالم و حيرة الناس في انهم يقدروا يحافظوا على قيمة ما تبقى من مدخراتهم انا حابب النهاردة أتكلم عن تجربة اشتغلت عليها مع صديقي ياسر فتحي لمدة ٦ شهور متواصلة تقريبا من اواخر ٢٠٢٠ لحد منتصف ٢٠٢١ بنحاول نحل مشكلة بالرغم من ان التجربة ممكن بشكل موضوعي نحكم عليها بالفشل أو أنها لم ترتقي لمستوى توقعاتنا و لكن في تفاصيل كتيرة حصلت في الفترة دي ممكن نتكلم عليهم

    طيب ليه انا باكتب ؟ السبب الرئيسي أنا مازلت مقتنع انها مشكلة كبيرة و محتاجة شغل كتير و ممكن حد يستفيد من تجربتنا او يحاول يكررها بشكل مختلف و السبب التاني إني باحب شخصيا الكتابة و التوثيق و باحاول دايما اكتب اذا اتيحت الفرصة ، السبب الاخير أننا نشرنا كل السورس كود اللي اشتغلنا عليه الفترة دي برخصة مفتوحة المصدر و بالتالي من المهم اننا ننشر تفاصيل اكتر لاي حد حابب يعيد استخدامها و الروابط موجودة في اخر المقال

    ايه هي المشكلة و ازاي حاولنا نقدم حل ؟

    احنا شفنا ملايين من الناس مش قادرين يلاقوا فرص مجدية و آمنة انهم يستثمروا أي فوائض ادخارية و بالتالي بيتجهوا للمستريحين او على أفضل الأحوال العقارات او شهادات بنكية مش بتحميهم من التضخم بشكل كبير و في نفس الوقت في ملايين من المشروعات الصغيرة والمتوسطة اللي بتدخل أرباح معقولة و قدامها فرصة كويسة للتوسع لو توفر سيولة كويسة

    طيب هل المشكلة دي حاجة في خيالنا بس؟ الحقيقة في ارقام كتيرة جدا بتتكلم عن حجم السوق الضخم زي مثلا ان المشاريع الصغيرة والمتوسطة بتمثل حوالي ٩٨٪ من الاقتصاد المصري و ٩٧٪ من الاقتصاد الجزائرى ، دي مشاريع راس مالها بيكون صغير جدا و بتشغل عدد افراد محدود زي كشك سجاير او مخبز او ورشة نجارة بسيطة …الخ

    رقم تاني مهم جدا هو ٦٪ نسبة المستثمرين الأفراد في البورصة المصرية و الفارق مهول ٥٥٪ للبورصة الامريكيه و لو بصينا مع الرقم ده على كم الشقق المغلقة يقوي جدا فرضيتنا

    الحل

    احنا اتفقنا مبدئيًا على حاجة الناس لسوق يربط بين مستثمر و صاحب بيزنس صغير او متوسط لكن اتناقشنا كتير عن دورنا في السوق كوسيط لان ده كان من أهم القرارات اللي هتاثر على اسلوب الشغل و قررنا اننا نقدم الحد الادني بدون اي تداخل بين الطرفين عشان نبعد في البداية عن المعوقات القانونية و اي مسؤولية مباشرة في عملية البيع و الشراء لكننا في نفس الوقت طورنا ادوات بتمكن صاحب اي مشروع انه يقيم مشروعه ماليا بناءً على مدخلات كتير و ده يعتبر أسلوب مختلف عن السائد ان الناس بتقيم المشروع بقيمة الارض فقط مع المعدات و الاجهزة او بشكل عرفي ، كانت فكرتنا انه عن طريق الادوات اللي وفرناها للتقييم ممن نوفر نقطة بداية ايجابية بين البايع و الشاري

    اخترنا اننا نركز شغلنا على مصر و شمال افريقيا و دول العالم التالت اللي فيها كثافة سكانية عالية و هيكل اقتصادي مشابه لينا عشان ننفذ بروتوتايب واحد نقدر نجرب بيه فكرتنا في أماكن مختلفة في وقت واحد

    بدانا نشتغل بالتوازي على تطبيق اندرويد و شغل التسويق عن طريق إعلانات الفيسبوك و قدرنا نوصل ل بروتوتايب كويس في وقت قليل جاهز للنشر على متجر بلاي و زودنا دعم للغات مختلفة تغطي مجموعة الدول اللي كنا بنستهدفها زي اللغات العربية و الانجليزية و الفرنسية و التركية و الاوردو و غيرها ..

    مجرد ما رفعنا التطبيق قدرنا بميزانية تسويق محدودة جدا على Google و Facebook (اقل من الف دولار) نوصل لاكتر من الف داونلود و ٤٠٠ تسجيل مستخدم جديد و شفنا اهتمام من دول في الشرق الأوسط اكتر من مصر و خاصة شمال افريقيا و كان في البداية مؤشرات ايجابية كويسة زي انه كان بيوصل لنا كم كبير من الرسايل على صفحتنا مهتمين بالموضوع

    دقات الساعة

    دخلنا في الجد و المرحلة اللي بتنطلق فيها الفكرة من فكرة لبيزنس على أرض الواقع و اهم مؤشر كنا بنبص عليه هو عدد الشركات اللي سجلت في الموقع عشان تدور على توسع و مشتري و لكن للأسف ما قدرناش نحقق نمو في قاعدة بياناتنا

    بدأنا نحاول في كذا اتجاه زي اننا نعمل استطلاعات رأي على الفيسبوك أو اننا نعين موظف يكون مختص انه يتواصل مباشرة مع أصحاب البيزنس اللي ممكن يكونوا مهتمين

    بدأنا كمان نتواصل مع الرسايل الكتيرة اللي وصلت لينا سواء تليفونيا أو عن طريق الفيسبوك و لكن ظل حجم ردود الفعل بعد ما تواصلنا مع أصحاب الرسائل ضعيف و غير كافي انه يساعدنا نقدم في أي مسرع من مسرعات الشركات الناشئة و كانت نقطة ضعف قوية اننا مش قادرين نبين عدد كبير من المستخدمين في ملف التقديم لما قدمنا في كذا برنامج عشان تاخد الفكرة لقدام

    و طبعا بما اننا احنا الاتنين عندنا وظيفة رئيسية و مغامرة بيكويتي كانت بعد وقت العمل بدأ مخزون الطاقة و الحماس يقل تدريجيا مع قلة رد الفعل من السوق و مع الوقت بدأنا نتخلى عن محاولات التقديم المختلفة اللي عملناها ده غير طبعا أماكن تانية قدمنا فيها و اترفضنا للسبب اللي قلته قبل كدة

    الختام .. ايه اللي اتعلمته ؟

    من أهم الدروس اللي أنا شايفها مهمة انك دائما تعمل ال bootstrapping طالما تقدر على كل التاسكات المطلوبة للستارت اب بتاعتك ، ٩٩٪؜ من المشاريع و الأفكار الجديدة بتفشل و بالتالي للأسف مهما كانت شطارتك ف احتمالية الخسارة أقل من المكسب و في الحالة دي الخبطة هتكون أقل بكتير لو استثمرت مجهودك و وقتك ( و ده عن تجربة شخصية أخرى ممكن أكتب عنها مرة تانية) مقارنة بانك تغامر بفلوسك أو فلوس حد تاني و كمان إنك اكتر واحد عندك شغف لفكرتك و هتحاول توصل أعلى جودة تقدر عليها و اعتقد اننا كنا راضيين جدا عن البروتوتايب اللي اتنفذ في وقت قليل و بجودة كويسة

    من النقط اللي أنا شايف انها فرقت معانا اننا ما كانش عندنا علاقات في مجال ريادة الأعمال و ال fintech ، و في ظني لو عندنا شبكة كويسة كانت هتفرق معانا بشكل كبير و عشان كدة حاولنا نقدم في برامج ريادة أعمال مختلفة و ياسر التحق بمنحة لريادة الأعمال في المجال و لكن في النهاية يظل حكم السوق هو الحقيقة الأكيدة و السوق ما تفاعلش مع فكرتنا بالشكل اللي قدمناه

    من المشاكل التانية اللي انا شايف أنها كانت هتواجهنا لو حصل رد فعل قوي اننا ما كناش محددين استراتيجية واضحة لتحقيق الأرباح و كنا مركزين بشكل أساسي ننمو و نجمع أكبر عدد مستخدمين و لكن ما فكرناش بعد كدة في نموذج محدد للربح و كان عندنا تصور مبدأي اننا هنطبق فكرة ال freemium

    ختاما أقدر أقول انها كانت تجربة ممتعة جدا لمسنا فيها جوانب كتير جدا من المشروع على العكس من الشغل في شركة بيكون اكتر تخصصا و اتمنى لو الواحد يقدر يكررها تاني في مجال آخر مع فكرة تانية و يمكن التجارب الجاية تلاقي النجاح الكافي ، يمكن اللي كان ينقصنا أننا نشوف رد فعل كويس و نتواصل أكتر مع ناس مهتمة

    Sources

    اداة التقييم كانت مكونة من ٣ مكونات و الباك اند كانت ٢ منهم الجزء الأول كان ماتلاب مودل بيحسب قيمة البيزنس عن طريق مجموعة مدخلات و المكون التاني كان REST API للموديل معمولة عن طريق python flask و الفرونت بتاعنا كان تطبيق اندرويد بالنسبة لمكونات الباك اند ف رفعناها على GitHub برخصة Apache مفتوحة المصدر اللي بتتيح لأي حد مهتم يعيد استخدامهم

    https://github.com/Pequity-me/PequityIntrinsicValuation

    https://github.com/Pequity-me/pequity-rest

  • Setting up Rust Environment for Linux Kernel Development

    Setting up Rust Environment for Linux Kernel Development

    Hey 👋

    It’s me again, still writing about Rust before actually going beyond the hello world part of the documentation, but I will let you know why.

    I am currently going through Chris Simmonds’ terrific book “Mastering Embedded Linux Programming, and while reading through the chapter covering the kernel configuration and compilation , I stumbled upon a nice youtube video from the linux foundation covering the same topic but using the Rust fork as the codebase.

    So, since I have an interest in Rust too, I said why not combining both ? Which was actually a good choice because both the video and the book covered each other gaps.

    While watching the video, I took a note of most of the commands in a github gist which I think should be pretty useful for my future self and and other people too. I thought also of taking the notes here because why not ..

    #
    # Instructions for the video https://www.youtube.com/watch?v=tPs1uRqOnlk excluding setting up the env ( e.g. installing Rust and llvm)
    #
    
    
    #
    # Kernel
    #
    
    $ git clone --depth=1 https://github.com/Rust-for-Linux/linux.git
    $ cd linux/
    $ make allnoconfig qemu-busybox-min.config
    $ make allnoconfig qemu-busybox-min.config rust.config
    $ make LLVM=1 rustavailable # should say Rust is available if you have all dependencies
    $ make LLVM=1 -j4
    
    #
    # Busybox
    #
    $ cd busybox
    $ git clone --depth=1 https://github.com/mirror/busybox.git
    $ make defconfig
    $ make menuconfig # then from settings select use static libraries 
    # make -j4
    $ cd ./_install/
    $ find . | cpio -H newc -o | gzip > ../ramdisk.img
    
    
    #
    # running qemu
    #
    $ cd linux/
    $ qemu-system-x86_64 -nographic -kernel vmlinux # should panic
    $ qemu-system-x86_64 -nographic -kernel vmlinux -initrd ../busybox/ramdisk.img # should start
    
    
    #
    # adding proc filesystem to enable ps
    #
    $ cd busybox/_install/
    $ vim etc/init.d/rcS 
    # then add this content inside 
    # mkdir -p /proc 
    # mount -t proc none /proc
    $ find . | cpio -H newc -o | gzip > ../ramdisk.img
    $ qemu-system-x86_64 -nographic -kernel vmlinux -initrd ../busybox/ramdisk.img # ps should work
    
    
    #
    # enabling a rust sample kernel module
    #
    $ make LLVM=1 menuconfig
    # then select the samples from kernel hacking --> samples --> rust samples
    
    
    #
    # enable networking
    #
    $ cd busybox/_install/
    $ vim etc/init.d/rcS 
    # then add this content inside to enable loopback interface 
    # ifconfig lo up
    # udhcpc -i eth0
    $ mkdir -p usr/share/udhcpc
    $ cp ../examples/udhcp/simple.script usr/share/udhcpc/default.script
    $ qemu-system-x86_64 -nographic -kernel vmlinux -initrd ../busybox/ramdisk.img -nic user,model=rtl8139
    $ qemu-system-x86_64 -nographic -kernel vmlinux -initrd ../busybox/ramdisk.img -nic user,model=rtl8139,hostfwd=tcp::5556-:8080

  • My talk about virtualization in automotive on the E-OnTech#7 event

    I have just decided to post a link to the talk I made on last November hoping maybe to boost the number of views which is currently below 100 (most of them are family and friends 🙂 ) to maybe 101 or 102. I am also including the slides which are not linked in the original video.

    Full talk on youtube
    Slides
  • Relating C++ move semantics to python objects

    I have been learning lately about C++11 move semantics, originally being a C programmer who is concerned with the performance it was very interesting to explore such an important optimization feature. I had to go through many articles explaining rvalues, lvalues and the && operator. I believe you still need to learn these topics to develop a firm understanding of the topic but in my point of view the move semantics can be explained intuitively by drawing the similarity between it and python’s object execution model.

    The goal of move semantics is to avoid copying large objects unnecessarily when they are passed from one function to another.

    How are objects passed in python?

    Interestingly enough, python was created with that particular optimization in mind.

    Firstly, It’s important to understand the subtle difference between the interpretation of the following statement in python and C++


    str = 'medium'

    view raw

    assignment.py

    hosted with ❤ by GitHub

    In C++ the variable str is created in memory, this location in memory contains the data medium and str refers to this memory location.

    However in python the story is different. Although this statement also creates an object with the same content, but str isn’t the object reference. str is a merely a name and the statement binds it to the object. This subtle deviation may not look crucial but it makes all the difference when passing arguments to a function.

    Consider the following 2 code snippets


    def modify(arg):
    arg = 'hard'
    str = 'medium'
    modify(str)
    print(str) # >> medium

    In the first snippet, an immutable object is created containing the data ‘medium’ and str is bound to this object. When the method modify is called a new name arg is also bound to ‘medium’, but as soon as line 2 is executed the binding of arg is relocated to another new object with the data ‘hard’ because there is no way to change an immutable. The resulting behavior appears as a conventional pass by value call.


    def modify(arg):
    arg += [1]
    l = [2]
    modify(l)
    print(l) # >> [2, 1]

    view raw

    call-by-ref.py

    hosted with ❤ by GitHub

    On the other hand, the behavior depicted in the second snippet resembles a pass by reference call as modify here doesn’t rebind arg to a new object because this object is mutable. arg and l are two names bound to the same object. When line 2 is executed this object is modified.

    In python object references are passed by value, in other words objects are moved.

    C++ move semantics in layman terms

    Before the move semantics there were a couple of ways to avoid unnecessary large copies by passing pointers around which is somehow considered an unsafe practice compared to use an instantiated object which auto destructs.

    Move semantics are based on rvalue references. An rvalue appears on the right hand side of the assignment statement. Example of an rvalue could be “medium” here:


    string str = "medium";

    view raw

    assignment.cpp

    hosted with ❤ by GitHub

    Also the function getName() can return an rvalue because it appears on the right side of the statement.


    string getName() {
    string str = "medium";
    return s;
    }
    // getName() returns an rvalue
    string&& name = getName();

    view raw

    rvalue.cpp

    hosted with ❤ by GitHub

    name is an rvalue reference.

    I like to think of an rvalue as a python object and the rvalue reference as the name bound to this object. The difference being that an rvalue can’t exist on its own while python relies on garbage collection to clean up objects which are no longer bound to any scope.


    class Obj {
    //default constructor
    Obj(int size){
    ..
    }
    //copy constructor
    Obj(const Obj& other){
    ..
    }
    //assignment operator
    Obj& operator= (const Obj& other){
    ..
    }
    }
    Obj B;
    B = Obj(1000);

    view raw

    copy.cpp

    hosted with ❤ by GitHub

    Without a move constructor the last line assignment will

    • allocate memory for the temporary object (and destruct it later)
    • allocate memory again at the destination

    Adding a move constructor to the object definition will optimize out the second allocation and reuse the previous allocation for the destination.


    class Obj {
    //move constructor
    Obj(const Obj&& other){
    ..
    }
    //move assignment operator
    Obj& operator= (const Obj&& other){
    ..
    }
    }

    view raw

    move.cpp

    hosted with ❤ by GitHub

    Conclusion

    Having this analogy in head, comprehending the power of move semantics was no more complicated. When a move constructor is defined for an object, it will be possible to rebind it to different name while avoiding expensive copies.

    Resources

    https://medium.com/@meghamohan/mutable-and-immutable-side-of-python-c2145cf72747

    https://www.internalpointers.com/post/c-rvalue-references-and-move-semantics-beginners

    Lesson #5: Move Semantics

    https://stackoverflow.com/questions/3106110/what-is-move-semantics

     

  • Serial Communication with FTDI D2xx API on Windows

    I was performing some testing on the FTDI throughput and I wrote this simple program that measures the throughput of FTDI chip if you connect its Rx pin to the Tx pin.

    You are free to use it for any application with FTDI, it proved to be actually faster than using Windows VCP API but remember you need to install D2xx driver and make sure that your FTDI is actually using this driver and not the default ًWindows VCP driver

    Note that the D2xx API uses a different method than conventional

        hSerial = CreateFile("COM9",GENERIC_READ | GENERIC_WRITE,
                                  0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);

    , it uses a string name instead that you can get from
    device manager >> Right click on COM >> Details >> From the scroll list choose Device instance id >> you will find it after VID and PID

    Code on github 

     

     

     

     

     

  • Fast DES C++ code

    I found an old undergraduate project in a Security course, I and some friends implemented DES encryption algorithm. I don’t remember much but what I do remember is :
    – We were Group Number 4 😀
    – We tried to optimize it as much as possible to be fast , degrading the code readability and actually our algorithm was the fastest among the class.
    – Compile it in Release mode

    Code on github

  • OCRA : OCR for Arabic Cursive Text is now open source !

    Hi,
    I was working on a MATLAB implementation for Arabic OCR on graduate course project and I decided to release it as as open source software under GPL license.

    Disclaimer

    This implementation was a part of a graduate course project and actually it achieves very poor results, you can’t rely on it for any real OCR but it will be useful as a starting point to learn from and build on.

    Details

    You can learn all about it here : My github repo

  • al-haitham is open source

    I have benefited a lot from the open source community and it’s time to give back, I uploaded the source code of my graduation project which proposes a real time computer vision system  implemented on FPGA to translate human gestures into computer commands 

     First I would like to thank my graduation project team members:

       Ahmed Hafez Khalil

       Asmaa Omar

       Amani Mohamed Sedek

       Mohamed Ismail Khalil

       Mohamed Kamal Ali

       Mohamed Maged Abdel Majed

     

    and here are the links to my grad project github repos: 

    Hardware repo : https://github.com/aabdelfattah/alhaitham-hardware

    Software repo : https://github.com/aabdelfattah/alhaitham-software

    Have a look at thd brochure I designed for the EED competition 2012 which we won its 1st place 🙂

    project-brochure-1

  • Cross-compiling a Pie ! The Raspberry Pi Ultimate Guide

    Hi,

    During the last few weeks I was interested in cross-compiling for the RPi. I have gone through many tutorials and blog posts to get the task done , so I tried to compile as many information as I can in this guide as a future reference and to help everybody else [The post is long, use CTRL+F for navigation].

    Topics:

    1. Getting started , setting up the cross-compilation toolchain.
    2. Hello World! Building an RPi C application using shell.
    3. Hello World 2! Building an RPi C application using eclipse.
    4. Remote debugging the RPi with gdb on eclipse + RSE plugin.
    5. Updating your kernel. RPi Kernel cross-compilation.
    6. Extra: How does the bootloader work ?? 

     

    Let’s get started with cross-compiling a Pie , there are usually 2 configurations : 

    • either to build the tool chain yourself on your host machine;
    • or to get a pre-compiled toolchain (the Canadian cross).

    pi12

    pi13

    [images from free-electrons embedded training slides]

     

    For this guide I will be using pre-built linaro toolchain(the second way),still I encourage you to try to build the toolchain yourself  for the sake of knowledge using one of those excellent tutorials :  A and B

    Now, let’s download the Linaro gcc toolchain [source]


    $ sudo apt-get install git rsync cmake ia32-libs

    $ mkdir raspberrypi

    $ cd raspberrypi

    $ git clone git://github.com/raspberrypi/tools.git

    Add the cross-compile to your $PATH

    $ export PATH=$PATH:$HOME/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin

    And finally append the very same line to the end of your ~/.bashrc file to make the change permnant

    That’s it, now try

    $ arm-linux-gnueabihf-gcc -v 

    should give you something like this

    Using built-in specs.
    COLLECT_GCC=arm-linux-gnueabihf-gcc
    COLLECT_LTO_WRAPPER=/home/ahmed/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../libexec/gcc/arm-linux-gnueabihf/4.8.3/lto-wrapper
    Target: arm-linux-gnueabihf
    Configured with: /cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/src/gcc-linaro-4.8-2014.01/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu --target=arm-linux-gnueabihf --prefix=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install --with-sysroot=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-languages=c,c++,fortran --disable-multilib --enable-multiarch --with-arch=armv6 --with-tune=arm1176jz-s --with-fpu=vfp --with-float=hard --with-pkgversion='crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11' --with-bugurl=https://bugs.launchpad.net/gcc-linaro --enable-__cxa_atexit --enable-libmudflap --enable-libgomp --enable-libssp --with-gmp=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpfr=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-mpc=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-isl=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-cloog=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --with-libelf=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/.build/arm-linux-gnueabihf/build/static --enable-threads=posix --disable-libstdcxx-pch --enable-linker-build-id --enable-plugin --enable-gold --with-local-prefix=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-raspbian-linux/install/arm-linux-gnueabihf/libc --enable-c99 --enable-long-long --with-float=hard
    Thread model: posix
    gcc version 4.8.3 20140106 (prerelease) (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11)

    Now let’s build a simple application , use your favorite editor to write helloworld.c

    #include <stdio.h>
    int main()
    {
       printf("Hello world \n");
       return 0;
    }

    and compile it using the usual gcc way

    $ arm-linux-gnueabihf-gcc -o helloworld helloworld.c

    Copy this to your Pi with a USB flash memory or on the sd card or whatever suits you, launch it and it should work !

    pi@raspberrypi:~$ ./helloworld

    Hello world

    pi@raspberrypi:~$

    Now, Let’s add our toolchain to eclipse : 

    •  install C/C++ cross-compiler support plugin;

    pi14

    • from the menu File >> New Project >> C-Project >> Cross-Compile project , input the name of your project and hit next;
    • enter arm-linux-gnueabihf- as Tool command prefix and ~/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin as the tool command path , hit next and finish;

    pi16

    • Congratulations 🙂 !!

    It’s important to be able to debug your code online on the RPi, so we are going to use a nice plugin called RSE to do this [source]:

    You may use this source code HelloDebug.c if you wish:

    #include <stdio.h>
    
    int main()
    {
    	int i = 0;
    	printf("Hello world \n");
    	while (i < 1000)
    	{
    		printf("%d \n",i);
    		i++;
    	}
    	return 0;
    
    }
    • install the RSE plugin;

    pi15

    • create a new project with the above source, build it in debug mode (not release);
    • add a new connection to your RPi from the Remote Systems window (if you can’t see it , add it from Window >> Show View >> Others >> Remote Systems) , then hit the tiny button to add an ssh connection to your pi;

    pi19

    • copy the elf executable to the pi using RSE (right click to copy it and paste it on the dir you wish from the stfp menu);

    pi20

    • make sure to chmod+x the execultable;
    • now we will add a new debug configuration , right click on the project and select Debug as >> Debug Configurations  and add a new C/C++ Remote Application configuration;
    • pi17
    • ensure that in Debugger >> Main tab the debugger is arm-linux-gnueabihf-gdb
    • login to your pi using ssh to launch the gdbserver $sudo gdbserver your-linux-pc-ip:any-free-port  HelloDebug

    pi18

    • back to eclipse , ensure that you have the right connection parameters in Debugger >> Connection tab where you should pick the RPi IP and the port number you previously picked.
    • That’s it !! click Debug and enjoy debugging 🙂

    pi11

    Now , there is an excellent tutorial for compiling the kernel [this is not my work,  I am just copying it here for future reference because it’s short and to the point ]also elinux wiki has a good compilation:

    Create our working directory:

    $ mkdir -p raspberrypi/kernel
    $ cd raspberrypi/kernel

    Before starting our work, install the necessary tools and source code of Raspberry Pi linux:

    $ git clone https://github.com/raspberrypi/tools.git
    $ git clone https://github.com/raspberrypi/linux.git

    Prepare the .config file from pre-packaged config, bcmrpi_cutdown_defconfig:

    $ cd linux
    $ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- bcmrpi_cutdown_defconfig

    Build kernel:

    $ make ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi-
    $ mkdir ../modules
    $ make modules_install ARCH=arm CROSS_COMPILE=/usr/bin/arm-linux-gnueabi- INSTALL_MOD_PATH=../modules/
    $ cd ../tools/mkimage/
    $ ./imagetool-uncompressed.py ../../linux/arch/arm/boot/Image

    Now insert a Raspbian installed SD Card, and run the command:

    $ sudo rm /media/<boot-partition>/kernel.img
    $ sudo mv kernel.img /media/<boot-partition>/
    $ sudo rm -rf /media/<rootfs-partition>/lib/modules/
    $ sudo rm -rf /media/<rootfs-partition>/lib/firmware/
    $ cd ../../modules/
    $ sudo cp -a lib/modules/ /media/<rootfs-partition>/lib/
    $ sudo cp -a lib/firmware/ /media/<rootfs-partition>/lib/
    $ sync

    Now you can remove the SD Card and use it to boot Raspberry Pi with the new kernel.

    pi8

    Finally , here is a nice answer on stackexchange about How the Pi boots and another nice reference :

    1. When the Raspberry Pi is first turned on, the ARM core is off, and the GPU core is on. At this point the SDRAM is disabled.
    2. The GPU starts executing the first stage bootloader, which is stored in ROM on the SoC. The first stage bootloader reads the SD card, and loads the second stage bootloader (bootcode.bin) into the L2 cache, and runs it.
    3. bootcode.bin enables SDRAM, and reads the third stage bootloader (loader.bin) from the SD card into RAM, and runs it.
    4. loader.bin reads the GPU firmware (start.elf).
    5. start.elf reads config.txtcmdline.txt and kernel.img

    loader.bin doesn’t do much. It can handle .elf files, and so is needed to load start.elf at the top of memory (ARM uses SDRAM from address zero). There is a plan to add elf loading support to bootcode.bin, which would make loader.bin unnecessary, but it’s a low priority (I guess it might save you 100ms on boot).