using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; public class BdiAcc { public const UInt16 INIT_PPC_NOP = 0; public const UInt16 INIT_PPC_DELAY = 1; public const UInt16 INIT_PPC_WM8 = 2; /* write a 8bit value to target memory */ public const UInt16 INIT_PPC_WM16 = 3; /* write a 16bit value to target memory */ public const UInt16 INIT_PPC_WM32 = 4; /* write a 32bit value to target memory */ public const UInt16 INIT_PPC_WGPR = 5; /* write to a GPR */ public const UInt16 INIT_PPC_WSPR = 6; /* write to a SPR */ public const UInt16 INIT_PPC_WMSR = 7; /* write to the MSR */ public const UInt16 INIT_PPC_WCR = 8; /* write to the CR */ public const UInt16 INIT_PPC_SUPM = 9; /* set the addresses of MCR MDR */ public const UInt16 INIT_PPC_WUPM = 10; /* writes an entry into the UPM RAM array */ public const UInt16 INIT_PPC_TSZ1 = 11; /* COP: maximal transfer size 1 byte */ public const UInt16 INIT_PPC_TSZ2 = 12; /* COP: maximal transfer size 2 byte */ public const UInt16 INIT_PPC_TSZ4 = 13; /* COP: maximal transfer size 4 byte */ public const UInt16 INIT_PPC_TSZ8 = 14; /* COP: maximal transfer size 8 byte */ public const UInt16 INIT_COP_MMAP = 15; /* COP: define a valid memory range */ public const UInt16 INIT_PPC_WM64 = 16; /* COP: write a 64 bit value to target memory */ public const UInt16 INIT_PPC_WDCR = 9; /* PPC400: device control register */ public const UInt16 INIT_PPC_MMAP = 10; /* PPC400: define a valid memory range */ public const UInt16 INIT_PPC_WTLB = 11; /* PPC440: add a TLB entry */ public const UInt16 INIT_PPC_RM8 = 12; /* PPC400: read a 8bit value from target memory */ public const UInt16 INIT_PPC_RM16 = 13; /* PPC400: read a 16bit value from target memory */ public const UInt16 INIT_PPC_RM32 = 14; /* PPC400: read a 32bit value from target memory */ public const UInt16 INIT_PPC_STLB = 15; /* PPC440: setup Index, PID and flags in TLB Word 2 */ public const UInt16 INIT_PPC_WIAR = 16; /* PPC440: set instruction address register (PC) */ public const UInt16 FLASH_AM29F0X0 = 2; /* e.g. Am29F010, Am29F040 */ public const UInt16 FLASH_AM29F = 2; public const UInt16 FLASH_I28FBXB = 5; /* e.g. i28F001BX, i28F400BX (byte-mode) */ public const UInt16 FLASH_I28BX8 = 5; public const UInt16 FLASH_I28FBXW = 6; /* e.g. i28F400BX (word-mode) */ public const UInt16 FLASH_I28BX16 = 6; public const UInt16 FLASH_AM29FX00B = 11; /* e.g. Am29F100 (byte-mode) */ public const UInt16 FLASH_AM29BX8 = 11; public const UInt16 FLASH_AM29FX00W = 12; /* e.g. Am29F100 (word-mode) */ public const UInt16 FLASH_AM29BX16 = 12; public const UInt16 HC12_EEPROM = 14; /* HC12 internal EEPROM */ public const UInt16 HC12_FLASH = 15; /* HC12 internal Flash */ public const UInt16 MPC555_FLASH = 16; /* MPC555 flash array */ public const UInt16 MPC555_SHADOW = 17; /* MPC555 flash shadow information */ public const UInt16 HC12A_EEPROM = 18; /* internal EEPROM of HC12A targets */ public const UInt16 HC12A_FLASH = 19; /* internal Flash of HC12A targets */ public const UInt16 STAR12_EEPROM = 20; /* internal EEPROM of STAR12 targets */ public const UInt16 STAR12_FLASH = 21; /* internal Flash of STAR2 targets */ public const UInt16 MCORE_SGFM = 21; /* internal Flash of MMC2114,MMC2113 */ public const UInt16 FLASH_AT49 = 22; /* Atmel AT49 byte mode only chip */ public const UInt16 FLASH_AT49X8 = 23; /* Atmel AT49 byte/word chip in byte mode */ public const UInt16 FLASH_AT49X16 = 24; /* Atmel AT49 byte/word chip in word mode */ public const UInt16 UC3F_FLASH = 25; /* UC3F flash array */ public const UInt16 UC3F_SHADOW = 26; /* UC3F shadow information */ public const UInt16 FLASH_STRATAX8 = 29; /* Intel StrataFlash x8 mode */ public const UInt16 FLASH_STRATAX16 = 30; /* Intel StrataFlash x16 mode */ public const UInt16 FLASH_MIRROR = 31; /* AMD MirrorBit Flash byte mode only chip */ public const UInt16 FLASH_MIRRORX8 = 32; /* AMD MirrorBit Flash byte/word chip in byte mode */ public const UInt16 FLASH_MIRRORX16 = 33; /* AMD MirrorBit Flash byte/word chip in word mode */ public const UInt16 FLASH_I28FBXD = 34; /* Intel algorithm for x32 chip */ public const UInt16 FLASH_AM29DX16 = 35; /* AMD x32 chip in x16 mode */ public const UInt16 FLASH_AM29DX32 = 36; /* AMD x32 chip in x32 mode */ public const UInt16 FLASH_AM29BDDX16 = 37; /* Am29BDD160G chip in x16 mode */ public const UInt16 FLASH_AM29BDDX32 = 38; /* Am29BDD160G chip in x32 mode */ public const UInt16 FLASH_CFM = 39; /* ColdFire Flash Module (MCF5282) */ public const UInt16 FLASH_CFM32 = 40; /* MAC7100 Code Flash Module */ public const UInt16 FLASH_CFM16 = 41; /* MAC7100 Data Flash Module */ public const UInt16 FLASH_LPC2000 = 42; /* Philips LPC2000 Flash Module */ public const UInt16 FLASH_LPC1000 = 42; /* Philips LPC1000 Flash Module */ public const UInt16 FLASH_STA2051 = 43; /* ST STA2051 internal flash */ public const UInt16 FLASH_STR710 = 43; /* ST STR71x internal flash */ public const UInt16 FLASH_ADUC7000 = 44; /* Analog Device ADuC7000 internal flash */ public const UInt16 FLASH_ST30F = 45; /* ST ST30F internal flash */ public const UInt16 FLASH_AT91SAM7S = 46; /* Atmel AT91SAM7Sxx internal flash */ public const UInt16 FLASH_S29M64X8 = 47; /* Spansion MirrorBit Flash 64 byte write buffer */ public const UInt16 FLASH_S29M32X16 = 48; /* Spansion MirrorBit Flash 32 word write buffer */ public const UInt16 FLASH_STR910F = 49; /* ST STR91xF internal flash */ public const UInt16 FLASH_H7F = 50; /* MPC55xx flash array */ public const UInt16 S12XE_PFLASH = 51; /* S12XE FTM P-Flash */ public const UInt16 S12XE_DFLASH = 52; /* S12XE FTM D-Flash */ public const UInt16 FLASH_STM32F10 = 53; /* ST STM32F10xxx internal flash */ public const UInt16 FLASH_LM3S = 54; /* Luminary Micro Stellaris internal flash */ public const UInt16 FLASH_S29WSRX16 = 55; /* Spansion S29WS-R */ public const UInt16 FLASH_SAM9XE = 56; /* Atmel AT91SAM9XE internal flash */ public const UInt16 FLASH_SAM7L = 57; /* Atmel AT91SAM7L internal flash */ public const UInt16 FLASH_STM32L15 = 58; /* ST STM32L15xxx internal flash */ public const UInt16 FLASH_EFM32 = 59; /* Energy Micro EFM32 internal flash */ public const UInt16 FLASH_FTFL = 60; /* Freescale Kinetis FTFL flash */ [DllImport("bdiifc32.dll", CharSet = CharSet.Ansi)] public unsafe static extern int BDI_Connect( char* parameter); [DllImport("bdiifc32.dll", CharSet = CharSet.Ansi)] public unsafe static extern int BDI_Disconnect(); [DllImport("bdiifc32.dll", CharSet = CharSet.Ansi)] public unsafe static extern int BDI_InitListReset(); [DllImport("bdiifc32.dll", CharSet = CharSet.Ansi)] public unsafe static extern int BDI_InitListAdd( UInt16 command, UInt32 address, UInt32 value); [DllImport("bdiifc32.dll", CharSet = CharSet.Ansi)] public unsafe static extern int BDI_TargetStartup( UInt16 resetTime, UInt32 cpuClock, UInt16 initCount, UIntPtr pInitList); [DllImport("bdiifc32.dll", CharSet = CharSet.Ansi)] public unsafe static extern int BDI_FlashSetType( UInt16 flashType, UInt32 flashSize, UInt16 pageSize, UInt16 memoryWidth, UInt32 workSpace); [DllImport("bdiifc32.dll", CharSet = CharSet.Ansi)] public unsafe static extern int BDI_FlashEraseSector( UInt32 address); [DllImport("bdiifc32.dll", CharSet = CharSet.Ansi)] public unsafe static extern int BDI_FlashWriteFile( char* fileName, UInt32* errorAddr); [DllImport("bdiifc32.dll", CharSet = CharSet.Ansi)] public unsafe static extern int BDI_FlashWriteBinary( char* fileName, UInt32 startAddr, UInt32* errorAddr); [DllImport("bdiifc32.dll", CharSet = CharSet.Ansi)] public unsafe static extern int BDI_VerifyBinary( char* fileName, UInt32 startAddr, UInt32* errorAddr); } namespace MyConsole { class Hello { static unsafe void Main() { int result; UInt32 errorAddr; // Connect to BDI2000 result = BdiAcc.BDI_Connect((char*)Marshal.StringToHGlobalAnsi("NETWORK BDI2000")); if (result == 0) { Console.WriteLine("BDI successful connected!"); } else { Console.WriteLine("BDI connection failed!"); Console.WriteLine("Press any key to exit."); Console.ReadKey(); return; } // set flash type for AMCC 440EP Evaluation Kit "Yosemite" result = BdiAcc.BDI_FlashSetType( BdiAcc.FLASH_MIRRORX16, 0x04000000, 0, 16, 0x00004000); // prepare Init List for AMCC 440EP Evaluation Kit "Yosemite" result = BdiAcc.BDI_InitListReset(); result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WSPR, 8007, 500 ); // Wake-up delay 500 ms result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WSPR, 8009, 8 ); // Set IR length to 8 for 440EP // === Setup TLB === result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WTLB, 0xF000009D, 0x0F00003F); // TLB: Map Boot Space 256MB result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WTLB, 0x0000009C, 0x0000003F); // TLB: Map SDRAM 256MB @ 0x00000000 result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WTLB, 0xE000009D, 0x0E00001B); // TLB: Registers 256MB result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WTLB, 0x8000009D, 0x0800003F); // TLB: BCSR NVRAM 256MB // === Setup Peripheral Bus === result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 18, 0x00000010); // Select EBC0_B0AP result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 19, 0x03017300); // B0AP: Flash result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 18, 0x00000000); // Select EBC0_B0CR result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 19, 0xFC0DA000); // B0CR: 64MB at 0xFC000000, r/w, 16bit result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 18, 0x00000012); // Select EBC0_B2AP result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 19, 0x04814500); // B2AP: BCSR NVRAM result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 18, 0x00000002); // Select EBC0_B2CR result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 19, 0x80018000); // B2CR: 1MB at 0x80000000, r/w, 8bit result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WM32, 0xEF600B08, 0x50010000); // GPIO0_OSRL : Enable PerAddr07/06, CS2 (64Meg FLASH) result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WM32, 0xEF600B10, 0x50010000); // GPIO0_TSRL : Enable PerAddr07/06, CS2 result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WM32, 0xEF600B30, 0x50000000); // GPIO0_ISR1L: Enable PerAddr07/06 // === Setup SDRAM Controller === result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 16, 0x00000082); // Select SDRAM0_CLKTR result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 17, 0x40000000); // CLKTR: Advance 90 degrees result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 16, 0x00000080); // Select SDRAM0_TR0 result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 17, 0x410A4012); // TR0: result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 16, 0x00000081); // Select SDRAM0_TR1 result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 17, 0x80800840); // TR1: result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 16, 0x00000040); // Select SDRAM0_B0CR result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 17, 0x000A4001); // B0CR: result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 16, 0x00000044); // Select SDRAM0_B1CR result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 17, 0x080A4001); // B1CR: result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 16, 0x00000030); // Select SDRAM0_RTR result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 17, 0x04080000); // RTR: result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 16, 0x00000020); // Select SDRAM0_CFG0 result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 17, 0x04000000); // CFG0: 32bit, PMU disable result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WDCR, 17, 0x84000000); // CFG0: enable SDRAM result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_DELAY, 0, 100 ); // === Clear DBCR1 and DBCR2 == result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WSPR, 309, 0x00000000); // DBCR1 result = BdiAcc.BDI_InitListAdd(BdiAcc.INIT_PPC_WSPR, 310, 0x00000000); // DBCR2 // PPC440, 16 MHz JTAG clock result = BdiAcc.BDI_TargetStartup(100, (3<<8) | 0, 0, (UIntPtr)0); /* erase flash */ Console.Write("erasing ... "); result = BdiAcc.BDI_FlashEraseSector(0xfff80000); result = BdiAcc.BDI_FlashEraseSector(0xfffa0000); result = BdiAcc.BDI_FlashEraseSector(0xfffc0000); result = BdiAcc.BDI_FlashEraseSector(0xfffe0000); if (result == 0) Console.WriteLine("passed"); else Console.WriteLine("failed"); Console.Write("programming..."); result = BdiAcc.BDI_FlashWriteBinary( (char*)Marshal.StringToHGlobalAnsi("C:/temp/uboot_440ep.bin"), 0xfff80000, &errorAddr); if (result == 0) Console.WriteLine("passed"); else Console.WriteLine("failed"); Console.Write("verifying..."); result = BdiAcc.BDI_FlashWriteBinary( (char*)Marshal.StringToHGlobalAnsi("C:/temp/uboot_440ep.bin"), 0xfff80000, &errorAddr); if (result == 0) Console.WriteLine("passed"); else Console.WriteLine("failed"); // Disconnect from BDI2000 result = BdiAcc.BDI_Disconnect(); // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } }