Apply Newlib Patch to RTEMS Source Builder
Create a patch for Newlib and test it for RSB (RTEMS Source Builder)
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.
(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).
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.
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
.
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
I found that this file is including another file, rtems-default.bset
.
$ vim -M rtems-default.bset
.
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).
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:
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 usednewlib_ndbm
.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.- 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.
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
Follow/ Connect with me anytime.
- LinkedIn- https://www.linkedin.com/in/varodek/
- GitHub- https://www.github.com/VARoDeK
- Facebook- https://www.facebook.com/vaibhav.gupta.1004837
- Twitter- https://twitter.com/varodek
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 :).