Initial version
This commit is contained in:
commit
b8db6e9dc4
155
fm10k-dump.c
Normal file
155
fm10k-dump.c
Normal file
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
*
|
||||
*
|
||||
* Install IES on /root/install, via: ./configure --prefix /root/install && make && make install
|
||||
*
|
||||
gcc -DFM_SUPPORT_FM10000 -D_FM_ARCH_X86_64 \
|
||||
-I/root/install/include -I/root/install/include/alos -I/root/install/include/alos/linux -I/root/install/include/std/intel -I/root/install/include/common -I/root/install/include/platforms -I/root/install/include/platforms/libertyTrail -L/usr/local/lib \
|
||||
-lFocalpointSDK -ldl -lpthread -lm \
|
||||
-o fm10k-dump fm10k-dump.c
|
||||
*
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "fm_sdk.h"
|
||||
#include "fm_sdk_fm10000_int.h"
|
||||
#include "util/fm10000/fm10000_util_spi.h"
|
||||
|
||||
#define FM_MAIN_SWITCH 0
|
||||
#define FM_DEFAULT_VLAN 1
|
||||
#define ETHTOOL_SPFLAGS 0x00000028
|
||||
#define ETHTOOL_PRV_FLAG_IES_DISABLE (0 << 0)
|
||||
|
||||
#define SPI_FREQ_KHZ 50000
|
||||
|
||||
fm_semaphore seqSem;
|
||||
fm_int sw = FM_MAIN_SWITCH;
|
||||
|
||||
/*****************************************************************************/
|
||||
/** RegRead32
|
||||
* \ingroup intPlatform
|
||||
*
|
||||
* \desc Read register value.
|
||||
*
|
||||
* \param[in] switchMem is pointer to mapped memory
|
||||
*
|
||||
* \param[in] addr is the address of the register
|
||||
*
|
||||
* \param[out] value is a pointer to the register value
|
||||
*
|
||||
* \return FM_OK if successful.
|
||||
* \return FM_ERR_INVALID_ARGUMENT if either switchMem or value is NULL.
|
||||
*
|
||||
*****************************************************************************/
|
||||
static fm_status RegRead32(fm_uintptr switchMem,
|
||||
fm_uint addr,
|
||||
fm_uint32 *value)
|
||||
{
|
||||
FM_LOG_ENTRY(FM_LOG_CAT_PLATFORM,
|
||||
"switchMem %p addr 0x%x value %p\n",
|
||||
(void*)switchMem,
|
||||
addr,
|
||||
(void*)value);
|
||||
|
||||
if ( ((fm_uint32*)switchMem == NULL) || (value == NULL) )
|
||||
{
|
||||
FM_LOG_EXIT(FM_LOG_CAT_PLATFORM, FM_ERR_INVALID_ARGUMENT);
|
||||
}
|
||||
|
||||
*value = *(((fm_uint32*)switchMem) + addr);
|
||||
|
||||
FM_LOG_EXIT(FM_LOG_CAT_PLATFORM, FM_OK);
|
||||
|
||||
} /* end RegRead32 */
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/** RegWrite32
|
||||
* \ingroup intPlatform
|
||||
*
|
||||
* \desc Write a value to register.
|
||||
*
|
||||
* \param[in] switchMem is pointer to mapped memory
|
||||
*
|
||||
* \param[in] addr is the address of the register
|
||||
*
|
||||
* \param[out] value is the register value
|
||||
*
|
||||
* \return FM_OK if successful.
|
||||
* \return FM_ERR_INVALID_ARGUMENT if switchMem is NULL.
|
||||
*
|
||||
*****************************************************************************/
|
||||
static fm_status RegWrite32(fm_uintptr switchMem,
|
||||
fm_uint addr,
|
||||
fm_uint32 value)
|
||||
{
|
||||
FM_LOG_ENTRY(FM_LOG_CAT_PLATFORM,
|
||||
"switchMem %p addr 0x%x value 0x%x\n",
|
||||
(void*)switchMem,
|
||||
addr,
|
||||
value);
|
||||
|
||||
if ((fm_uint32*)switchMem == NULL)
|
||||
{
|
||||
FM_LOG_EXIT(FM_LOG_CAT_PLATFORM, FM_ERR_INVALID_ARGUMENT);
|
||||
}
|
||||
|
||||
*(((fm_uint32*)switchMem) + addr) = value;
|
||||
|
||||
FM_LOG_EXIT(FM_LOG_CAT_PLATFORM, FM_OK);
|
||||
|
||||
} /* end RegWrite32 */
|
||||
|
||||
|
||||
fm_status fm10000CrmDummy( fm_smEventInfo *eventInfo, void *userInfo, fm_int *nextState ){
|
||||
|
||||
}
|
||||
|
||||
int main(int argc, char** argv){
|
||||
fm_int fd;
|
||||
fm_int size;
|
||||
void *memmapAddr;
|
||||
fm_uint32 *switchMem;
|
||||
fm_status err = FM_OK;
|
||||
|
||||
FILE* binFD;
|
||||
|
||||
if(argc < 2){
|
||||
printf("Usage: %s <output.bin>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
binFD = fopen(argv[1], "wb");
|
||||
|
||||
if(binFD == NULL){
|
||||
printf("Could not create %s\n", argv[1]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
err = fmPlatformMmapUioDevice(NULL, &fd, &memmapAddr, &size);
|
||||
if (err)
|
||||
{
|
||||
printf("Unable to map uio device to read NVM\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
switchMem = (fm_uint32*) memmapAddr;
|
||||
|
||||
fm_uint32 bootImageSize = 1 * 1024 * 1024;
|
||||
fm_byte value;
|
||||
for(fm_uint32 addr = 0x0; addr < bootImageSize; ++addr){
|
||||
err = fm10000UtilSpiReadFlash((fm_uintptr)switchMem, RegRead32, RegWrite32, addr, &value, sizeof(fm_byte), SPI_FREQ_KHZ);
|
||||
if(err){
|
||||
return 2;
|
||||
}
|
||||
fwrite(&value, sizeof(value), 1, binFD);
|
||||
}
|
||||
|
||||
fclose(binFD);
|
||||
|
||||
return err;
|
||||
}
|
Loading…
Reference in a new issue