Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/gnu-toolchain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: GNU Toolchain CI
Comment thread
manojKoppolu marked this conversation as resolved.

on:
push:
branches: [ main, master ]
pull_request:
branches: [ "**" ]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read

jobs:
build:
name: Build and Validate
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Show tool versions
run: |
make --version

- name: Restore toolchain cache
uses: actions/cache@v4
with:
path: |
$HOME/gnupru
key: toolchain-gnupru-2025.05.sha

- name: Install GNU toolchain if missing
run: |
set -e
mkdir -p "$HOME/gnupru/downloads"
cd "$HOME/gnupru"

# Install gnupru-2025.05
if [ ! -d "$HOME/gnupru/pru-elf-2025.05" ]; then
cd "$HOME/gnupru/downloads"
wget -q --retry-connrefused --waitretry=1 --tries=5 --timeout=30 \
https://github.com/dinuxbg/gnupru/releases/download/2025.05/pru-elf-2025.05.amd64.tar.xz
echo "23d4a8e8a64400ab73565be5575bc6ea5a3c1f5c06858a03b441e1549427380256ce7b22c3131f7b09d45e941ef133c5d51da38331cfaa338f6b601f21065a3e pru-elf-2025.05.amd64.tar.xz" > pru-elf-2025.05.amd64.sum
sha512sum -c pru-elf-2025.05.amd64.sum
cd "$HOME/gnupru"
tar xaf "$HOME/gnupru/downloads/pru-elf-2025.05.amd64.tar.xz"
mv pru-elf pru-elf-2025.05
fi

test -x "$HOME/gnupru/pru-elf-2025.05/bin/pru-gcc"

- name: Export toolchain environment
run: |
{
echo "PATH=$PATH:$HOME/gnupru/pru-elf-2025.05/bin"
} >> $GITHUB_ENV

- name: Build examples folder
run: |
make -C examples/gcc_rpmsg_echo_linux -j$(nproc)
make -C examples/gcc_rpmsg_echo_linux -j$(nproc) MCU_DEVICE=am62x.pru1
1 change: 1 addition & 0 deletions examples/gcc_rpmsg_echo_linux/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
generated
105 changes: 105 additions & 0 deletions examples/gcc_rpmsg_echo_linux/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Copyright (c) 2026, Dimitar Dimitrov
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# * Neither the name of the copyright holders nor the names of
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# Very simple makefile to cross-compile for PRU using the GNU toolchain.

# Select which PRU core to compile for
MCU_DEVICE ?= am62x.pru0

# Common flags
CROSS_COMPILE ?= pru-
CFLAGS += -Oz
CFLAGS += -Wall -Wextra

# Enable the GCC static analyzer.
CFLAGS += -fanalyzer

# Headers needed by the TI rpmsg library.
HEADER_DIRS := \
./ \
../../source/include/linux


CFLAGS += $(foreach directory, $(HEADER_DIRS), -I$(directory))

# Define this to squeeze code size by removing atexit, exit, constructors
# and destructors from CRT.
CFLAGS += -minrt

# Per-PRU core flags. The -mmcu option will select the correct linker
# script and will predefine mcu-specific macros.
CFLAGS += -mmcu=${MCU_DEVICE}

# List of source files to compile for each PRU core.
SRC := \
main.c \
../../source/rpmsg/pru_rpmsg.c \
../../source/rpmsg/pru_virtqueue.c

