Skip to content

Commit

Permalink
Squashed 'applications/' changes from 3a00cb6..529d667
Browse files Browse the repository at this point in the history
529d667 Merged bootloaders source code version 2.0.001.
87a308b Squashed 'bootloaders/' changes from 2706e99..8c8d325

git-subtree-dir: applications
git-subtree-split: 529d667b381c83e78f1c999ff81aec4c7c110674
  • Loading branch information
Lavakrishna authored and Lavakrishna committed Dec 30, 2022
1 parent 03ecd09 commit 11bfa5d
Show file tree
Hide file tree
Showing 16 changed files with 212 additions and 436 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@
#define FLASH_BYTE_SIZE (FLASH_SECTOR_SIZE * FLASH_SECTORS)
#define LAST_BLOCK_ADDR (FLASH_BYTE_SIZE - FLASH_BLOCK_SIZE)

#ifdef __UNUSED_CODE
static int test_flash(void);
static void mem_test(uint8_t *address);
static int read_program_from_flash(uint8_t *read_buf, uint32_t read_byte_length);
static void Bootloader_JumpToApplication(uint32_t stack_location, uint32_t reset_vector);
#endif

static int write_program_to_i2ceeprom(uint8_t *write_buf, uint32_t file_size);
static int write_program_to_flash(uint8_t *write_buf, uint32_t file_size);
static void copy_hex_to_i2ceeprom(void);
Expand Down Expand Up @@ -590,340 +583,3 @@ static int write_program_to_flash(uint8_t *write_buf, uint32_t file_size)

return(0);
}

#ifdef __UNUSED_CODE
/*-------------------------------------------------------------------------*//**
* Test flash on RTG4
*/
static int test_flash(void)
{
uint8_t write_buffer[FLASH_SEGMENT_SIZE];
uint8_t read_buffer[FLASH_SEGMENT_SIZE];
uint16_t status;
int flash_address = 0;
int count = 0;
spi_flash_status_t result;
struct device_Info DevInfo;

spi_flash_control_hw( SPI_FLASH_RESET, 0, &status );

result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );

result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );

/*--------------------------------------------------------------------------
* First fetch status register. First byte in low 8 bits, second byte in
* upper 8 bits.
*/
result = spi_flash_control_hw( SPI_FLASH_GET_STATUS, 0, &status );

result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );

/*--------------------------------------------------------------------------
* Fetch protection register value for each of the 128 sectors.
* After power up these should all read as 0xFF
*/
for( count = 0; count != 128; ++count )
{
result = spi_flash_control_hw( SPI_FLASH_GET_PROTECT,
count * FLASH_SECTOR_SIZE,
&read_buffer[count] );
}

//device D
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );

/*--------------------------------------------------------------------------
* Show sector protection in action by:
* - unprotecting the first sector
* - erasing the sector
* - writing some data to the first 256 bytes
* - protecting the first sector
* - erasing the first sector
* - reading back the first 256 bytes of the first sector
* - unprotecting the first sector
* - erasing the sector
* - reading back the first 256 bytes of the first sector
*
* The first read should still show the written data in place as the erase
* will fail. the second read should show all 0xFFs. Step through the code
* in debug mode and examine the read buffer after the read operations to
* see this.
*/
result = spi_flash_control_hw( SPI_FLASH_SECTOR_UNPROTECT, flash_address, NULL );
//device D works
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );
result = spi_flash_control_hw( SPI_FLASH_4KBLOCK_ERASE, flash_address , NULL );
//device D-- now working
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );
memset( write_buffer, count, FLASH_SEGMENT_SIZE );
strcpy( (char *)write_buffer, "Microsemi FLASH test" );

spi_flash_write( flash_address, write_buffer, FLASH_SEGMENT_SIZE );
//device D --
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );

result = spi_flash_control_hw( SPI_FLASH_SECTOR_PROTECT, flash_address, NULL );
//device D
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );
result = spi_flash_control_hw( SPI_FLASH_4KBLOCK_ERASE, flash_address , NULL );
//device D
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );
result = spi_flash_control_hw( SPI_FLASH_GET_STATUS, 0, &status );
//device D
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );

spi_flash_read ( flash_address, read_buffer, FLASH_SEGMENT_SIZE);
//device D
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );

result = spi_flash_control_hw( SPI_FLASH_SECTOR_UNPROTECT, flash_address, NULL );
//device D
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );
result = spi_flash_control_hw( SPI_FLASH_4KBLOCK_ERASE, flash_address , NULL );
//device D
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );
result = spi_flash_control_hw( SPI_FLASH_GET_STATUS, 0, &status );
//device D
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );

result = spi_flash_control_hw( SPI_FLASH_SECTOR_UNPROTECT, flash_address, NULL );
//device D
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );
result = spi_flash_control_hw( SPI_FLASH_4KBLOCK_ERASE, flash_address , NULL );
//device D
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );

spi_flash_read ( flash_address, read_buffer, FLASH_SEGMENT_SIZE );
//device D
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );
/*--------------------------------------------------------------------------
* Read the protection registers again so you can see that the first sector
* is unprotected now.
*/
for( count = 0; count != 128; ++count )
{
spi_flash_control_hw( SPI_FLASH_GET_PROTECT, count * FLASH_SECTOR_SIZE,
&write_buffer[count] );
}
//device D
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );
/*--------------------------------------------------------------------------
* Write something to all 32768 blocks of 256 bytes in the 8MB FLASH.
*/
for( count = 0; count != 1000 /*32768*/; ++count )
{
/*----------------------------------------------------------------------
* Vary the fill for each chunk of 256 bytes
*/
memset( write_buffer, count, FLASH_SEGMENT_SIZE );
strcpy( (char *)write_buffer, "Microsemi FLASH test" );
/*----------------------------------------------------------------------
* at the start of each sector we need to make sure it is unprotected
* so we can erase blocks within it. The spi_flash_write() function
* unprotects the sector as well but we need to start erasing before the
* first write takes place.
*/
if(0 == (flash_address % FLASH_SECTOR_SIZE))
{
result = spi_flash_control_hw( SPI_FLASH_SECTOR_UNPROTECT, flash_address, NULL );
}
/*----------------------------------------------------------------------
* At the start of each 4K block we issue an erase so that we are then
* free to write anything we want to the block. If we don't do this the
* write may fail as we can only effectively turn 1s to 0s when we
* write. For example if we have an erased location with 0xFF in it and
* we write 0xAA to it first and then later on write 0x55, the resulting
* value is 0x00...
*/
if(0 == (flash_address % FLASH_BLOCK_SIZE))
{
result = spi_flash_control_hw( SPI_FLASH_4KBLOCK_ERASE, flash_address , NULL );
}
/*----------------------------------------------------------------------
* Write our values to the FLASH, read them back and compare.
* Placing a breakpoint on the while statement below will allow
* you break on any failures.
*/
spi_flash_write( flash_address, write_buffer, FLASH_SEGMENT_SIZE );
spi_flash_read ( flash_address, read_buffer, FLASH_SEGMENT_SIZE );
if( memcmp( write_buffer, read_buffer, FLASH_SEGMENT_SIZE ) )
{
while(1) // Breakpoint here will trap write faults
{
result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo );
spi_flash_control_hw( SPI_FLASH_RESET, 0, &status );

}

}

flash_address += FLASH_SEGMENT_SIZE; /* Step to the next 256 byte chunk */
}

/*--------------------------------------------------------------------------
* One last look at the protection registers which should all be 0 now
*/
for( count = 0; count != 128; ++count )
{
spi_flash_control_hw(SPI_FLASH_GET_PROTECT,
count * FLASH_SECTOR_SIZE,
&write_buffer[count]);
}

UART_polled_tx_string( &g_uart, " Flash test success\r\n" );

return(0);
}

