Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
augustofg committed Jul 19, 2023
2 parents a631724 + d85e5f8 commit 3b7ae35
Show file tree
Hide file tree
Showing 132 changed files with 28,576 additions and 2,180 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build for all targets
on:
push:
branches:
- master
- devel
pull_request:

jobs:
build:
runs-on: ubuntu-latest
container:
image: ghcr.io/lnls-dig/openmmc-builder:latest
strategy:
matrix:
build-flags:
- { flags: -DBOARD=afc-bpm -DVERSION=3.1 }
- { flags: -DBOARD=afc-timing -DBOARD_RTM=8sfp }
- { flags: -DBOARD=afc-v4 }
- { flags: -DBOARD=afc-v4 -DDEBUG_PROBE=jlink -DOPENOCD_TRANSPORT=swd }
- { flags: -DBOARD=afc-v4 -DDEBUG_PROBE=cmsis-dap -DOPENOCD_TRANSPORT=swd }
- { flags: -DBOARD=afc-v4 -DDEBUG_PROBE=digilent_jtag_hs3 -DOPENOCD_TRANSPORT=jtag }
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: Create build environment
run: mkdir build
- name: Configure CMake
working-directory: build
run: cmake .. -DCMAKE_BUILD_TYPE=RELWITHDEBINFO ${{matrix.build-flags.flags}}
- name: Build for all targets
working-directory: build
run: make
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ CMakeFiles/
Makefile
*cmake_install.cmake
CMakeCache.txt
build/

#Output files
out/*
Expand Down
71 changes: 0 additions & 71 deletions .travis.yml

This file was deleted.

56 changes: 23 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Define minimal required version of CMake.
cmake_minimum_required(VERSION 2.8.8)
cmake_minimum_required(VERSION 3.0.0)

option(DISABLE_WATCHDOG "Disable watchdog module to aid debugging" OFF)

#Include text color definitions
include( ${CMAKE_SOURCE_DIR}/toolchain/colors.cmake )
Expand All @@ -18,7 +20,7 @@ project(openMMC C CXX ASM)

#Find a toolchain file
if(NOT CMAKE_TOOLCHAIN_FILE)
message(WARNING "${Yellow}No toolchain configuration file specified. Using default option!${ColourReset}")
message(NOTICE "No toolchain configuration file specified. Using default option!")

include(${CMAKE_SOURCE_DIR}/toolchain/toolchain-arm-none-eabi.cmake)
endif()
Expand Down Expand Up @@ -57,22 +59,17 @@ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING "")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}" CACHE STRING "")

set(PROJ_HDRS ${CMAKE_SOURCE_DIR} )
set(UCONTROLLER_APP_LD_SCRIPT "")

add_subdirectory(port/board)
add_subdirectory(port/ucontroller)
add_subdirectory(FreeRTOS)
add_subdirectory(boot)
add_subdirectory(modules)

include_directories( ${UCONTROLLER_HDRS} ${PROJ_HDRS} )

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DTARGET_CONTROLLER=${TARGET_CONTROLLER} -DTARGET_BOARD_NAME=\"${TARGET_BOARD_NAME}\" ")

if(BENCH_TEST)
set(MODULES_FLAGS "${MODULES_FLAGS} -DBENCH_TEST")
message( STATUS "${Magenta}Bench mode activated! ${ColourReset}")
endif()

# Get Git information
git_describe(GIT_TAG "--tags")
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
Expand All @@ -92,44 +89,37 @@ else()
message(FATAL_ERROR "${BOARD} not supported!")
endif()



# Linker flags
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
SUFFIX ".axf"
LINK_FLAGS "-T ${CMAKE_SOURCE_DIR}/linker/${TARGET_CONTROLLER}_app.ld -Wl,-Map=${CMAKE_SOURCE_DIR}/linker/${TARGET_CONTROLLER}_app.map" )
SUFFIX ".elf"
LINK_FLAGS "-T ${UCONTROLLER_APP_LD_SCRIPT} -Wl,-Map=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${TARGET_CONTROLLER}_app.map"
)

# Headers path
target_include_directories(${CMAKE_PROJECT_NAME} PUBLIC ${PROJ_HDRS})
# Link libraries
target_link_libraries(${CMAKE_PROJECT_NAME} FreeRTOS c gcc m ${PROJ_LIBS})


target_link_libraries(${CMAKE_PROJECT_NAME} FreeRTOS gcc c ${PROJ_LIBS})

##Generate binary file
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_PROJECT_NAME}.axf ${CMAKE_PROJECT_NAME}.bin
COMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_PROJECT_NAME}.elf ${CMAKE_PROJECT_NAME}.bin
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMENT "Converting the AXF output to a binary file"
COMMENT "Converting the ELF output to a binary file"
)

#generate bootloader files only for afc cards
if(${BOARD} MATCHES "^(afc)")
add_executable(bootloader ${BOOT_SRCS})
set_target_properties(bootloader PROPERTIES
SUFFIX ".axf"
LINK_FLAGS "-T ${CMAKE_SOURCE_DIR}/linker/${TARGET_CONTROLLER}_boot.ld -Wl,-Map=${CMAKE_SOURCE_DIR}/linker/${TARGET_CONTROLLER}_boot.map")
# Headers path
target_include_directories(bootloader PUBLIC ${PROJ_HDRS})
# Link libraries
target_link_libraries(bootloader gcc c m lpcopen)

add_custom_command(TARGET bootloader POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -O binary bootloader.axf bootloader.bin
##Generate hpm files if bin2hpm is installed

find_program(BIN2HPM NAMES "bin2hpm")
if(BIN2HPM)
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND bin2hpm -c 1 -n -m 0x315A -p 0x00 ${CMAKE_PROJECT_NAME}.bin -o ${CMAKE_PROJECT_NAME}.hpm
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMENT "Converting the AXF output to a binary file"
)
COMMENT "Creating HPM file from binary"
)
message(STATUS "bin2hpm found in the $PATH, .hpm files will be generated automatically.")
else()
message(NOTICE "bin2hpm not found in the $PATH, .hpm files will not be generated.")
endif()

include( ${CMAKE_SOURCE_DIR}/probe/lpclink.cmake )
include( ${CMAKE_SOURCE_DIR}/probe/openocd.cmake )
1 change: 1 addition & 0 deletions FreeRTOS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set(LIBFREERTOS_SRCS ${LIBFREERTOS_SRCS}
timers.c
tasks.c
event_groups.c
openocd.c
)

include_directories(${UCONTROLLER_HDRS})
Expand Down
20 changes: 20 additions & 0 deletions FreeRTOS/openocd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Since at least FreeRTOS V7.5.3 uxTopUsedPriority is no longer
* present in the kernel, so it has to be supplied by other means for
* OpenOCD's threads awareness.
*
* Add this file to your project, and, if you're using --gc-sections,
* ``--undefined=uxTopUsedPriority'' (or
* ``-Wl,--undefined=uxTopUsedPriority'' when using gcc for final
* linking) to your LDFLAGS; same with all the other symbols you need.
*/

