Apply Newlib Patch to RTEMS Source Builder

Create a patch for Newlib and test it for RSB (RTEMS Source Builder)

Vaibhav Gupta
Jun 24 · 5 min read

What is Newlib?

Newlib is a C standard library implementation intended for use on embedded systems. It is a conglomeration of several library parts, all under free software licenses that make them easily usable on embedded products.

It was created by Cygnus Support as part of building the first GNU cross-development tool-chains. It is now maintained by Red Hat developers and is used in most commercial and non-commercial GCC ports for non-Linux embedded systems.

Wikipedia contributors. (2019, April 12). Newlib. In Wikipedia, The Free Encyclopedia. Retrieved 19:23, June 26, 2019, from https://en.wikipedia.org/w/index.php?title=Newlib&oldid=892195321

Patches

Hello Readers,

For my GSoC project, I need to port some codes in Newlib. It can be cloned from its git repository.

$ git clone git://sourceware.org/git/newlib-cygwin.git

After creating patches, I need to submit them to Newlib mailing list for review. But before I must make sure that the changes are successfully working.

As Newlib is used by RTEMS as its C Library, one way is to use the patch in RTEMS and design a testsuite for it. If tests are successful, the changes are fine.

Project-Sandboxing of my project (for reference)

As I will be explaining the steps using my system.

Step 1 : Create the patch of your changes.

Screenshot of my Terminal

(Note: For RSB, before creating Newlib patch, you must run autoreconf in the required directory after you make changes to the code.)

(This is not required when you create patch to send to ‘newlib-devel’. Because they need only your code, and not other generated files. But if you want RSB to address your changes, your patch should also include regenerated files. )

Step 2 : Place the patch into the RSB directory.

Run the following command.

$ cd <rtems-source-directory>/rsb/rtems/patches .

(replace <rtems-source-directory> with the path to the directory where you have setup RTEMS for development).

$ cp <newlib-source-directory>/0001-Port-ndbm.patch ./

(replace <newlib-source-directory> with the path to the directory where you have setup newlib for development).

Screenshot of my Terminal

Step 3 : Calculate sha512 of the patch

Run the following command.

$ sha512sum 0001-Port-ndbm.patch

Keep the hash value. We will need it later in Step 6.

Screenshot of my Terminal

Step 4 : Check the .bset file used by your BSP.

Run following commands:

$ cd <rtems-source-directory>/rsb/rtems/config/5

(replace <rtems-source-directory> with the path to the directory where you have setup RTEMS for development).

$ ls

For example, I will be building RTEMS for erc32 (a member of SPARC). Hence the it will be using rtems-sparc.bset .

Screenshot of my Terminal

Step 5 : Check the configuration file used by your .bset file.

For my rtems-sparc.bset , I will open the file using Vim.

$ vim -M rtems-sparc.best

Screenshot of my Terminal

I found that this file is including another file, rtems-default.bset .

$ vim -M rtems-default.bset .

Screenshot of my Terminal

Hence, my BSP is using rtems-gcc-7.4.0-newlib-1d35a003f.cfg to configure Newlib.

Step 6 : Edit the configuration file, used by your .bset file.

Locate the .cfg file.

$ cd <rtems-source-directory>/rsb/config/tools

(replace <rtems-source-directory> with the path to the directory where you have setup RTEMS for development).

Screenshot of my Terminal

We need to tell RSB about patches for building new tool-chain.

$ vim rtems-gcc-7.4.0-newlib-1d35a003f.cfg

Add the following lines:

  1. patch add <group-name-for-patches> <patch-location>: You can encapsulate multiple patches into a single group. Hence provide a group name for patches. In my example, I used newlib_ndbm .
  2. hash sha512 : Patches require a checksum to avoid a warning. The %hash directive can be used to add a checksum for a patch that is used to verify the patch. Use the hash value we calculated in Step 3.
  3. The patches are applied when a patch setup command is issued. All patches in the group are applied.

Reference: https://docs.rtems.org/branches/master/user/rsb/project-sets.html#patches

For example : The lines will look something like this for my newlib patch:

%patch add newlib -p1 file://0001-port-ndbm.patch
%hash sha512 0001-port-ndbm.patch 0130e688c70255053c929e04dba7df16388effaeef83e19adb0109c5e4c1f9c8135bc41acfba03439d7245a548de500d04ae66aaf7d1cdd6b883687b6f3739e3

Note: Write the newlib patch commands, along with other newlib commands. And put the group name as ‘newlib’. Then you will not need to mention %patch setup.... line. Your newlib patch will be applied with other newlib patches.

Screenshot of my Terminal (Here sha512 is different than shown in above examples as it is the screenshot of another patch)

Step 7 : Build new Tool-chain

Run the configure command. For example I had to run:

$ cd /home/varodek/development/rtems/rsb/rtems$ ../source-builder/sb-set-builder --prefix=/home/varodek/development/rtems/5 5/rtems-sparc

(If you are thinking why I went to rsb/rtems directory and then used ../source-builder…… ? Why did not I directly went to rsb/source-builder directly?

Then you need to read this article - Build RTEMS for SPARC Architecture on Linux Host. Read sub-heading “Setup RSB”).



Let’s get connected

For any queries, ping me on LinkedIn or Facebook.


Follow this Publication for more stories on this subject. If you find this blog helpful, please click the 👏 button and share to help others find it! Feel free to leave a comment 💬 below :).

My GSoC 2019 Journey

Open Source is an entirely different world. I see GSoC as a major step to become a part of it. Through this publication I will be sharing my GSoC journey to help other students who are aspiring for same. I operate under my pseudonym “VARoDeK”.

Vaibhav Gupta

Written by

He is a Curious Learner | Mentor | Teacher | Programmer | Developer | OS/Kernel Enthusiast | Avid-Reader | Blogger | Archer | Painter | Sketch-Artist.

My GSoC 2019 Journey

Open Source is an entirely different world. I see GSoC as a major step to become a part of it. Through this publication I will be sharing my GSoC journey to help other students who are aspiring for same. I operate under my pseudonym “VARoDeK”.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade