Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[platform/cel] - Add cpld upgrade tool. #2446

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions platform/broadcom/sonic-platform-modules-cel/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ KVERSION ?= $(shell uname -r)
KERNEL_SRC := /lib/modules/$(KVERSION)
MOD_SRC_DIR:= $(shell pwd)
MODULE_DIRS:= dx010 haliburton silverstone seastone2
TOOL_DIRS := tools

%:
dh $@
Expand All @@ -17,13 +18,18 @@ override_dh_auto_build:
python2.7 setup.py bdist_wheel -d $(MOD_SRC_DIR)/$${mod}/modules; \
cd $(MOD_SRC_DIR); \
done)
make -C $(MOD_SRC_DIR)/tools/ispvme_12.2;

override_dh_auto_install:
(for mod in $(MODULE_DIRS); do \
dh_installdirs -pplatform-modules-$${mod} \
$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \
dh_installdirs -pplatform-modules-$${mod} \
/usr/local/bin; \
cp $(MOD_SRC_DIR)/$${mod}/modules/*.ko \
debian/platform-modules-$${mod}/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \
cp $(MOD_SRC_DIR)/tools/ispvme_12.2/ispvm \
debian/platform-modules-$${mod}/usr/local/bin/; \
done)

override_dh_usrlocal:
Expand All @@ -33,4 +39,5 @@ override_dh_clean:
(for mod in $(MODULE_DIRS); do \
make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules clean; \
done)
make -C $(MOD_SRC_DIR)/tools/ispvme_12.2 clean;

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CC = gcc
AR = ar
CFLAGS = -Wall -W -Wunused -lpthread -g -O0 -ggdb -DDIAG_DEBUG -DDIAG_API -DHAVE_CONFIG_H -DFCS_DEBUG -DHAVE_NANOSLEEP
LFLAGS = -lm -pthread
DEL_FILE = rm -f
MV_FILE = mv -f
OBJ_FILE_NODE = ./*.o
INCPATH = -I../include/
TARGET = ispvm

OBJECTS += hardware.o ispvm_ui.o ivm_core.o

.c.o:
$(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
$(TARGET):$(OBJECTS)
$(CC) -o $(TARGET) $(OBJECTS)

clean:
-$(DEL_FILE) $(TARGET)
-$(DEL_FILE) $(OBJ_FILE_NODE)


Original file line number Diff line number Diff line change
@@ -0,0 +1,313 @@
/*********************************************************************************
* Lattice Semiconductor Corp. Copyright 2000-2008
*
* This is the hardware.c of ispVME V12.1 for JTAG programmable devices.
* All the functions requiring customization are organized into this file for
* the convinience of porting.
*********************************************************************************/
/*********************************************************************************
* Revision History:
*
* 09/11/07 NN Type cast mismatch variables
* 09/24/07 NN Added calibration function.
* Calibration will help to determine the system clock frequency
* and the count value for one micro-second delay of the target
* specific hardware.
* Modified the ispVMDelay function
* Removed Delay Percent support
* Moved the sclock() function from ivm_core.c to hardware.c
lguohan marked this conversation as resolved.
Show resolved Hide resolved
*********************************************************************************/
#include "vmopcode.h"
#include <sys/io.h>
#include <unistd.h>
/********************************************************************************
* Declaration of global variables
*
*********************************************************************************/
#ifndef IPMI_PRJ
unsigned long g_siIspPins = 0x00000000; /*Keeper of JTAG pin state*/
unsigned short g_usInPort = 0x588; /*Address of the TDO pin*/
unsigned short g_usOutPort = 0x588; /*Address of TDI, TMS, TCK pin*/
unsigned short g_usCpu_Frequency = 2400; // Here is Intel rangely CPU frequence /*Enter your CPU frequency here, unit in MHz.*/
#else
unsigned long g_siIspPins = 0x00000000; /*Keeper of JTAG pin state*/
unsigned short g_usInPort = 0x548; /*Address of the TDO pin*/
unsigned short g_usOutPort = 0x548; /*Address of TDI, TMS, TCK pin*/
unsigned short g_usCpu_Frequency = 4000; // Here is Intel rangely CPU frequence /*Enter your CPU frequency here, unit in MHz.*/
#endif

/*********************************************************************************
* This is the definition of the bit locations of each respective
* signal in the global variable g_siIspPins.
*
* NOTE: Users must add their own implementation here to define
* the bit location of the signal to target their hardware.
* The example below is for the Lattice download cable on
* on the parallel port.
*
*********************************************************************************/

#ifndef IPMI_PRJ
const unsigned long g_ucPinTDI = 0x00000100; /* Bit address of TDI */
const unsigned long g_ucPinTCK = 0x00000010; /* Bit address of TCK */
const unsigned long g_ucPinTMS = 0x00000020; /* Bit address of TMS */
const unsigned long g_ucPinENABLE = 0x08; /* Bit address of ENABLE */
const unsigned long g_ucPinTRST = 0x10; /* Bit address of TRST */
const unsigned long g_ucPinTDO = 0x00040000; /* Bit address of TDO*/
#else
const unsigned long g_ucPinTDI = 0x00000010; /* Bit address of TDI Bit4*/
const unsigned long g_ucPinTCK = 0x00000020; /* Bit address of TCK Bit5*/
const unsigned long g_ucPinTMS = 0x00000004; /* Bit address of TMS Bit2*/
const unsigned long g_ucPinENABLE = 0x08; /* Bit address of ENABLE */
const unsigned long g_ucPinTRST = 0x10; /* Bit address of TRST */
const unsigned long g_ucPinTDO = 0x00000008; /* Bit address of TDO Bit3*/
#endif
/***************************************************************
*
* Functions declared in hardware.c module.
*
***************************************************************/
void writePort( unsigned long a_ucPins, unsigned char a_ucValue );
unsigned char readPort();
void sclock();
void ispVMDelay( unsigned short a_usTimeDelay );
void calibration(void);

/********************************************************************************
* writePort
* To apply the specified value to the pins indicated. This routine will
* be modified for specific systems.
* As an example, this code uses the IBM-PC standard Parallel port, along with the
* schematic shown in Lattice documentation, to apply the signals to the
* JTAG pins.
*
* PC Parallel port pin Signal name Port bit address
* 2 g_ucPinTDI 1
* 3 g_ucPinTCK 2
* 4 g_ucPinTMS 4
* 5 g_ucPinENABLE 8
* 6 g_ucPinTRST 16
* 10 g_ucPinTDO 64
*
* Parameters:
* - a_ucPins, which is actually a set of bit flags (defined above)
* that correspond to the bits of the data port. Each of the I/O port
* bits that drives an isp programming pin is assigned a flag
* (through a #define) corresponding to the signal it drives. To
* change the value of more than one pin at once, the flags are added
* together, much like file access flags are.
*
* The bit flags are only set if the pin is to be changed. Bits that
* do not have their flags set do not have their levels changed. The
* state of the port is always manintained in the static global
* variable g_siIspPins, so that each pin can be addressed individually
* without disturbing the others.
*
* - a_ucValue, which is either HIGH (0x01 ) or LOW (0x00 ). Only these two
* values are valid. Any non-zero number sets the pin(s) high.
*
*********************************************************************************/

void writePort( unsigned long a_ucPins, unsigned char a_ucValue )
{
if ( a_ucValue ) {
g_siIspPins = (a_ucPins | g_siIspPins);
}
else {
g_siIspPins = (~a_ucPins & g_siIspPins);
}

outl_p( g_siIspPins, g_usOutPort );
/* This is a sample code for Windows/DOS without Windows Driver.
_outp( g_usOutPort, g_siIspPins );
*/
}

/*********************************************************************************
*
* readPort
*
* Returns the value of the TDO from the device.
*
**********************************************************************************/
unsigned char readPort()
{
unsigned char ucRet = 0;

if ( inl_p( g_usInPort ) & g_ucPinTDO ) {
ucRet = 0x01;
}
else {
ucRet = 0x00;
}
//printf("Read Port: 0x%x\n", ucRet);
return ( ucRet );
}

/*********************************************************************************
* sclock
*
* Apply a pulse to TCK.
*
* This function is located here so that users can modify to slow down TCK if
* it is too fast (> 25MHZ). Users can change the IdleTime assignment from 0 to
* 1, 2... to effectively slowing down TCK by half, quarter...
*
*********************************************************************************/
void sclock()
{
unsigned short IdleTime = 0; //change to > 0 if need to slow down TCK
unsigned short usIdleIndex = 0;
IdleTime++;
for ( usIdleIndex = 0; usIdleIndex < IdleTime; usIdleIndex++ ) {
writePort( g_ucPinTCK, 0x01 );
}
for ( usIdleIndex = 0; usIdleIndex < IdleTime; usIdleIndex++ ) {
writePort( g_ucPinTCK, 0x00 );
}
}
/********************************************************************************
*
* ispVMDelay
*
*
* Users must implement a delay to observe a_usTimeDelay, where
* bit 15 of the a_usTimeDelay defines the unit.
* 1 = milliseconds
* 0 = microseconds
* Example:
* a_usTimeDelay = 0x0001 = 1 microsecond delay.
* a_usTimeDelay = 0x8001 = 1 millisecond delay.
*
* This subroutine is called upon to provide a delay from 1 millisecond to a few
* hundreds milliseconds each time.
* It is understood that due to a_usTimeDelay is defined as unsigned short, a 16 bits
* integer, this function is restricted to produce a delay to 64000 micro-seconds
* or 32000 milli-second maximum. The VME file will never pass on to this function
* a delay time > those maximum number. If it needs more than those maximum, the VME
* file will launch the delay function several times to realize a larger delay time
* cummulatively.
* It is perfectly alright to provide a longer delay than required. It is not
* acceptable if the delay is shorter.
*
* Delay function example--using the machine clock signal of the native CPU------
* When porting ispVME to a native CPU environment, the speed of CPU or
* the system clock that drives the CPU is usually known.
* The speed or the time it takes for the native CPU to execute one for loop
* then can be calculated as follows:
* The for loop usually is compiled into the ASSEMBLY code as shown below:
* LOOP: DEC RA;
* JNZ LOOP;
* If each line of assembly code needs 4 machine cycles to execute,
* the total number of machine cycles to execute the loop is 2 x 4 = 8.
* Usually system clock = machine clock (the internal CPU clock).
* Note: Some CPU has a clock multiplier to double the system clock for
the machine clock.
*
* Let the machine clock frequency of the CPU be F, or 1 machine cycle = 1/F.
* The time it takes to execute one for loop = (1/F ) x 8.
* Or one micro-second = F(MHz)/8;
*
* Example: The CPU internal clock is set to 100Mhz, then one micro-second = 100/8 = 12
*
* The C code shown below can be used to create the milli-second accuracy.
* Users only need to enter the speed of the cpu.
*
**********************************************************************************/
void ispVMDelay( unsigned short a_usTimeDelay )
{
unsigned short loop_index = 0;
unsigned short ms_index = 0;
unsigned short us_index = 0;

if ( a_usTimeDelay & 0x8000 ) /*Test for unit*/
{
a_usTimeDelay &= ~0x8000; /*unit in milliseconds*/
}
else { /*unit in microseconds*/
a_usTimeDelay = (unsigned short) (a_usTimeDelay/1000); /*convert to milliseconds*/
if ( a_usTimeDelay <= 0 ) {
a_usTimeDelay = 1; /*delay is 1 millisecond minimum*/
}
}
/*Users can replace the following section of code by their own*/
for( ms_index = 0; ms_index < a_usTimeDelay; ms_index++)
{
/*Loop 1000 times to produce the milliseconds delay*/
for (us_index = 0; us_index < 1000; us_index++)
{ /*each loop should delay for 1 microsecond or more.*/
loop_index = 0;
do {
/*The NOP fakes the optimizer out so that it doesn't toss out the loop code entirely*/
asm("nop");
}while (loop_index++ < ((g_usCpu_Frequency/8)+(+ ((g_usCpu_Frequency % 8) ? 1 : 0))));/*use do loop to force at least one loop*/
}
}
}

/*********************************************************************************
*
* calibration
*
* It is important to confirm if the delay function is indeed providing
* the accuracy required. Also one other important parameter needed
* checking is the clock frequency.
* Calibration will help to determine the system clock frequency
* and the loop_per_micro value for one micro-second delay of the target
* specific hardware.
*
**********************************************************************************/
void calibration(void)
{
/*Apply 2 pulses to TCK.*/
writePort( g_ucPinTCK, 0x00 );
writePort( g_ucPinTCK, 0x01 );
writePort( g_ucPinTCK, 0x00 );
writePort( g_ucPinTCK, 0x01 );
writePort( g_ucPinTCK, 0x00 );

/*Delay for 1 millisecond. Pass on 1000 or 0x8001 both = 1ms delay.*/
ispVMDelay(0x8001);

/*Apply 2 pulses to TCK*/
writePort( g_ucPinTCK, 0x01 );
writePort( g_ucPinTCK, 0x00 );
writePort( g_ucPinTCK, 0x01 );
writePort( g_ucPinTCK, 0x00 );
}

void port_test(void)
{
int siRetCode;
unsigned char cbit;

printf("TDI set HIGH.\n");
scanf("%d",&siRetCode);
writePort( g_ucPinTDI, 0x01);
printf("TDI set LOW.\n");
scanf("%d",&siRetCode);
writePort( g_ucPinTDI, 0x00);
printf("TMS set HIGH.\n");
scanf("%d",&siRetCode);
writePort(g_ucPinTMS, 0x01);
printf("TMS set LOW.\n");
scanf("%d",&siRetCode);
writePort(g_ucPinTMS, 0x00);
printf("TCK set HIGH.\n");
scanf("%d",&siRetCode);
writePort(g_ucPinTCK, 0x01);
printf("TCK set LOW.\n");
scanf("%d",&siRetCode);
writePort(g_ucPinTCK, 0x00);
printf("write finished.read begin:\n");
scanf("%d",&siRetCode);
cbit = readPort();
printf("Read date is %d\n", cbit);
printf("read begin:\n");
scanf("%d",&siRetCode);
cbit = readPort();
printf("Read date is %d\n", cbit);
printf("read finished.\n");
scanf("%d",&siRetCode);
/******test JTAG ports**********/
}
Loading