# GCC's -MMD does not yield the needed C dependencies when compiling all
# C source files at once. So manually list headers here.
HEADERS := $(foreach directory, $(HEADER_DIRS), $(wildcard $(directory)/*.h))

# Where to output compiled objects
OUT := generated

# Final ELF image file names
ELF := $(OUT)/gcc_rpmsg_echo_linux_am62x-sk_${MCU_DEVICE}.elf

# ============================ DO NOT TOUCH BELOW ============================
all: $(ELF)
@echo Success: $^

%.s : %.elf
$(CROSS_COMPILE)objdump -S -d $< > $@

# Binary images for IMEM and DMEM memories. Might be useful
# for firmware loaders that cannot handle ELF.
%.imem.bin : %.elf
$(CROSS_COMPILE)objcopy -O binary --only-section=.text* $< $@

%.dmem.bin : %.elf
$(CROSS_COMPILE)objcopy -O binary \
--only-section=.data* \
--only-section=.bss* \
--set-section-flags .bss=alloc,load,contents \
$< $@

$(OUT):
mkdir $(OUT)

$(ELF): $(SRC) $(HEADERS) | $(OUT)
$(CROSS_COMPILE)gcc $(CFLAGS) $(SRC) -o $@

clean:
$(RM) -fr $(ELF) $(OUT)

cscope:
cscope -bRk

.PHONY: all clean cscope
56 changes: 56 additions & 0 deletions examples/gcc_rpmsg_echo_linux/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# RPMSG Echo Example Using the GNU Toolchain

This is an RPMSG firmware built using the GNU toolchain for PRU. This firmware
is the classical RPMSG echo example from Texas Instruments, but with a twist
to show-off some GCC features. The returned echo string is reversed using
inline assembly routine.

WARNING: Neither the GNU PRU toolchain nor this example are supported by Texas Instruments!

The example was last tested on BeaglePlay board running kernel 6.12.57-ti-arm64-r59.

## Getting the GNU toolchain for PRU

Convenient prebuilt toolchain binaries are offered [here](https://github.com/dinuxbg/gnupru/releases).
They are prepared by the same hobbyist, who also maintains the PRU port for GCC and Binutils.
This toolchain includes:
* [GCC](https://gcc.gnu.org/) compiler.
* [Binutils](https://www.gnu.org/software/binutils/) assembler, linker and tools.
* [newlib](https://sourceware.org/newlib/) C library.

Being free software, the GNU toolchain can also be built from sources.
PRU support has been mainlined, and is part of recent official source releases
for GCC, Binutils and newlib. Apart from official GNU sources, you need only a
[small additional package](https://github.com/dinuxbg/gnuprumcu) for
SoC-specific support in order to
[build the toolchain](https://github.com/dinuxbg/gnupru/?tab=readme-ov-file#building-from-sources) by yourself.

## Compiling the example

```
cd examples/gcc_rpmsg_echo_linux
make MCU_DEVICE=am62x.pru0
```

Or, if compiling for the other PRU core:

```
make MCU_DEVICE=am62x.pru1
```

Steps for running the firmware are the same as for the TI CGT example.

## Reasons to consider using the GNU toolchain for PRU

* The GNU toolchain is free software.
* GCC supports the [latest language](https://gcc.gnu.org/onlinedocs/gcc/Standards.html#C-Language)
standards (e.g. C23 and C2Y), and numerous [extensions](https://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html).
* GCC has a really nice [static analyzer](https://developers.redhat.com/articles/2025/04/10/6-usability-improvements-gcc-15#4__an_easier_transition_to_c23).
* GCC has a powerful [extension](https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html)
for writing snippets of inline assembly inside C functions.

## Support

For community support you can:
* File an issue in https://github.com/dinuxbg/gnupru
* Ask a question in https://forum.beagleboard.org
34 changes: 34 additions & 0 deletions examples/gcc_rpmsg_echo_linux/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

/* These constants are excellently explained in examples/rpmsg_echo_linux/readme.md.
*
* Show-off here the GCC's "-mmcu=" option, which among other things
* automatically defines PRU-instance-specific macros (e.g. __AM62X_PRU0__).
* Thus instead of manually changing these constants in the Makefile
Comment thread
pratheesh-ti marked this conversation as resolved.
* as in the TI CGT example, we can simply define them in this header.
* An ifdef block is used for each supported PRU core instance.
*
*
* For a list of supported PRU core instances (a.k.a. MCUs), see
* https://github.com/dinuxbg/gnuprumcu/blob/master/MCU-LIST.md
*
* For list of defined macros, simply open the correspondingly named
* spec file from the above project. Example:
* https://github.com/dinuxbg/gnuprumcu/blob/master/device-specs/am62x.pru0
*/
Comment thread
nsaulnier-ti marked this conversation as resolved.
#if defined(__AM62X_PRU0__)
#define HOST_INT_BIT 30
#define TO_ARM_HOST 16
#define FROM_ARM_HOST 17
#define CHAN_PORT 30
#define INTMAP_CHANNEL 0
#define INTMAP_HOST 0
#elif defined(__AM62X_PRU1__)
#define HOST_INT_BIT 31
#define TO_ARM_HOST 18
#define FROM_ARM_HOST 19
#define CHAN_PORT 31
#define INTMAP_CHANNEL 1
#define INTMAP_HOST 1
#else
#error "Please define the RPMSG channel properties for your specific PRU instance."
#endif
47 changes: 47 additions & 0 deletions examples/gcc_rpmsg_echo_linux/intc_map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#ifndef _INTC_MAP_H_
#define _INTC_MAP_H_

/*
* ======== PRU INTC Map ========
*
* Define the INTC mapping for interrupts going to the ICSS / ICSSG:
* ICSS Host interrupts 0, 1
* ICSSG Host interrupts 0, 1, 10-19
*
* Note that INTC interrupts going to the ARM Linux host should not be defined
* in this file (ICSS/ICSSG Host interrupts 2-9).
*
* The INTC configuration for interrupts going to the ARM host should be defined
* in the device tree node of the client driver, "interrupts" property.
* See Documentation/devicetree/bindings/interrupt-controller/ti,pruss-intc.yaml
* entry #interrupt-cells for more.
*
* For example, on ICSSG:
*
* &client_driver0 {
* interrupt-parent = <&icssg0_intc>;
* interrupts = <21 2 2>, <22 3 3>;
* interrupt-names = "interrupt_name1", "interrupt_name2";
* };
*/

#include <stddef.h>
#include <rsc_types.h>
#include "config.h"

/*
* .pru_irq_map is used by the RemoteProc driver during initialization. However,
* the map is NOT used by the PRU firmware. The GNU linker's default script for PRU
* knows about the ".pru_irq_map", and will retain it.
*/

struct pru_irq_rsc my_irq_rsc
__attribute__((section(".pru_irq_map"),unavailable("pru_irq_map is for usage by the host only"))) = {
0, /* type = 0 */
1, /* number of system events being mapped */
{
{FROM_ARM_HOST, INTMAP_CHANNEL, INTMAP_HOST}, /* {sysevt, channel, host interrupt} */
},
};
Comment thread
manojKoppolu marked this conversation as resolved.

#endif /* _INTC_MAP_H_ */
Loading
Loading