/**
* Read from flash
*/
static int read_program_from_flash(uint8_t *read_buf, uint32_t read_byte_length)
{
uint16_t status;
int flash_address = 0;
int count = 0;
uint32_t nb_segments_to_read;
spi_flash_status_t result;
struct device_Info DevInfo;
flash_content_t flash_content;

UART_polled_tx_string( &g_uart, "\r\n------------------- Reading from SPI flash into DDR memory --------------------\r\n" );
UART_polled_tx_string( &g_uart, "This will take several minutes to complete in order to read the full SPI flash \r\ncontent.\r\n" );

spi_flash_control_hw( SPI_FLASH_RESET, 0, &status );

result = spi_flash_control_hw(SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo);

result = spi_flash_control_hw(SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo);

/*--------------------------------------------------------------------------
* First fetch status register. First byte in low 8 bits, second byte in
* upper 8 bits.
*/
result = spi_flash_control_hw(SPI_FLASH_GET_STATUS, 0, &status);

result = spi_flash_control_hw(SPI_FLASH_READ_DEVICE_ID,
count * FLASH_SECTOR_SIZE,
&DevInfo);

/*--------------------------------------------------------------------------
* Retrieve the size of the data previously written to SPI flash.
*/
spi_flash_read ( LAST_BLOCK_ADDR, (uint8_t *)&flash_content, FLASH_SEGMENT_SIZE );

if(SPI_FLASH_VALID_CONTENT_KEY == flash_content.validity_key)
{
read_byte_length = flash_content.spi_content_byte_size;
}
else
{
read_byte_length = 0;
}

/*--------------------------------------------------------------------------
* Read from flash 256 bytes increments (FLASH_SEGMENT_SIZE).
*/
nb_segments_to_read = read_byte_length / FLASH_SEGMENT_SIZE;
if((read_byte_length % FLASH_SEGMENT_SIZE) > 0)
{
++nb_segments_to_read;
}

for( count = 0; count != nb_segments_to_read; ++count )
{
/*----------------------------------------------------------------------
* Write our values to the FLASH, read them back and compare.
* Placing a breakpoint on the while statement below will allow
* you break on any failures.
*/

spi_flash_read ( flash_address, read_buf, FLASH_SEGMENT_SIZE );
read_buf += FLASH_SEGMENT_SIZE;

flash_address += FLASH_SEGMENT_SIZE; /* Step to the next 256 byte chunk */
}

UART_polled_tx_string( &g_uart, " Flash read success\r\n" );

return(0);
}

/*
* Simple sanity check
*/
static void mem_test(uint8_t *address)
{
volatile uint8_t value=2;
volatile uint32_t value32=3;
*address = 1;
value = *address;
value32 = (uint32_t)*address;

if((value32 == value) &&(value == 1))
UART_polled_tx_string( &g_uart, " Read/Write success\r\n" );
else
UART_polled_tx_string( &g_uart, " Read/Write fail\r\n" );
}

/*------------------------------------------------------------------------------
* Call this function if you want to switch to another program
* de-init any loaded drivers before calling this function
*/
//volatile uint32_t cj_debug;
static void Bootloader_JumpToApplication(uint32_t stack_location, uint32_t reset_vector)
{
/*
* The bootstrap is going to copy the program from NV memory to the TCM.
* The TCM start address is 0x40000000. Jump to that address.
*/
__asm__ volatile ("fence.i");
__asm__ volatile("lui ra,0x40000");
__asm__ volatile("ret");
/*User application execution should now start and never return here.... */
}

#endif /*__UNUSED_CODE*/
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2021 Microchip FPGA Embedded Systems Solutions.
* Copyright 2019-2023 Microchip FPGA Embedded Systems Solutions.
*
* SPDX-License-Identifier: MIT
*
Expand Down
2 changes: 1 addition & 1 deletion bootloaders/miv-rv32-bootloader/src/platform/hal/hal_irq.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************//**
* Copyright 2019-2021 Microchip FPGA Embedded Systems Solutions.
* Copyright 2019-2023 Microchip FPGA Embedded Systems Solutions.
*
* SPDX-License-Identifier: MIT
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright 2019-2021 Microchip FPGA Embedded Systems Solutions.
* Copyright 2019-2023 Microchip FPGA Embedded Systems Solutions.
*
* SPDX-License-Identifier: MIT
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************//**
* Copyright 2019-2021 Microchip FPGA Embedded Systems Solutions.
* Copyright 2019-2023 Microchip FPGA Embedded Systems Solutions.
*
* SPDX-License-Identifier: MIT
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/***************************************************************************//**
* Copyright 2019-2021 Microchip FPGA Embedded Systems Solutions.
* Copyright 2019-2023 Microchip FPGA Embedded Systems Solutions.
*
* SPDX-License-Identifier: MIT
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ MEMORY
}

STACK_SIZE = 1k; /* needs to be calculated for your application */
HEAP_SIZE = 0; /* needs to be calculated for your application */
HEAP_SIZE = 1k; /* needs to be calculated for your application */

SECTIONS
{
Expand Down
Loading

0 comments on commit 11bfa5d

Please sign in to comment.