1*4882a593Smuzhiyun========================================= 2*4882a593SmuzhiyunFreescale QUICC Engine Firmware Uploading 3*4882a593Smuzhiyun========================================= 4*4882a593Smuzhiyun 5*4882a593Smuzhiyun(c) 2007 Timur Tabi <timur at freescale.com>, 6*4882a593Smuzhiyun Freescale Semiconductor 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun.. Table of Contents 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun I - Software License for Firmware 11*4882a593Smuzhiyun 12*4882a593Smuzhiyun II - Microcode Availability 13*4882a593Smuzhiyun 14*4882a593Smuzhiyun III - Description and Terminology 15*4882a593Smuzhiyun 16*4882a593Smuzhiyun IV - Microcode Programming Details 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun V - Firmware Structure Layout 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun VI - Sample Code for Creating Firmware Files 21*4882a593Smuzhiyun 22*4882a593SmuzhiyunRevision Information 23*4882a593Smuzhiyun==================== 24*4882a593Smuzhiyun 25*4882a593SmuzhiyunNovember 30, 2007: Rev 1.0 - Initial version 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunI - Software License for Firmware 28*4882a593Smuzhiyun================================= 29*4882a593Smuzhiyun 30*4882a593SmuzhiyunEach firmware file comes with its own software license. For information on 31*4882a593Smuzhiyunthe particular license, please see the license text that is distributed with 32*4882a593Smuzhiyunthe firmware. 33*4882a593Smuzhiyun 34*4882a593SmuzhiyunII - Microcode Availability 35*4882a593Smuzhiyun=========================== 36*4882a593Smuzhiyun 37*4882a593SmuzhiyunFirmware files are distributed through various channels. Some are available on 38*4882a593Smuzhiyunhttp://opensource.freescale.com. For other firmware files, please contact 39*4882a593Smuzhiyunyour Freescale representative or your operating system vendor. 40*4882a593Smuzhiyun 41*4882a593SmuzhiyunIII - Description and Terminology 42*4882a593Smuzhiyun================================= 43*4882a593Smuzhiyun 44*4882a593SmuzhiyunIn this document, the term 'microcode' refers to the sequence of 32-bit 45*4882a593Smuzhiyunintegers that compose the actual QE microcode. 46*4882a593Smuzhiyun 47*4882a593SmuzhiyunThe term 'firmware' refers to a binary blob that contains the microcode as 48*4882a593Smuzhiyunwell as other data that 49*4882a593Smuzhiyun 50*4882a593Smuzhiyun 1) describes the microcode's purpose 51*4882a593Smuzhiyun 2) describes how and where to upload the microcode 52*4882a593Smuzhiyun 3) specifies the values of various registers 53*4882a593Smuzhiyun 4) includes additional data for use by specific device drivers 54*4882a593Smuzhiyun 55*4882a593SmuzhiyunFirmware files are binary files that contain only a firmware. 56*4882a593Smuzhiyun 57*4882a593SmuzhiyunIV - Microcode Programming Details 58*4882a593Smuzhiyun=================================== 59*4882a593Smuzhiyun 60*4882a593SmuzhiyunThe QE architecture allows for only one microcode present in I-RAM for each 61*4882a593SmuzhiyunRISC processor. To replace any current microcode, a full QE reset (which 62*4882a593Smuzhiyundisables the microcode) must be performed first. 63*4882a593Smuzhiyun 64*4882a593SmuzhiyunQE microcode is uploaded using the following procedure: 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun1) The microcode is placed into I-RAM at a specific location, using the 67*4882a593Smuzhiyun IRAM.IADD and IRAM.IDATA registers. 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun2) The CERCR.CIR bit is set to 0 or 1, depending on whether the firmware 70*4882a593Smuzhiyun needs split I-RAM. Split I-RAM is only meaningful for SOCs that have 71*4882a593Smuzhiyun QEs with multiple RISC processors, such as the 8360. Splitting the I-RAM 72*4882a593Smuzhiyun allows each processor to run a different microcode, effectively creating an 73*4882a593Smuzhiyun asymmetric multiprocessing (AMP) system. 74*4882a593Smuzhiyun 75*4882a593Smuzhiyun3) The TIBCR trap registers are loaded with the addresses of the trap handlers 76*4882a593Smuzhiyun in the microcode. 77*4882a593Smuzhiyun 78*4882a593Smuzhiyun4) The RSP.ECCR register is programmed with the value provided. 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun5) If necessary, device drivers that need the virtual traps and extended mode 81*4882a593Smuzhiyun data will use them. 82*4882a593Smuzhiyun 83*4882a593SmuzhiyunVirtual Microcode Traps 84*4882a593Smuzhiyun 85*4882a593SmuzhiyunThese virtual traps are conditional branches in the microcode. These are 86*4882a593Smuzhiyun"soft" provisional introduced in the ROMcode in order to enable higher 87*4882a593Smuzhiyunflexibility and save h/w traps If new features are activated or an issue is 88*4882a593Smuzhiyunbeing fixed in the RAM package utilizing they should be activated. This data 89*4882a593Smuzhiyunstructure signals the microcode which of these virtual traps is active. 90*4882a593Smuzhiyun 91*4882a593SmuzhiyunThis structure contains 6 words that the application should copy to some 92*4882a593Smuzhiyunspecific been defined. This table describes the structure:: 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun --------------------------------------------------------------- 95*4882a593Smuzhiyun | Offset in | | Destination Offset | Size of | 96*4882a593Smuzhiyun | array | Protocol | within PRAM | Operand | 97*4882a593Smuzhiyun --------------------------------------------------------------| 98*4882a593Smuzhiyun | 0 | Ethernet | 0xF8 | 4 bytes | 99*4882a593Smuzhiyun | | interworking | | | 100*4882a593Smuzhiyun --------------------------------------------------------------- 101*4882a593Smuzhiyun | 4 | ATM | 0xF8 | 4 bytes | 102*4882a593Smuzhiyun | | interworking | | | 103*4882a593Smuzhiyun --------------------------------------------------------------- 104*4882a593Smuzhiyun | 8 | PPP | 0xF8 | 4 bytes | 105*4882a593Smuzhiyun | | interworking | | | 106*4882a593Smuzhiyun --------------------------------------------------------------- 107*4882a593Smuzhiyun | 12 | Ethernet RX | 0x22 | 1 byte | 108*4882a593Smuzhiyun | | Distributor Page | | | 109*4882a593Smuzhiyun --------------------------------------------------------------- 110*4882a593Smuzhiyun | 16 | ATM Globtal | 0x28 | 1 byte | 111*4882a593Smuzhiyun | | Params Table | | | 112*4882a593Smuzhiyun --------------------------------------------------------------- 113*4882a593Smuzhiyun | 20 | Insert Frame | 0xF8 | 4 bytes | 114*4882a593Smuzhiyun --------------------------------------------------------------- 115*4882a593Smuzhiyun 116*4882a593Smuzhiyun 117*4882a593SmuzhiyunExtended Modes 118*4882a593Smuzhiyun 119*4882a593SmuzhiyunThis is a double word bit array (64 bits) that defines special functionality 120*4882a593Smuzhiyunwhich has an impact on the software drivers. Each bit has its own impact 121*4882a593Smuzhiyunand has special instructions for the s/w associated with it. This structure is 122*4882a593Smuzhiyundescribed in this table:: 123*4882a593Smuzhiyun 124*4882a593Smuzhiyun ----------------------------------------------------------------------- 125*4882a593Smuzhiyun | Bit # | Name | Description | 126*4882a593Smuzhiyun ----------------------------------------------------------------------- 127*4882a593Smuzhiyun | 0 | General | Indicates that prior to each host command | 128*4882a593Smuzhiyun | | push command | given by the application, the software must | 129*4882a593Smuzhiyun | | | assert a special host command (push command)| 130*4882a593Smuzhiyun | | | CECDR = 0x00800000. | 131*4882a593Smuzhiyun | | | CECR = 0x01c1000f. | 132*4882a593Smuzhiyun ----------------------------------------------------------------------- 133*4882a593Smuzhiyun | 1 | UCC ATM | Indicates that after issuing ATM RX INIT | 134*4882a593Smuzhiyun | | RX INIT | command, the host must issue another special| 135*4882a593Smuzhiyun | | push command | command (push command) and immediately | 136*4882a593Smuzhiyun | | | following that re-issue the ATM RX INIT | 137*4882a593Smuzhiyun | | | command. (This makes the sequence of | 138*4882a593Smuzhiyun | | | initializing the ATM receiver a sequence of | 139*4882a593Smuzhiyun | | | three host commands) | 140*4882a593Smuzhiyun | | | CECDR = 0x00800000. | 141*4882a593Smuzhiyun | | | CECR = 0x01c1000f. | 142*4882a593Smuzhiyun ----------------------------------------------------------------------- 143*4882a593Smuzhiyun | 2 | Add/remove | Indicates that following the specific host | 144*4882a593Smuzhiyun | | command | command: "Add/Remove entry in Hash Lookup | 145*4882a593Smuzhiyun | | validation | Table" used in Interworking setup, the user | 146*4882a593Smuzhiyun | | | must issue another command. | 147*4882a593Smuzhiyun | | | CECDR = 0xce000003. | 148*4882a593Smuzhiyun | | | CECR = 0x01c10f58. | 149*4882a593Smuzhiyun ----------------------------------------------------------------------- 150*4882a593Smuzhiyun | 3 | General push | Indicates that the s/w has to initialize | 151*4882a593Smuzhiyun | | command | some pointers in the Ethernet thread pages | 152*4882a593Smuzhiyun | | | which are used when Header Compression is | 153*4882a593Smuzhiyun | | | activated. The full details of these | 154*4882a593Smuzhiyun | | | pointers is located in the software drivers.| 155*4882a593Smuzhiyun ----------------------------------------------------------------------- 156*4882a593Smuzhiyun | 4 | General push | Indicates that after issuing Ethernet TX | 157*4882a593Smuzhiyun | | command | INIT command, user must issue this command | 158*4882a593Smuzhiyun | | | for each SNUM of Ethernet TX thread. | 159*4882a593Smuzhiyun | | | CECDR = 0x00800003. | 160*4882a593Smuzhiyun | | | CECR = 0x7'b{0}, 8'b{Enet TX thread SNUM}, | 161*4882a593Smuzhiyun | | | 1'b{1}, 12'b{0}, 4'b{1} | 162*4882a593Smuzhiyun ----------------------------------------------------------------------- 163*4882a593Smuzhiyun | 5 - 31 | N/A | Reserved, set to zero. | 164*4882a593Smuzhiyun ----------------------------------------------------------------------- 165*4882a593Smuzhiyun 166*4882a593SmuzhiyunV - Firmware Structure Layout 167*4882a593Smuzhiyun============================== 168*4882a593Smuzhiyun 169*4882a593SmuzhiyunQE microcode from Freescale is typically provided as a header file. This 170*4882a593Smuzhiyunheader file contains macros that define the microcode binary itself as well as 171*4882a593Smuzhiyunsome other data used in uploading that microcode. The format of these files 172*4882a593Smuzhiyundo not lend themselves to simple inclusion into other code. Hence, 173*4882a593Smuzhiyunthe need for a more portable format. This section defines that format. 174*4882a593Smuzhiyun 175*4882a593SmuzhiyunInstead of distributing a header file, the microcode and related data are 176*4882a593Smuzhiyunembedded into a binary blob. This blob is passed to the qe_upload_firmware() 177*4882a593Smuzhiyunfunction, which parses the blob and performs everything necessary to upload 178*4882a593Smuzhiyunthe microcode. 179*4882a593Smuzhiyun 180*4882a593SmuzhiyunAll integers are big-endian. See the comments for function 181*4882a593Smuzhiyunqe_upload_firmware() for up-to-date implementation information. 182*4882a593Smuzhiyun 183*4882a593SmuzhiyunThis structure supports versioning, where the version of the structure is 184*4882a593Smuzhiyunembedded into the structure itself. To ensure forward and backwards 185*4882a593Smuzhiyuncompatibility, all versions of the structure must use the same 'qe_header' 186*4882a593Smuzhiyunstructure at the beginning. 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun'header' (type: struct qe_header): 189*4882a593Smuzhiyun The 'length' field is the size, in bytes, of the entire structure, 190*4882a593Smuzhiyun including all the microcode embedded in it, as well as the CRC (if 191*4882a593Smuzhiyun present). 192*4882a593Smuzhiyun 193*4882a593Smuzhiyun The 'magic' field is an array of three bytes that contains the letters 194*4882a593Smuzhiyun 'Q', 'E', and 'F'. This is an identifier that indicates that this 195*4882a593Smuzhiyun structure is a QE Firmware structure. 196*4882a593Smuzhiyun 197*4882a593Smuzhiyun The 'version' field is a single byte that indicates the version of this 198*4882a593Smuzhiyun structure. If the layout of the structure should ever need to be 199*4882a593Smuzhiyun changed to add support for additional types of microcode, then the 200*4882a593Smuzhiyun version number should also be changed. 201*4882a593Smuzhiyun 202*4882a593SmuzhiyunThe 'id' field is a null-terminated string(suitable for printing) that 203*4882a593Smuzhiyunidentifies the firmware. 204*4882a593Smuzhiyun 205*4882a593SmuzhiyunThe 'count' field indicates the number of 'microcode' structures. There 206*4882a593Smuzhiyunmust be one and only one 'microcode' structure for each RISC processor. 207*4882a593SmuzhiyunTherefore, this field also represents the number of RISC processors for this 208*4882a593SmuzhiyunSOC. 209*4882a593Smuzhiyun 210*4882a593SmuzhiyunThe 'soc' structure contains the SOC numbers and revisions used to match 211*4882a593Smuzhiyunthe microcode to the SOC itself. Normally, the microcode loader should 212*4882a593Smuzhiyuncheck the data in this structure with the SOC number and revisions, and 213*4882a593Smuzhiyunonly upload the microcode if there's a match. However, this check is not 214*4882a593Smuzhiyunmade on all platforms. 215*4882a593Smuzhiyun 216*4882a593SmuzhiyunAlthough it is not recommended, you can specify '0' in the soc.model 217*4882a593Smuzhiyunfield to skip matching SOCs altogether. 218*4882a593Smuzhiyun 219*4882a593SmuzhiyunThe 'model' field is a 16-bit number that matches the actual SOC. The 220*4882a593Smuzhiyun'major' and 'minor' fields are the major and minor revision numbers, 221*4882a593Smuzhiyunrespectively, of the SOC. 222*4882a593Smuzhiyun 223*4882a593SmuzhiyunFor example, to match the 8323, revision 1.0:: 224*4882a593Smuzhiyun 225*4882a593Smuzhiyun soc.model = 8323 226*4882a593Smuzhiyun soc.major = 1 227*4882a593Smuzhiyun soc.minor = 0 228*4882a593Smuzhiyun 229*4882a593Smuzhiyun'padding' is necessary for structure alignment. This field ensures that the 230*4882a593Smuzhiyun'extended_modes' field is aligned on a 64-bit boundary. 231*4882a593Smuzhiyun 232*4882a593Smuzhiyun'extended_modes' is a bitfield that defines special functionality which has an 233*4882a593Smuzhiyunimpact on the device drivers. Each bit has its own impact and has special 234*4882a593Smuzhiyuninstructions for the driver associated with it. This field is stored in 235*4882a593Smuzhiyunthe QE library and available to any driver that calles qe_get_firmware_info(). 236*4882a593Smuzhiyun 237*4882a593Smuzhiyun'vtraps' is an array of 8 words that contain virtual trap values for each 238*4882a593Smuzhiyunvirtual traps. As with 'extended_modes', this field is stored in the QE 239*4882a593Smuzhiyunlibrary and available to any driver that calles qe_get_firmware_info(). 240*4882a593Smuzhiyun 241*4882a593Smuzhiyun'microcode' (type: struct qe_microcode): 242*4882a593Smuzhiyun For each RISC processor there is one 'microcode' structure. The first 243*4882a593Smuzhiyun 'microcode' structure is for the first RISC, and so on. 244*4882a593Smuzhiyun 245*4882a593Smuzhiyun The 'id' field is a null-terminated string suitable for printing that 246*4882a593Smuzhiyun identifies this particular microcode. 247*4882a593Smuzhiyun 248*4882a593Smuzhiyun 'traps' is an array of 16 words that contain hardware trap values 249*4882a593Smuzhiyun for each of the 16 traps. If trap[i] is 0, then this particular 250*4882a593Smuzhiyun trap is to be ignored (i.e. not written to TIBCR[i]). The entire value 251*4882a593Smuzhiyun is written as-is to the TIBCR[i] register, so be sure to set the EN 252*4882a593Smuzhiyun and T_IBP bits if necessary. 253*4882a593Smuzhiyun 254*4882a593Smuzhiyun 'eccr' is the value to program into the ECCR register. 255*4882a593Smuzhiyun 256*4882a593Smuzhiyun 'iram_offset' is the offset into IRAM to start writing the 257*4882a593Smuzhiyun microcode. 258*4882a593Smuzhiyun 259*4882a593Smuzhiyun 'count' is the number of 32-bit words in the microcode. 260*4882a593Smuzhiyun 261*4882a593Smuzhiyun 'code_offset' is the offset, in bytes, from the beginning of this 262*4882a593Smuzhiyun structure where the microcode itself can be found. The first 263*4882a593Smuzhiyun microcode binary should be located immediately after the 'microcode' 264*4882a593Smuzhiyun array. 265*4882a593Smuzhiyun 266*4882a593Smuzhiyun 'major', 'minor', and 'revision' are the major, minor, and revision 267*4882a593Smuzhiyun version numbers, respectively, of the microcode. If all values are 0, 268*4882a593Smuzhiyun then these fields are ignored. 269*4882a593Smuzhiyun 270*4882a593Smuzhiyun 'reserved' is necessary for structure alignment. Since 'microcode' 271*4882a593Smuzhiyun is an array, the 64-bit 'extended_modes' field needs to be aligned 272*4882a593Smuzhiyun on a 64-bit boundary, and this can only happen if the size of 273*4882a593Smuzhiyun 'microcode' is a multiple of 8 bytes. To ensure that, we add 274*4882a593Smuzhiyun 'reserved'. 275*4882a593Smuzhiyun 276*4882a593SmuzhiyunAfter the last microcode is a 32-bit CRC. It can be calculated using 277*4882a593Smuzhiyunthis algorithm:: 278*4882a593Smuzhiyun 279*4882a593Smuzhiyun u32 crc32(const u8 *p, unsigned int len) 280*4882a593Smuzhiyun { 281*4882a593Smuzhiyun unsigned int i; 282*4882a593Smuzhiyun u32 crc = 0; 283*4882a593Smuzhiyun 284*4882a593Smuzhiyun while (len--) { 285*4882a593Smuzhiyun crc ^= *p++; 286*4882a593Smuzhiyun for (i = 0; i < 8; i++) 287*4882a593Smuzhiyun crc = (crc >> 1) ^ ((crc & 1) ? 0xedb88320 : 0); 288*4882a593Smuzhiyun } 289*4882a593Smuzhiyun return crc; 290*4882a593Smuzhiyun } 291*4882a593Smuzhiyun 292*4882a593SmuzhiyunVI - Sample Code for Creating Firmware Files 293*4882a593Smuzhiyun============================================ 294*4882a593Smuzhiyun 295*4882a593SmuzhiyunA Python program that creates firmware binaries from the header files normally 296*4882a593Smuzhiyundistributed by Freescale can be found on http://opensource.freescale.com. 297