| /* |
| * Copyright 2023 Google LLC |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| /* |
| * Barebones SPI Flash support for reading data from SPI at startup. |
| */ |
| #include "spi.h" |
| |
| #include <fail-simulator-on-error.h> |
| #include <thread.h> |
| |
| #include <debug.hh> |
| |
| #include "hw/top_matcha/sw/autogen/top_matcha.h" |
| #include "sw/device/lib/spi_flash.h" |
| |
| /// Expose debugging features unconditionally for this compartment. |
| using Debug = ConditionalDebug<false, "SPI">; |
| |
| #include "compat.h" |
| |
| typedef uint8_t spi_host_t[TOP_MATCHA_SPI_HOST0_SIZE_BYTES]; |
| typedef uint8_t flash_ctrl_t[TOP_MATCHA_FLASH_CTRL_CORE_SIZE_BYTES]; |
| typedef uint8_t otp_t[TOP_MATCHA_OTP_CTRL_CORE_SIZE_BYTES]; |
| |
| void spi_init(void) { |
| Debug::log("spi_init: called from Thread {}", thread_id_get()); |
| CHECK_DIF_OK( |
| spi_flash_init((uintptr_t)MMIO_CAPABILITY(spi_host_t, spi_host), |
| (uintptr_t)MMIO_CAPABILITY(flash_ctrl_t, flash_ctrl), |
| (uintptr_t)MMIO_CAPABILITY(otp_t, otp))); |
| } |
| |
| void spi_load_file_from_tar(const char* filename, void* addr, |
| size_t max_mem_addr) { |
| Debug::log("Load {} at {}, max {} ", filename, addr, max_mem_addr); |
| CHECK_DIF_OK(load_file_from_tar(filename, addr, max_mem_addr)); |
| } |