#include "FreeRTOS.h"

#ifdef __GNUC__
#define USED __attribute__((used))
#else
#define USED
#endif

volatile const int USED uxTopUsedPriority = configMAX_PRIORITIES - 1;
77 changes: 57 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# openMMC

[![Travis build status](https://travis-ci.org/lnls-dig/openMMC.svg?branch=master)](https://travis-ci.org/lnls-dig/openMMC)
[![Continuous Integration Status](https://github.com/lnls-dig/openMMC/actions/workflows/build.yml/badge.svg)](https://github.com/lnls-dig/openMMC/actions)

Open Source modular IPM Controller firmware

Expand Down Expand Up @@ -39,45 +39,82 @@ After creating the build files with CMake, you can compile the firmware using `m

make [VERBOSE=1]

Both a `.axf` file and a `.bin` file will be generated in the `out` folder. You can use any one you prefer to program your processor.
Both a `.elf` file and a `.bin` file will be generated in the `out` folder. You can use any one you prefer to program your processor.

To clean the compilation files (binaries, objects and dependence files), just run

make clean

To make a debug build (to include symbols into axf file, turn off optimizations, etc.) add `-DCMAKE_BUILD_TYPE=Debug` option to `cmake` command. Example:
To make a debug build (to include symbols into elf file, turn off optimizations, etc.) add `-DCMAKE_BUILD_TYPE=Debug` option to `cmake` command. Example:

cmake ~/openmmc/ -DBOARD=afc -DVERSION=3.1 -DCMAKE_BUILD_TYPE=Debug

## Programming
After creating the binaries, you can program them to your chip any way you want, using a JTAG cable, ISP Programmer, custom bootloader, etc.
There are 2 program interfaces supported so far: *LPCLink* and *LPCLink2*
In order to select which interface will be used, include the flag `-DDEBUG_PROBE=<probe_name>` when running CMake (this option defaults to `LPCLink`).

cmake ~/openmmc/ -DBOARD=afc -DVERSION=3.1 -DDEBUG_PROBE=LPCLink2
### OpenOCD
Flashing the MMC microcontroller via SWD/JTAG is supported for CMSIS-DAP and Jlink compatible probes through OpenOCD. You can specify the debug probe with the flag `-DDEBUG_PROBE=<probe_name>`, valid options are `cmsis-dap` (default) and `jlink`.

cmake ~/openmmc/ -DBOARD=afc -DVERSION=3.1 -DDEBUG_PROBE=cmsis-dap

### LPCLink
If you own a *LPCLink* or *LPCLink2* board, you can use it to program the LPC1764 processor via its JTAG interface
This will create a `openocd.cfg` file in `<build_dir>/out`.

**NOTE**: In this case you **must** have the LPCXpresso installed in your machine, since we need to use the binaries for the interface chip on the LPCLink that they provide.
To flash the application firmware only, run

The CMake script should be able to find LPCXpresso path, but if this is not possible, open the `<openMMC_root_folder>/CMakeLists.txt` and change the following line
make program_app

set(LPCXPRESSO_PATH <lpcxpresso_path>)
To flash the bootloader firmware only, run

*NOTE*: You can also use cmake-gui to set this option.
make program_boot

To transfer only the application firmware, run
If you want to erase the whole Flash and flash both firmwares:

make program_app
make program_all

To transfer only the bootloader firmware, run
### LPC-Link1
It is possible to flash the MMC microcontroller with the LPC-Link1 adapter by using the `probe/lpclink1-flash.sh` script. You will need to have MCUXpresso IDE installed in your computer. This script assumes that the MCUXpresso binaries are located in `/usr/local/mcuxpressoide/ide/binaries/` by default, you can change this path by setting the `MCUXPRESSOIDE_BIN` environment variable.

make program_boot
./probe/lpclink1-flash.sh firmware.bin LPC1764 0x0000

If you want to erase the whole Flash and copy both firmwares:
### HPM-Downloader
> :warning: **Disclaimer:** Due to [f06f69f](https://github.com/lnls-dig/openMMC/commit/f06f69f978c11bb8e1a2b12e4846e4bd51f757e4), this alternative is deprecated and ipmitool should be used instead, except when updating the OpenMMC application from older versions.
make program_all
Another option to program the MMC microcontroler is through [HPM-Downloader](https://github.com/lnls-dig/hpm-downloader).
First, download and compile the HPM. In it's root directory, in order to load the firmware, run

./bin/hpm-downloader --no-retries --ip <MCH_IP_address> --slot <slots_to_be_updated> --component 1 <path_to_openMMC.bin>

Due to timeout on sending packets, it may fails sometimes, with the Completion Code `0xc3` in the `ACTIVATE_FIRMWARE_UPLOAD` process. If it occurs, just try the same command again, until you receive the `Upgrade success` message.
Now, you have to upload the bootloader, since the old bootloader is incompatible. To succeed this, run

./bin/hpm-downloader --ignore-component-check --ip <MCH_IP_address> --slot <slots_to_be_updated> --component 0 <path_to_newboot.bin>

It's also important to mention that you can use the `--help` command in case of doubt about how to use the HPM commands. Run

./bin/hpm-downloader --help

### ipmitool
After [5631857](https://github.com/lnls-dig/openMMC/commit/563185791c8b51ea026680c98ec0ea9587ea645b), it's possible to program the firmware and the bootloader through [ipmitool](https://codeberg.org/IPMITool/ipmitool), for previous releases, you still need to use [hpm-downloader](https://github.com/lnls-dig/hpm-downloader). In order to use it, you have to install the ipmitool, and then generate .hpm files from `OpenMMC.bin` and `newboot.bin`. To generate `.hpm` files, you will need to use [bin2hpm](https://github.com/MicroTCA-Tech-Lab/bin2hpm). If you have bin2hpm in your `$PATH`, the `.hpm` files will be automatically generated for you, provided you build from [0095b14](https://github.com/lnls-dig/openMMC/commit/0095b14667afe844113725228671d8810b45d9e0) or more recent versions.
After generate the files, you can use the following commands to program the MMC microcontroller.
To upgrade the firmware, use

ipmitool -I lan -H host_name_mch -A none -T 0x82 -m 0x20 -t (112 + num_slot*2 in hexadecimal) hpm upgrade openMMC.hpm activate

To upgrade the bootloader, use

ipmitool -I lan -H host_name_mch -A none -T 0x82 -m 0x20 -t (112 + num_slot*2 in hexadecimal) hpm upgrade newboot.hpm activate

## Debugging
It is possible to debug the MMC firmware using OpenOCD and GDB. First, connect OpenOCD with the debug probe using the `out/openocd.cfg` file generated by cmake in the build directory:

openocd -f out/openocd.cfg

Then open GDB:

$ arm-none-eabi-gdb out/openMMC.elf
(gdb) target remote localhost:3333

Now you can use the typical GDB commands to inspect the program flow and variables. Some useful commands when interacting with a microcontroller trough OpenOCD are listed below:

**NOTE 2**: We only have linker scripts to LPC1764 and LPC1769, so if you wish to compile to a different controller, you'll have to change the `linker/lpc1764_boot.ld` and `linker/lpc1764_app.ld` files, which defines the memory regions, otherwise you'll run into several HardFault errors.
(gdb) monitor reset halt # Resets the microcontroller and immediately halts
(gdb) monitor reset run # Resets the microcontroller and starts executing
(gdb) load # Reload the firmware into flash
9 changes: 0 additions & 9 deletions boot/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 3b7ae35

Please sign in to comment.