-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
treewide: Add SPI write support and flashing utility (#45)
* hw/bootrom: Add `ebreak` on return, some cleanup * sw: Add SD and NOR flash write support and flashing utility * target/xilinx: Add QSPI and NOR flash boot support on Genesys2 * sw/boot: Clean up VCU128 NOR flash device tree entry * util: Increase OpenOCD adapter speed to 8 kHz * sw: Fix various `-Wpedantic` warnings, some cleanup * nonfree: Integrate new internal CI setup * docs: Document changes
- Loading branch information
Showing
30 changed files
with
2,220 additions
and
1,852 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,7 +61,7 @@ chs-clean-deps: | |
###################### | ||
|
||
CHS_NONFREE_REMOTE ?= [email protected]:pulp-restricted/cheshire-nonfree.git | ||
CHS_NONFREE_COMMIT ?= fd3526f | ||
CHS_NONFREE_COMMIT ?= 99e58ec | ||
|
||
CHS_PHONY += chs-nonfree-init | ||
chs-nonfree-init: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,12 @@ | |
// | ||
// Nicole Narr <[email protected]> | ||
// Christopher Reinwardt <[email protected]> | ||
// Paul Scheffler <paulsc@student.ethz.ch> | ||
// Paul Scheffler <paulsc@iis.ee.ethz.ch> | ||
|
||
#include <stdint.h> | ||
#include "util.h" | ||
#include "params.h" | ||
#include "regs/cheshire.h" | ||
#include "regs/serial_link.h" | ||
#include "spi_host_regs.h" | ||
#include "dif/clint.h" | ||
#include "hal/i2c_24fc1025.h" | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2023 ETH Zurich and University of Bologna. | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Paul Scheffler <[email protected]> | ||
// | ||
// Boot disk flasher for Cheshire; writes a contiguous disk segment to a boot target disk. | ||
// This program can be preloaded and invoked repeatedly to write multiple segments. | ||
|
||
#include <stdint.h> | ||
#include "util.h" | ||
#include "params.h" | ||
#include "regs/cheshire.h" | ||
#include "spi_host_regs.h" | ||
#include "dif/clint.h" | ||
#include "hal/i2c_24fc1025.h" | ||
#include "hal/spi_s25fs512s.h" | ||
#include "hal/spi_sdcard.h" | ||
#include "hal/uart_debug.h" | ||
#include "gpt.h" | ||
#include "printf.h" | ||
|
||
int flash_spi_sdcard(uint64_t core_freq, uint64_t rtc_freq, void *img_base, uint64_t sector, | ||
uint64_t len) { | ||
// Initialize device handle | ||
spi_sdcard_t device = { | ||
.spi_freq = 24 * 1000 * 1000, // 24MHz (maximum is 25MHz) | ||
.csid = 0, | ||
.csid_dummy = SPI_HOST_PARAM_NUM_C_S - 1 // Last physical CS is designated dummy | ||
}; | ||
CHECK_CALL(spi_sdcard_init(&device, core_freq)) | ||
// Wait for device to be initialized (1ms, round up extra tick to be sure) | ||
clint_spin_until((1000 * rtc_freq) / (1000 * 1000) + 1); | ||
// Write sectors: we have 512 512B blocks per 256KiB sector, so a 9b left shift | ||
return spi_sdcard_write_blocks(&device, img_base, sector << 9, len << 9, 1); | ||
} | ||
|
||
int flash_spi_s25fs512s(uint64_t core_freq, uint64_t rtc_freq, void *img_base, uint64_t sector, | ||
uint64_t len) { | ||
// Initialize device handle | ||
spi_s25fs512s_t device = { | ||
.spi_freq = MIN(40 * 1000 * 1000, core_freq / 4), // Up to quarter core freq or 40MHz | ||
.csid = 1}; | ||
CHECK_CALL(spi_s25fs512s_init(&device, core_freq)) | ||
// Wait for device to be initialized (t_PU = 300us, round up extra tick to be sure) | ||
clint_spin_until((350 * rtc_freq) / (1000 * 1000) + 1); | ||
// Write sectors of 256 KiB directly | ||
return spi_s25fs512s_single_flash(&device, img_base, sector, len); | ||
} | ||
|
||
int flash_i2c_24fc1025(uint64_t core_freq, void *img_base) { | ||
// Initialize device handle | ||
dif_i2c_t i2c; | ||
CHECK_CALL(i2c_24fc1025_init(&i2c, core_freq)) | ||
// Write half of a single 256 KiB sector (entire capacity) | ||
return i2c_24fc1025_write(&i2c, img_base, 0, 128 * 1024); | ||
} | ||
|
||
int main() { | ||
int ret; | ||
// Read reference frequency and compute core frequency | ||
uint32_t rtc_freq = *reg32(&__base_regs, CHESHIRE_RTC_FREQ_REG_OFFSET); | ||
uint64_t core_freq = clint_get_core_freq(rtc_freq, 2500); | ||
// Get arguments from scratch registers | ||
volatile uint32_t *scratch = reg32(&__base_regs, CHESHIRE_SCRATCH_0_REG_OFFSET); | ||
uint64_t target = scratch[0]; | ||
void *img_base = (void *)(uintptr_t)scratch[1]; | ||
uint64_t sector = scratch[2]; | ||
uint64_t len = scratch[3]; | ||
// Flash chosen disk | ||
printf("[FLASH] Write buffer at 0x%x of length %d to target %d, sector %d ... ", img_base, len, | ||
target, sector); | ||
switch (target) { | ||
case 1: { | ||
ret = flash_spi_sdcard(core_freq, rtc_freq, img_base, sector, len); | ||
break; | ||
} | ||
case 2: { | ||
ret = flash_spi_s25fs512s(core_freq, rtc_freq, img_base, sector, len); | ||
break; | ||
} | ||
case 3: { | ||
ret = flash_i2c_24fc1025(core_freq, img_base); | ||
break; | ||
} | ||
default: { | ||
ret = -1; | ||
break; | ||
} | ||
} | ||
if (ret) | ||
printf("ERROR (%d)\r\n", ret); | ||
else | ||
printf("OK\r\n"); | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.