Skip to content

Commit

Permalink
[bazel] Download and patch FreeRTOS using Bazel
Browse files Browse the repository at this point in the history
Signed-off-by: Miguel Young de la Sota <[email protected]>
  • Loading branch information
mcy committed Mar 29, 2022
1 parent 738dc12 commit d36c3e4
Show file tree
Hide file tree
Showing 12 changed files with 1,352 additions and 20 deletions.
4 changes: 4 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,7 @@ git_repository(
patches = ["//sw/vendor/patches/mundane:build_with_bazel.patch"],
remote = "https://fuchsia.googlesource.com/mundane",
)

load("//third_party/freertos:deps.bzl", "freertos_deps")

freertos_deps()
26 changes: 14 additions & 12 deletions sw/device/lib/testing/test_framework/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,10 @@ cc_library(

cc_library(
name = "freertos_config",
hdrs = [
"FreeRTOSConfig.h",
],
hdrs = ["FreeRTOSConfig.h"],
# FreeRTOS sources don't follow our project's include-path standard,
# and just include via the bare filename.
includes = ["."],
deps = [
"//sw/device/lib/arch:device",
],
)

cc_library(
Expand All @@ -62,18 +57,21 @@ cc_library(
"freertos_port.S",
"freertos_port.c",
],
hdrs = [
"ottf_macros.h",
],
hdrs = ["ottf_macros.h"],
# FIXME: Temporary hack to allow us to #include the version in //third_party.
# To be removed once Meson is removed.
# https://github.com/lowRISC/opentitan/issues/11743
local_defines = ["FREERTOS_IS_BAZEL"],
deps = [
":check",
":freertos_config",
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
"//sw/device/lib:irq",
"//sw/device/lib/dif:rv_timer",
"//sw/device/lib/dif:uart",
"//sw/device/lib/runtime:hart",
"//sw/device/lib/runtime:log",
"//sw/vendor/freertos_freertos_kernel:kernel",
"//third_party/freertos",
],
)

Expand Down Expand Up @@ -124,9 +122,13 @@ cc_library(
"-Wl,--start-group",
"$(location :freertos_port)",
"$(location //sw/device/lib:irq)",
"$(location //sw/vendor/freertos_freertos_kernel:kernel)",
"$(location //third_party/freertos)",
"-Wl,--end-group",
],
# FIXME: Temporary hack to allow us to #include the version in //third_party.
# To be removed once Meson is removed.
# https://github.com/lowRISC/opentitan/issues/11743
local_defines = ["FREERTOS_IS_BAZEL"],
target_compatible_with = [OPENTITAN_CPU],
deps = [
":freertos_port",
Expand All @@ -136,6 +138,6 @@ cc_library(
"//sw/device/lib/runtime:ibex",
"//sw/device/lib/runtime:log",
"//sw/device/lib/runtime:print",
"//sw/vendor/freertos_freertos_kernel:kernel",
"//third_party/freertos",
],
)
2 changes: 0 additions & 2 deletions sw/device/lib/testing/test_framework/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_FRAMEWORK_FREERTOSCONFIG_H_
#define OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_FRAMEWORK_FREERTOSCONFIG_H_

#include "sw/device/lib/arch/device.h"

// These macros configure FreeRTOS. A description of each macro can be found
// here: https://www.freertos.org/a00110.html

Expand Down
6 changes: 6 additions & 0 deletions sw/device/lib/testing/test_framework/freertos_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
#include "sw/device/lib/irq.h"
#include "sw/device/lib/runtime/hart.h"
#include "sw/device/lib/runtime/log.h"

#ifdef FREERTOS_IS_BAZEL
#include "external/freertos/include/FreeRTOS.h"
#include "external/freertos/include/task.h"
#else
#include "sw/vendor/freertos_freertos_kernel/include/FreeRTOS.h"
#include "sw/vendor/freertos_freertos_kernel/include/task.h"
#endif

// NOTE: the function names below do NOT, and cannot, conform to the style
// guide, since they are specific implementations of FreeRTOS defined functions.
Expand Down
13 changes: 10 additions & 3 deletions sw/device/lib/testing/test_framework/freertos_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
#include "sw/device/lib/runtime/log.h"
#include "sw/device/lib/testing/check.h"
#include "sw/device/lib/testing/test_framework/FreeRTOSConfig.h"
#include "sw/vendor/freertos_freertos_kernel/include/FreeRTOS.h"
#include "sw/vendor/freertos_freertos_kernel/include/task.h"
#include "sw/vendor/freertos_freertos_kernel/portable/GCC/RISC-V/portmacro.h"

// TODO: make this toplevel agnostic.
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h" // Generated.

#ifdef FREERTOS_IS_BAZEL
#include "external/freertos/include/FreeRTOS.h"
#include "external/freertos/include/task.h"
#include "external/freertos/portable/GCC/RISC-V/portmacro.h"
#else
#include "sw/vendor/freertos_freertos_kernel/include/FreeRTOS.h"
#include "sw/vendor/freertos_freertos_kernel/include/task.h"
#include "sw/vendor/freertos_freertos_kernel/portable/GCC/RISC-V/portmacro.h"
#endif

// NOTE: some of the function names below do NOT, and cannot, conform to the
// style guide, since they are specific implementations of FreeRTOS defined
// functions.
Expand Down
13 changes: 10 additions & 3 deletions sw/device/lib/testing/test_framework/ottf.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@
#include "sw/device/lib/testing/test_framework/FreeRTOSConfig.h"
#include "sw/device/lib/testing/test_framework/test_coverage.h"
#include "sw/device/lib/testing/test_framework/test_status.h"
#include "sw/vendor/freertos_freertos_kernel/include/FreeRTOS.h"
#include "sw/vendor/freertos_freertos_kernel/include/queue.h"
#include "sw/vendor/freertos_freertos_kernel/include/task.h"

// TODO: make this toplevel agnostic.
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"

#ifdef FREERTOS_IS_BAZEL
#include "external/freertos/include/FreeRTOS.h"
#include "external/freertos/include/queue.h"
#include "external/freertos/include/task.h"
#else
#include "sw/vendor/freertos_freertos_kernel/include/FreeRTOS.h"
#include "sw/vendor/freertos_freertos_kernel/include/queue.h"
#include "sw/vendor/freertos_freertos_kernel/include/task.h"
#endif

// Check layout of test configuration struct since OTTF ISR asm code requires a
// specific layout.
OT_ASSERT_MEMBER_OFFSET(test_config_t, enable_concurrency, 0);
Expand Down
46 changes: 46 additions & 0 deletions third_party/freertos/0001-Remove-mtime-address-macros.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
From 3d0a295ce55a3d5180e947d1b552ed91a1e63967 Mon Sep 17 00:00:00 2001
From: Miguel Young de la Sota <[email protected]>
Date: Mon, 28 Mar 2022 10:22:07 -0400
Subject: [PATCH 1/3] Remove mtime address macros

---
portable/GCC/RISC-V/portmacro.h | 23 -----------------------
1 file changed, 23 deletions(-)

diff --git a/portable/GCC/RISC-V/portmacro.h b/portable/GCC/RISC-V/portmacro.h
index fe93dc28c..5522e0bb8 100644
--- a/portable/GCC/RISC-V/portmacro.h
+++ b/portable/GCC/RISC-V/portmacro.h
@@ -156,29 +156,6 @@ not necessary for to use this port. They are defined so the common demo files
#define portMEMORY_BARRIER() __asm volatile( "" ::: "memory" )
/*-----------------------------------------------------------*/

-
-/* configCLINT_BASE_ADDRESS is a legacy definition that was replaced by the
-configMTIME_BASE_ADDRESS and configMTIMECMP_BASE_ADDRESS definitions. For
-backward compatibility derive the newer definitions from the old if the old
-definition is found. */
-#if defined( configCLINT_BASE_ADDRESS ) && !defined( configMTIME_BASE_ADDRESS ) && ( configCLINT_BASE_ADDRESS == 0 )
- /* Legacy case where configCLINT_BASE_ADDRESS was defined as 0 to indicate
- there was no CLINT. Equivalent now is to set the MTIME and MTIMECMP
- addresses to 0. */
- #define configMTIME_BASE_ADDRESS ( 0 )
- #define configMTIMECMP_BASE_ADDRESS ( 0 )
-#elif defined( configCLINT_BASE_ADDRESS ) && !defined( configMTIME_BASE_ADDRESS )
- /* Legacy case where configCLINT_BASE_ADDRESS was set to the base address of
- the CLINT. Equivalent now is to derive the MTIME and MTIMECMP addresses
- from the CLINT address. */
- #define configMTIME_BASE_ADDRESS ( ( configCLINT_BASE_ADDRESS ) + 0xBFF8UL )
- #define configMTIMECMP_BASE_ADDRESS ( ( configCLINT_BASE_ADDRESS ) + 0x4000UL )
-#elif !defined( configMTIME_BASE_ADDRESS ) || !defined( configMTIMECMP_BASE_ADDRESS )
- #error configMTIME_BASE_ADDRESS and configMTIMECMP_BASE_ADDRESS must be defined in FreeRTOSConfig.h. Set them to zero if there is no MTIME (machine time) clock. See https://www.FreeRTOS.org/Using-FreeRTOS-on-RISC-V.html
-#endif
-
-
-
#ifdef __cplusplus
}
#endif
--
2.35.1.1021.g381101b075-goog

Loading

0 comments on commit d36c3e4

Please sign in to comment.