📄 btscriptgen.c
字号:
/*
*
* Copyright (C) 2005 Koninklijke Philips Electronics N.V.,
* Copyright 2004, 2005 Momentum Data Systems, Inc.
* All Rights Reserved
*
* DESCRIPTION: This program creates various boot scripts for the pnx1x00. Each boot script
* is specified in a function found here. The shell takes inputs from command
* line and dispatches the various script functions.
*
* See chapter 6 of the pnx1500 data book for more info.
*
* This program is designed to be easily compiled with any C compiler.
*
* It is in one file and has no special library dependencies.
*
* It generates 3 basic types of boot scripts:
* - hosted (just set the memory speeds)
* - JTAG (load the small L1 program from EEPROM)
* - FLASH (load the small L1 program from flash using DMA
*
* The attempt is made to parameterize it.
* Users can feel free to modify it as necessary.
*
*/
/*
TODO:
- move globals into the "this" struct
- improve help text output (allowed frequencies, etc.)
- add script comments to text out versions of jtag, nor and nand script
- Merge code
writePciSetup (differs for hosted or not hosted)
writeXioProfiles (currently not done for PCI and jtag)
*/
//-----------------------------------------------------------------------------
// Include files:
//-----------------------------------------------------------------------------
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <io.h>
#include <fcntl.h>
#include <string.h>
#include "register.h"
#include "BoardId.h"
//-----------------------------------------------------------------------------
// Types and defines:
//-----------------------------------------------------------------------------
typedef unsigned char UInt8 ;
typedef unsigned long UInt32 ;
typedef int bool;
#define false 0
#define true (!false)
// Maximum values
#define MAX_EEPROM_SIZE (1024 * 128)
#define MAX_FILE_NAME_SIZE (512)
#define MAX_XIO_PROFILES (5) // NOTE! modifying this value alone is not enough. See where it is used!
// Error codes. They are used bitwise
#define ERR_HOSTSCRIPT_WRITE 1
#define ERR_JTAGSCRIPT_WRITE 2
#define ERR_NORSCRIPT_WRITE 4
#define ERR_NANDSCRIPT_WRITE 8
#define ERR_COMMAND_LINE 32
#define ERR_PRINT_HELP 64
#define ERR_MAC_ADDR 128
#define ERR_BOARD_ID 256
#define NORprofile (en_16bit_xio | \
0<<we_hi_shift | \
3<<we_lo_shift | \
5<<wait_shift | \
0<<offset_shift | \
type_NOR | \
size16M | \
en_profile )
#define NANDprofile (en_8bit_xio | \
use_ack | \
0<<ren_hi_shift | \
1<<ren_lo_shift | \
0<<wen_hi_shift | \
1<<wen_lo_shift | \
15<<wait_shift | \
4<<offset_shift | \
type_NAND | \
size32M | \
en_profile )
//-----------------------------------------------------------------------------
// Global data:
//-----------------------------------------------------------------------------
//
static char *g_btscriptText =
"-----------------------------------------------------------------------------\n"
"//\n"
"// This file has been generated.\n"
"//\n"
"// Use the BtScript.exe (in common/tools) to convert this text file to \n"
"// a raw binary image for the IIC EPROM.\n"
"//\n"
"// Usage: btscript text.iic out.raw [/h:nnn|/t:mmm]\n"
"//\n"
"// /h:nnn - number of zero bytes to add in the beginning of the image.\n"
"// /t:mmm - number of zero bytes to add in the end of the image.\n"
"// \n"
"// Remember that the image is located in address 1 in the EPROM if the \n"
"// EPROM size is smaller then 2048 bytes.\n"
"// \n"
"// The following is format (See example bellow) of the this text file:\n"
"// \n"
"// The supported commands are -\n"
"// \n"
"// write addr value\n"
"// writefile file_name addr\n"
"// writelist addr length (followed by length words of data)\n"
"// delay ticksNumber\n"
"//\n"
"// Example -\n"
"//\n"
"// For the ATMEL002 24C08 (DIP) part we need to start the image at \n"
"// address 1, so we add one byte in the beginning of the image:\n"
"// \n"
"// >btscript bootle.iic bootle.bsc /h:1\n"
"//\n"
"// Then program the bootle.bsc raw file into the part on the EPROM \n"
"// programmer.\n"
"//\n"
"// -----------------------------------------------------------------------------\n";
//TODO move these globals into the "this" struct.
UInt32 ibuffer[MAX_EEPROM_SIZE/4] ; // used for reading in JTAG memory image
static char host_file_name[MAX_FILE_NAME_SIZE] = "host.eep";
static char jtag_file_name[MAX_FILE_NAME_SIZE] = "jtag.eep";
static char nor_file_name[MAX_FILE_NAME_SIZE] = "nor.eep";
static char nand_file_name[MAX_FILE_NAME_SIZE] = "nand.eep";
static char ide_file_name[MAX_FILE_NAME_SIZE] = "ide.eep";
// These statics struct will be set by command line and are given with defaults:
struct scriptData_t
{
UInt32 fileOutputAsText;
char uP_type[MAX_FILE_NAME_SIZE];
char brd_name[MAX_FILE_NAME_SIZE];
UInt32 board_id;
char jtagmon_mi_file_name[MAX_FILE_NAME_SIZE];
UInt32 profile[MAX_XIO_PROFILES];
UInt32 sdram_base;
UInt32 sdram_limit;
UInt32 cacheable_limit;
UInt32 xio_base;
UInt32 mmio_base;
UInt32 uBTM_start;
UInt32 cpu_speed;
UInt32 ddr_speed;
UInt8 mac_address[6];
} this =
{
0, // fileOutputAsText == false
"pnx1500", // uP type
"lcp", // board name
0, // board id
"l1jtag.mi", // filename of jtagmon .mi file
{NORprofile, 0, 0,NANDprofile, 0}, // xio profile values. 0=NOR, 3=NAND.
0x00000000, // sdram_base
0x04000000, // sdram_limit 64M
0x04000000, // cacheable_limit all memory cached by default
0x10000000, // xio_base
0x1be00000, // mmio_base
0x00100000, // uBTM_start
300, // cpu_speed
200, // ddr_speed
{ 00u, 0x50u, 0xc2u, 0x19u, 0x50u, 0x7bu } // mac_address
};
/*
* script globals
*/
FILE *scriptFile ;
UInt32 scriptBytes ;
//-----------------------------------------------------------------------------
// Internal Prototypes:
//-----------------------------------------------------------------------------
//
static int writeHostScript( char *file_name, UInt32 sdram_base, UInt32 sdram_limit,
UInt32 cacheable_limit, UInt32 uBTM_start, UInt32 xio_base,
UInt32 mmio_base, UInt32 cpu_speed, UInt32 ddr_speed,
UInt8 *mac_address);
static int writeJTAGScript( char *file_name, UInt32 sdram_base, UInt32 sdram_limit,
UInt32 cacheable_limit, UInt32 uBTM_start, UInt32 xio_base,
UInt32 mmio_base, UInt32 cpu_speed, UInt32 ddr_speed,
UInt8 *mac_address, char *mi_file_name);
static int writeNorScript( char *file_name, UInt32 sdram_base, UInt32 sdram_limit,
UInt32 cacheable_limit, UInt32 uBTM_start, UInt32 xio_base,
UInt32 mmio_base, UInt32 cpu_speed, UInt32 ddr_speed,
UInt8 *mac_address);
static int writeNandScript( char *file_name, UInt32 sdram_base, UInt32 sdram_limit,
UInt32 cacheable_limit, UInt32 uBTM_start, UInt32 xio_base,
UInt32 mmio_base, UInt32 cpu_speed, UInt32 ddr_speed,
UInt8 *mac_address);
static void scriptComment(char *text);
static void scriptByte(UInt8 data);
static void scriptWord(UInt32 data);
static void scriptWriteSingle(UInt32 address, UInt32 data);
static void scriptDelayCycles(UInt32 cycles);
static void scriptDelaySeconds(float seconds);
static void writeMacAddress(UInt8 *mac_address, UInt32 mmio_base) ;
static void writeClocks(UInt32 cpu_speed, UInt32 ddr_speed, UInt32 mmio_base) ;
static void setupPCI(UInt32 sdram_limit, UInt32 mmio_base, bool master) ;
static int read_file(UInt8 *buffer, char *filename);
void scriptWriteCode(UInt32 address, UInt32 *data, UInt32 count) ;
static void printHelp(void);
static UInt32 FindPllFrequency(UInt32 frequency);
static int CheckArgcv (int argc, char **argv);
static int SetBoardID(char *brd_name, char *uP_type);
static UInt32 ClockGetMNPValues(UInt32 frequency);
#define PCI_MASTER 1
#define PCI_HOST 0
//-----------------------------------------------------------------------------
// Main Entry Point
//-----------------------------------------------------------------------------
//
int main(int argc, char **argv)
{
int rval;
rval = CheckArgcv(argc, argv);
if (rval != 0)
{
}
else
{
printf("\nBuilding boot scripts\n");
printf("Key constants defined in the program are:\n");
printf("\tSDRAM_BASE 0x%08X\n", this.sdram_base );
printf("\tSDRAM_LIMIT 0x%08X\n", this.sdram_limit );
printf("\tCACHEABLE_LIMIT 0x%08x\n", this.cacheable_limit);
printf("\tUBTM_PGM_BASE 0x%08X\n", this.uBTM_start );
printf("\tXIO_BASE 0x%08X\n", this.xio_base );
printf("\tMMIO_BASE 0x%08X\n", this.mmio_base );
printf("\tCPU Speed %d Mhz\n", this.cpu_speed);
printf("\tRAM Speed %d Mhz\n", this.ddr_speed);
printf("\tMAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
this.mac_address[0], this.mac_address[1], this.mac_address[2],
this.mac_address[3], this.mac_address[4], this.mac_address[5]);
printf ("\tBOARD_ID 0x%08x\n", this.board_id);
printf("\nWriting the following files:\n");
printf("\thost script %s\n", host_file_name);
printf("\tJTAG script %s\n", jtag_file_name);
printf("\tNOR script %s\n", nor_file_name);
printf("\tNAND script %s\n", nand_file_name);
// printf("\tIDE script %s\n", ide_file_name);
printf("\n");
// set a different bit for failure. Allows some to run if others fail...
rval = 0;
rval |= writeHostScript(host_file_name, this.sdram_base, this.sdram_limit, this.cacheable_limit,
this.uBTM_start, this.xio_base, this.mmio_base, this.cpu_speed, this.ddr_speed, this.mac_address);
rval |= writeJTAGScript(jtag_file_name, this.sdram_base, this.sdram_limit, this.cacheable_limit,
this.uBTM_start, this.xio_base, this.mmio_base, this.cpu_speed, this.ddr_speed,
this.mac_address, this.jtagmon_mi_file_name);
rval |= writeNorScript(nor_file_name, this.sdram_base, this.sdram_limit, this.cacheable_limit,
this.uBTM_start, this.xio_base, this.mmio_base, this.cpu_speed, this.ddr_speed, this.mac_address);
rval |= writeNandScript(nand_file_name, this.sdram_base, this.sdram_limit, this.cacheable_limit,
this.uBTM_start, this.xio_base, this.mmio_base, this.cpu_speed, this.ddr_speed, this.mac_address);
// writeIdeScript(ide_file_name, sdram_base, sdram_limit, cacheable_limit,
// uBTM_start, xio_base, mmio_base, cpu_speed, ddr_speed, mac_address);
}
return (rval);
} // End of main().
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -