summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2022-10-04 11:59:02 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-10-12 23:43:54 +0000
commit297c648ebcf2e62b1da7e2ad13eee4bad83c9545 (patch)
tree50e996c8db3450214cdcb2de6dfab8b036d86805
parentaebccf721edad727dfa011a48eb12ff75015be79 (diff)
downloadchrome-ec-297c648ebcf2e62b1da7e2ad13eee4bad83c9545.tar.gz
test: move spi_flash_reg to its own module
Move the logic of the spi_flash_reg.c from common/ to a separate directory. Also, move the tests. Update the build.mk system to still build this in the same manner as well as CMake to use it as a library. BRANCH=none BUG=b:246839061 TEST=make BOARD=dooly TEST=zmake build hoglin TEST=./twister -T common Signed-off-by: Yuval Peress <peress@google.com> Change-Id: Icc6b4fce1619c2c6a86c040f30390b7788171a9d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3935025 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Aaron Massey <aaronmassey@google.com> Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r--.gitignore2
-rw-r--r--CMakeLists.txt1
-rw-r--r--Kconfig1
-rw-r--r--common/CMakeLists.txt5
-rw-r--r--common/Kconfig5
-rw-r--r--common/build.mk4
-rw-r--r--common/spi/CMakeLists.txt5
-rw-r--r--common/spi/Kconfig5
-rw-r--r--common/spi/build.mk8
-rw-r--r--common/spi/flash_reg/CMakeLists.txt54
-rw-r--r--common/spi/flash_reg/Kconfig.module12
-rw-r--r--common/spi/flash_reg/build.mk11
-rw-r--r--common/spi/flash_reg/private/common.h (renamed from zephyr/test/spi_flash_reg/include/common.h)0
-rw-r--r--common/spi/flash_reg/private/util.h (renamed from zephyr/test/spi_flash_reg/include/util.h)0
-rw-r--r--common/spi/flash_reg/prj.conf (renamed from zephyr/test/spi_flash_reg/prj.conf)0
-rw-r--r--common/spi/flash_reg/public/spi_flash_reg.h (renamed from include/spi_flash_reg.h)0
-rw-r--r--common/spi/flash_reg/src/spi_flash_reg.c (renamed from common/spi_flash_reg.c)0
-rw-r--r--common/spi/flash_reg/src/spi_flash_reg_test.c (renamed from zephyr/test/spi_flash_reg/src/main.c)0
-rw-r--r--common/spi/flash_reg/testcase.yaml (renamed from zephyr/test/spi_flash_reg/testcase.yaml)0
-rw-r--r--include/common.h2
-rw-r--r--zephyr/CMakeLists.txt10
-rw-r--r--zephyr/Kconfig.flash11
-rw-r--r--zephyr/drivers/cros_flash/CMakeLists.txt4
-rw-r--r--zephyr/drivers/cros_flash/Kconfig2
-rw-r--r--zephyr/test/spi_flash_reg/CMakeLists.txt30
25 files changed, 125 insertions, 47 deletions
diff --git a/.gitignore b/.gitignore
index f5c02e557a..adbd410018 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,5 @@
build/
-private*/
+/private*/
# A "local" directory for hiding scripts and artifacts from git.
local/
*~
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4becf0edd8..6b2f3525fe 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,3 +23,4 @@ if(NOT EXISTS "${PLATFORM_EC}/zephyr/module.yml")
endif()
add_subdirectory(zephyr)
+add_subdirectory(common)
diff --git a/Kconfig b/Kconfig
index ed64b83cb4..d3705151e3 100644
--- a/Kconfig
+++ b/Kconfig
@@ -3,3 +3,4 @@
# found in the LICENSE file.
rsource "zephyr/Kconfig"
+rsource "common/Kconfig"
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
new file mode 100644
index 0000000000..2b9baa0e69
--- /dev/null
+++ b/common/CMakeLists.txt
@@ -0,0 +1,5 @@
+# Copyright 2022 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+add_subdirectory(spi)
diff --git a/common/Kconfig b/common/Kconfig
new file mode 100644
index 0000000000..545b51ab20
--- /dev/null
+++ b/common/Kconfig
@@ -0,0 +1,5 @@
+# Copyright 2022 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+rsource "spi/Kconfig"
diff --git a/common/build.mk b/common/build.mk
index db078e8a79..ef429058f2 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -158,8 +158,7 @@ endif
common-$(CONFIG_SOFTWARE_CLZ)+=clz.o
common-$(CONFIG_SOFTWARE_CTZ)+=ctz.o
common-$(CONFIG_CMD_SPI_XFER)+=spi_commands.o
-common-$(CONFIG_SPI_FLASH)+=spi_flash.o spi_flash_reg.o
-common-$(CONFIG_SPI_FLASH_REGS)+=spi_flash_reg.o
+common-$(CONFIG_SPI_FLASH)+=spi_flash.o
common-$(CONFIG_SPI_NOR)+=spi_nor.o
common-$(CONFIG_SWITCH)+=switch.o
common-$(CONFIG_SW_CRC)+=crc.o
@@ -323,6 +322,7 @@ endif
include $(_common_dir)fpsensor/build.mk
include $(_common_dir)usbc/build.mk
+include $(_common_dir)spi/build.mk
include $(_common_dir)mock/build.mk
common-y+=$(foreach m,$(mock-y),mock/$(m))
diff --git a/common/spi/CMakeLists.txt b/common/spi/CMakeLists.txt
new file mode 100644
index 0000000000..356a0ef16a
--- /dev/null
+++ b/common/spi/CMakeLists.txt
@@ -0,0 +1,5 @@
+# Copyright 2022 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+add_subdirectory_ifdef(CONFIG_PLATFORM_EC_SPI_FLASH_REGS flash_reg)
diff --git a/common/spi/Kconfig b/common/spi/Kconfig
new file mode 100644
index 0000000000..e8408a01f5
--- /dev/null
+++ b/common/spi/Kconfig
@@ -0,0 +1,5 @@
+# Copyright 2022 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+rsource "flash_reg/Kconfig.module"
diff --git a/common/spi/build.mk b/common/spi/build.mk
new file mode 100644
index 0000000000..ad5c728db7
--- /dev/null
+++ b/common/spi/build.mk
@@ -0,0 +1,8 @@
+# -*- makefile -*-
+# Copyright 2022 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
+
+include $(SELF_DIR)flash_reg/build.mk
diff --git a/common/spi/flash_reg/CMakeLists.txt b/common/spi/flash_reg/CMakeLists.txt
new file mode 100644
index 0000000000..1b575219b1
--- /dev/null
+++ b/common/spi/flash_reg/CMakeLists.txt
@@ -0,0 +1,54 @@
+# Copyright 2022 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+cmake_minimum_required(VERSION 3.20.0)
+
+# Create the library
+if(BOARD STREQUAL unit_testing)
+ add_library(spi_flash_reg)
+else()
+ zephyr_library_named(spi_flash_reg)
+ target_link_libraries(spi_flash_reg PRIVATE cros_ec_interface)
+endif()
+
+# Add the sources
+target_sources(spi_flash_reg
+ PRIVATE
+ src/spi_flash_reg.c
+ PUBLIC
+ public/spi_flash_reg.h
+)
+
+# Include the public directory
+target_include_directories(spi_flash_reg PUBLIC public)
+
+if(BOARD STREQUAL unit_testing)
+ project(flash_reg)
+
+ # Set the sources for the test (must be done before find_package)
+ set(SOURCES src/spi_flash_reg_test.c)
+
+ # Create the unittest libraries and binary
+ find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})
+
+ # Link the library being tested
+ target_link_libraries(testbinary PRIVATE spi_flash_reg)
+
+ # Add the private directory used to mock components of the EC
+ target_include_directories(testbinary PRIVATE private)
+ target_include_directories(spi_flash_reg PRIVATE private)
+
+ # Zephyr's unittest also generates a test_interface which we need in the
+ # library (not just in the test binary)
+ target_link_libraries(spi_flash_reg PRIVATE test_interface)
+
+ # W25Q64 has 0x400000 bytes as the first section, setting
+ # CONFIG_FLASH_SIZE_BYTES to that allows us to test every branch of
+ # spi_flash_reg.c
+ add_compile_definitions(spi_flash_reg
+ PUBLIC
+ CONFIG_SPI_FLASH_W25Q64
+ CONFIG_FLASH_SIZE_BYTES=4194304
+ )
+endif() \ No newline at end of file
diff --git a/common/spi/flash_reg/Kconfig.module b/common/spi/flash_reg/Kconfig.module
new file mode 100644
index 0000000000..04a306c8d0
--- /dev/null
+++ b/common/spi/flash_reg/Kconfig.module
@@ -0,0 +1,12 @@
+# Copyright 2022 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+config PLATFORM_EC_SPI_FLASH_REGS
+ bool
+ help
+ Enables flash registers for SPI flash (both internal and external).
+ When enabled, two new functions will become available: (1) a function
+ to compute the block write protection range from a set of status
+ registers, and (2) the inverse function to set the status registers
+ based on the desired protection offset/length.
diff --git a/common/spi/flash_reg/build.mk b/common/spi/flash_reg/build.mk
new file mode 100644
index 0000000000..5d6c9f10bf
--- /dev/null
+++ b/common/spi/flash_reg/build.mk
@@ -0,0 +1,11 @@
+# -*- makefile -*-
+# Copyright 2022 The ChromiumOS Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+SELF_DIR := $(dir $(lastword $(MAKEFILE_LIST)))
+REL_PATH := $(shell realpath --relative-to $(_common_dir) $(SELF_DIR))
+
+includes+=$(REL_PATH)public
+common-$(CONFIG_SPI_FLASH)+=$(REL_PATH)/src/spi_flash_reg.o
+common-$(CONFIG_SPI_FLASH_REGS)+=$(REL_PATH)/src/spi_flash_reg.o
diff --git a/zephyr/test/spi_flash_reg/include/common.h b/common/spi/flash_reg/private/common.h
index 9737e2f889..9737e2f889 100644
--- a/zephyr/test/spi_flash_reg/include/common.h
+++ b/common/spi/flash_reg/private/common.h
diff --git a/zephyr/test/spi_flash_reg/include/util.h b/common/spi/flash_reg/private/util.h
index 119d3f10cc..119d3f10cc 100644
--- a/zephyr/test/spi_flash_reg/include/util.h
+++ b/common/spi/flash_reg/private/util.h
diff --git a/zephyr/test/spi_flash_reg/prj.conf b/common/spi/flash_reg/prj.conf
index 6ec8f4d2a9..6ec8f4d2a9 100644
--- a/zephyr/test/spi_flash_reg/prj.conf
+++ b/common/spi/flash_reg/prj.conf
diff --git a/include/spi_flash_reg.h b/common/spi/flash_reg/public/spi_flash_reg.h
index 0d70d6982d..0d70d6982d 100644
--- a/include/spi_flash_reg.h
+++ b/common/spi/flash_reg/public/spi_flash_reg.h
diff --git a/common/spi_flash_reg.c b/common/spi/flash_reg/src/spi_flash_reg.c
index fa71ab5eb6..fa71ab5eb6 100644
--- a/common/spi_flash_reg.c
+++ b/common/spi/flash_reg/src/spi_flash_reg.c
diff --git a/zephyr/test/spi_flash_reg/src/main.c b/common/spi/flash_reg/src/spi_flash_reg_test.c
index 4a6a7a5edf..4a6a7a5edf 100644
--- a/zephyr/test/spi_flash_reg/src/main.c
+++ b/common/spi/flash_reg/src/spi_flash_reg_test.c
diff --git a/zephyr/test/spi_flash_reg/testcase.yaml b/common/spi/flash_reg/testcase.yaml
index 95a71b1aae..95a71b1aae 100644
--- a/zephyr/test/spi_flash_reg/testcase.yaml
+++ b/common/spi/flash_reg/testcase.yaml
diff --git a/include/common.h b/include/common.h
index 746b185226..72553161f5 100644
--- a/include/common.h
+++ b/include/common.h
@@ -14,7 +14,7 @@
#include "compile_time_macros.h"
#ifdef CONFIG_ZEPHYR
-#include <fpu.h>
+#include "fpu.h"
#include <zephyr/sys/util.h>
#include <zephyr/toolchain.h>
#ifdef CONFIG_ZTEST
diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt
index 290fe337f9..84f5aeb97f 100644
--- a/zephyr/CMakeLists.txt
+++ b/zephyr/CMakeLists.txt
@@ -75,6 +75,12 @@ get_property(APP_LTO_PROPERTY TARGET app PROPERTY INTERPROCEDURAL_OPTIMIZATION)
set_property(TARGET ec_shim PROPERTY INTERPROCEDURAL_OPTIMIZATION ${APP_LTO_PROPERTY})
set_property(TARGET ec_shim APPEND PROPERTY COMPILE_DEFINITIONS __REQUIRE_ZEPHYR_GPIOS__)
+# Create an interface library for CrosEC (cros_ec_interface) that can be used
+# as a dependency for individual CrosEC libraries. To use:
+# zephyr_library_named(my_lib)
+# target_link_libraries(my_lib PRIVATE cros_ec_interface)
+add_library(cros_ec_interface INTERFACE)
+
# Switch from the "zephyr" library to the "app" library for all Chromium OS
# sources.
set(ZEPHYR_CURRENT_LIBRARY app)
@@ -84,11 +90,13 @@ set(ZEPHYR_CURRENT_LIBRARY app)
function(cros_ec_library_include_directories)
target_include_directories(app PUBLIC ${ARGN})
target_include_directories(ec_shim PRIVATE ${ARGN})
+ target_include_directories(cros_ec_interface INTERFACE ${ARGN})
endfunction()
function(cros_ec_library_include_directories_ifdef feature_toggle)
if(${${feature_toggle}})
target_include_directories(app PUBLIC ${ARGN})
target_include_directories(ec_shim PRIVATE ${ARGN})
+ target_include_directories(cros_ec_interface INTERFACE ${ARGN})
endif()
endfunction()
@@ -361,8 +369,6 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_SWITCH
"${PLATFORM_EC}/common/switch.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_SWITCHCAP_LN9310
"${PLATFORM_EC}/driver/ln9310.c")
-zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_SPI_FLASH_REGS
- "${PLATFORM_EC}/common/spi_flash_reg.c")
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_STM_MEMS_COMMON
"${PLATFORM_EC}/driver/stm_mems_common.c")
diff --git a/zephyr/Kconfig.flash b/zephyr/Kconfig.flash
index b8b176e987..d6812a2ce9 100644
--- a/zephyr/Kconfig.flash
+++ b/zephyr/Kconfig.flash
@@ -4,17 +4,6 @@
if PLATFORM_EC_FLASH_CROS
-config PLATFORM_EC_SPI_FLASH_REGS
- bool "Enable SPI flash registers"
- default y if SOC_FAMILY_MEC
- default y if SOC_FAMILY_NPCX
- help
- Enables flash registers for SPI flash (both internal and external).
- When enabled, two new functions will become available: (1) a function
- to compute the block write protection range from a set of status
- registers, and (2) the inverse function to set the status registers
- based on the desired protection offset/length.
-
config PLATFORM_EC_CONSOLE_CMD_CHARGEN
bool "Console command: chargen"
depends on UART_INTERRUPT_DRIVEN
diff --git a/zephyr/drivers/cros_flash/CMakeLists.txt b/zephyr/drivers/cros_flash/CMakeLists.txt
index fdd60a2f44..7a8a41b15f 100644
--- a/zephyr/drivers/cros_flash/CMakeLists.txt
+++ b/zephyr/drivers/cros_flash/CMakeLists.txt
@@ -5,3 +5,7 @@
zephyr_library_sources_ifdef(CONFIG_CROS_FLASH_IT8XXX2 cros_flash_it8xxx2.c)
zephyr_library_sources_ifdef(CONFIG_CROS_FLASH_NPCX cros_flash_npcx.c)
zephyr_library_sources_ifdef(CONFIG_CROS_FLASH_XEC cros_flash_xec.c)
+
+zephyr_library_link_libraries_ifdef(CONFIG_PLATFORM_EC_SPI_FLASH_REGS
+ spi_flash_reg
+)
diff --git a/zephyr/drivers/cros_flash/Kconfig b/zephyr/drivers/cros_flash/Kconfig
index 247f261cc5..8931f413e4 100644
--- a/zephyr/drivers/cros_flash/Kconfig
+++ b/zephyr/drivers/cros_flash/Kconfig
@@ -7,6 +7,7 @@ menuconfig CROS_FLASH_NPCX
depends on SOC_FAMILY_NPCX
default y
select PLATFORM_EC_FLASH_CROS
+ select PLATFORM_EC_SPI_FLASH_REGS
help
This option enables a flash unit interface (FIU) driver for the NPCX
chip. This is used instead of the flash memory interface so we can
@@ -41,6 +42,7 @@ config CROS_FLASH_XEC
depends on SOC_FAMILY_MEC
default y
select PLATFORM_EC_FLASH_CROS
+ select PLATFORM_EC_SPI_FLASH_REGS
help
This option enables the flash driver for the MEC172x chips. Flash
access is via the QSPI driver to one of three ports: internal 512KB
diff --git a/zephyr/test/spi_flash_reg/CMakeLists.txt b/zephyr/test/spi_flash_reg/CMakeLists.txt
deleted file mode 100644
index d56b778df8..0000000000
--- a/zephyr/test/spi_flash_reg/CMakeLists.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-# Copyright 2022 The ChromiumOS Authors
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-cmake_minimum_required(VERSION 3.20.0)
-
-set(PLATFORM_EC "${CMAKE_CURRENT_LIST_DIR}/../../..")
-get_filename_component(PLATFORM_EC "${PLATFORM_EC}" REALPATH)
-
-project(spi_flash_reg)
-set(SOURCES src/main.c ${PLATFORM_EC}/common/spi_flash_reg.c)
-find_package(Zephyr COMPONENTS unittest REQUIRED HINTS $ENV{ZEPHYR_BASE})
-
-configure_file(
- ${PLATFORM_EC}/include/spi_flash_reg.h
- ${CMAKE_BINARY_DIR}/include/spi_flash_reg.h COPYONLY
-)
-target_include_directories(testbinary
- PRIVATE
- ${CMAKE_BINARY_DIR}/include include/
-)
-
-# W25Q64 has 0x400000 bytes as the first section, setting
-# CONFIG_FLASH_SIZE_BYTES to that allows us to test every branch of
-# spi_flash_reg.c
-target_compile_definitions(testbinary
- PUBLIC
- CONFIG_SPI_FLASH_W25Q64
- CONFIG_FLASH_SIZE_BYTES=4194304
-)