From 08dadd4f3e71a4e932e271d10381838d0d2e9166 Mon Sep 17 00:00:00 2001 From: MiGeRA Date: Thu, 17 Mar 2022 21:56:45 +0300 Subject: [PATCH] Added MX29LV320 support --- flashkit-md/Device.cs | 261 ++++++++++++++++++++- flashkit-md/Form1.Designer.cs | 121 +++++++--- flashkit-md/Form1.cs | 303 +++++++++++++++++++++++-- flashkit-md/Properties/AssemblyInfo.cs | 4 +- 4 files changed, 636 insertions(+), 53 deletions(-) diff --git a/flashkit-md/Device.cs b/flashkit-md/Device.cs index a070523..ae87ac7 100644 --- a/flashkit-md/Device.cs +++ b/flashkit-md/Device.cs @@ -186,7 +186,7 @@ public static void read(byte[] buff, int offset, int len) port.Write(cmd, 0, 5); - for (int i = 0; i < rd_len; ) + for (int i = 0; i < rd_len;) { i += port.Read(buff, offset + i, rd_len - i); } @@ -488,14 +488,14 @@ static Byte flash29lSRD() // Return Status Register value data (inside use): bit } - public static void flash29lErase(int addr) + public static void flash29lErase(int addr) // addr to word-mode !!! (linear / 2) { Device.writeByte(0x5555 * 2, 0xaa); Device.writeByte(0x2aaa * 2, 0x55); Device.writeByte(0x5555 * 2, 0x80); Device.writeByte(0x5555 * 2, 0xaa); Device.writeByte(0x2aaa * 2, 0x55); - Device.writeByte(addr, 0x30); // addr to word, as if already *2 + Device.writeByte(addr * 2, 0x30); while ((Device.getSR() & 0x80) == 0) { Device.setDelay(1); } // Fastest than Device.flash29lSRD() if ((Device.getSR() & 0x10) != 0) throw new Exception("Erase error ..."); @@ -609,5 +609,260 @@ static void flash29lWritePref(int addr) } + public static void flash29lvReset() // Reset and set Read-mode + { + Device.writeByte(0, 0xf0); // any address + + } + + static void flash29lvAS() // Automatic Select + { + byte[] cmd = new byte[27]; + + int addr_1st = 0x555; + int addr_2nd = 0x2aa; + byte dat_1st = 0xaa; + byte dat_2nd = 0x55; + byte dat_wrt = 0x90; + + cmd[0] = CMD_ADDR; + cmd[1] = (byte)(addr_1st >> 16); + cmd[2] = CMD_ADDR; + cmd[3] = (byte)(addr_1st >> 8); + cmd[4] = CMD_ADDR; + cmd[5] = (byte)(addr_1st); + cmd[6] = CMD_WR | PAR_SINGLE | PAR_MODE8; + cmd[7] = dat_1st; + cmd[8] = CMD_RY; + + cmd[9] = CMD_ADDR; + cmd[10] = (byte)(addr_2nd >> 16); + cmd[11] = CMD_ADDR; + cmd[12] = (byte)(addr_2nd >> 8); + cmd[13] = CMD_ADDR; + cmd[14] = (byte)(addr_2nd); + cmd[15] = CMD_WR | PAR_SINGLE | PAR_MODE8; + cmd[16] = dat_2nd; + cmd[17] = CMD_RY; + + cmd[18] = CMD_ADDR; + cmd[19] = (byte)(addr_1st >> 16); + cmd[20] = CMD_ADDR; + cmd[21] = (byte)(addr_1st >> 8); + cmd[22] = CMD_ADDR; + cmd[23] = (byte)(addr_1st); + cmd[24] = CMD_WR | PAR_SINGLE | PAR_MODE8; + cmd[25] = dat_wrt; + cmd[26] = CMD_RY; + + port.Write(cmd, 0, cmd.Length); + + } + + public static UInt16 flash29lvIdentMfr() // return Manufacturer ID: 29LV320 -> 0x00C2 + { + Device.writeByte(0, 0xf0); + /* + Device.writeByte(0x555 * 2, 0xaa); + Device.writeByte(0x2aa * 2, 0x55); + Device.writeByte(0x555 * 2, 0x90); + */ + Device.flash29lvAS(); + return (Device.readWord(0)); + + } + + public static UInt16 flash29lvIdentDev() // return Device ID: 29LV320 -> 0x22A7 | 0x22A8 + { + Device.writeByte(0, 0xf0); + /* + Device.writeByte(0x555 * 2, 0xaa); + Device.writeByte(0x2aa * 2, 0x55); + Device.writeByte(0x555 * 2, 0x90); + */ + Device.flash29lvAS(); + return (Device.readWord(2)); + + } + + public static UInt16 flash29lvFactLock() // return Device ID: 29LV320 -> 0x22A7 | 0x22A8 + { + Device.writeByte(0, 0xf0); + /* + Device.writeByte(0x555 * 2, 0xaa); + Device.writeByte(0x2aa * 2, 0x55); + Device.writeByte(0x555 * 2, 0x90); + */ + Device.flash29lvAS(); + return (Device.readWord(6)); + + } + + public static UInt16 flash29lvProtStat(int addr) // return Device ID: 29LV320 -> 0x22A7 | 0x22A8 + { + Device.writeByte(0, 0xf0); + /* + Device.writeByte(0x555 * 2, 0xaa); + Device.writeByte(0x2aa * 2, 0x55); + Device.writeByte(0x555 * 2, 0x90); + */ + Device.flash29lvAS(); + return (Device.readWord(addr + 4)); + + } + + public static void flash29lvErase(int addr) // addr to word-mode !!! (linear / 2) + { + Device.writeByte(0x555 * 2, 0xaa); + Device.writeByte(0x2aa * 2, 0x55); + Device.writeByte(0x555 * 2, 0x80); + Device.writeByte(0x555 * 2, 0xaa); + Device.writeByte(0x2aa * 2, 0x55); + Device.writeByte(addr * 2, 0x30); + + while ((Device.getSR() & 0x80) == 0) + if (((Device.getSR() & 0x20) != 0) && ((Device.getSR() & 0x80) == 0)) throw new Exception("Erase error ..."); + + } + + public static void flash29lvEraseAll() + { + Device.writeByte(0x555 * 2, 0xaa); + Device.writeByte(0x2aa * 2, 0x55); + Device.writeByte(0x555 * 2, 0x80); + Device.writeByte(0x555 * 2, 0xaa); + Device.writeByte(0x2aa * 2, 0x55); + Device.writeByte(0x555 * 2, 0x10); + + while ((Device.getSR() & 0x80) == 0) + if (((Device.getSR() & 0x20) != 0) && ((Device.getSR() & 0x80) == 0)) throw new Exception("Erase error ..."); + + } + + public static void flash29lvProg(int addr, UInt16 data) // Write single 16-bit word + { + /* + Device.writeByte(0x555 * 2, 0xaa); + Device.writeByte(0x2aa * 2, 0x55); + Device.writeByte(0x555 * 2, 0xa0); + Device.writeWord(addr * 2, data); + Device.flashRY(); + */ + + byte[] cmd = new byte[37]; + + int addr_1st = 0x555; + int addr_2nd = 0x2aa; + byte dat_1st = 0xaa; + byte dat_2nd = 0x55; + byte dat_wrt = 0xa0; + + cmd[0] = CMD_ADDR; + cmd[1] = (byte)(addr_1st >> 16); + cmd[2] = CMD_ADDR; + cmd[3] = (byte)(addr_1st >> 8); + cmd[4] = CMD_ADDR; + cmd[5] = (byte)(addr_1st); + cmd[6] = CMD_WR | PAR_SINGLE | PAR_MODE8; + cmd[7] = dat_1st; + cmd[8] = CMD_RY; + + cmd[9] = CMD_ADDR; + cmd[10] = (byte)(addr_2nd >> 16); + cmd[11] = CMD_ADDR; + cmd[12] = (byte)(addr_2nd >> 8); + cmd[13] = CMD_ADDR; + cmd[14] = (byte)(addr_2nd); + cmd[15] = CMD_WR | PAR_SINGLE | PAR_MODE8; + cmd[16] = dat_2nd; + cmd[17] = CMD_RY; + + cmd[18] = CMD_ADDR; + cmd[19] = (byte)(addr_1st >> 16); + cmd[20] = CMD_ADDR; + cmd[21] = (byte)(addr_1st >> 8); + cmd[22] = CMD_ADDR; + cmd[23] = (byte)(addr_1st); + cmd[24] = CMD_WR | PAR_SINGLE | PAR_MODE8; + cmd[25] = dat_wrt; + cmd[26] = CMD_RY; + + cmd[27] = CMD_ADDR; + cmd[28] = (byte)(addr >> 16); + cmd[29] = CMD_ADDR; + cmd[30] = (byte)(addr >> 8); + cmd[31] = CMD_ADDR; + cmd[32] = (byte)(addr); + cmd[33] = CMD_WR | PAR_SINGLE; + cmd[34] = (byte)(data >> 8); + cmd[35] = (byte)(data); + cmd[36] = CMD_RY; + + port.Write(cmd, 0, cmd.Length); + + } + + public static void flash29lvWrite(byte[] buff, int offset, int len) + { + len /= 2; + byte[] cmd = new byte[37 * len]; + + int addr_1st = 0x555; + int addr_2nd = 0x2aa; + int addr_dat = offset / 2; + byte dat_1st = 0xaa; + byte dat_2nd = 0x55; + byte dat_wrt = 0xa0; + + for (int i = 0; i < cmd.Length; i += 37) + { + cmd[0 + i] = CMD_ADDR; + cmd[1 + i] = (byte)(addr_1st >> 16); + cmd[2 + i] = CMD_ADDR; + cmd[3 + i] = (byte)(addr_1st >> 8); + cmd[4 + i] = CMD_ADDR; + cmd[5 + i] = (byte)(addr_1st); + cmd[6 + i] = CMD_WR | PAR_SINGLE | PAR_MODE8; + cmd[7 + i] = dat_1st; + cmd[8 + i] = CMD_RY; + + cmd[9 + i] = CMD_ADDR; + cmd[10 + i] = (byte)(addr_2nd >> 16); + cmd[11 + i] = CMD_ADDR; + cmd[12 + i] = (byte)(addr_2nd >> 8); + cmd[13 + i] = CMD_ADDR; + cmd[14 + i] = (byte)(addr_2nd); + cmd[15 + i] = CMD_WR | PAR_SINGLE | PAR_MODE8; + cmd[16 + i] = dat_2nd; + cmd[17 + i] = CMD_RY; + + cmd[18 + i] = CMD_ADDR; + cmd[19 + i] = (byte)(addr_1st >> 16); + cmd[20 + i] = CMD_ADDR; + cmd[21 + i] = (byte)(addr_1st >> 8); + cmd[22 + i] = CMD_ADDR; + cmd[23 + i] = (byte)(addr_1st); + cmd[24 + i] = CMD_WR | PAR_SINGLE | PAR_MODE8; + cmd[25 + i] = dat_wrt; + cmd[26 + i] = CMD_RY; + + cmd[27 + i] = CMD_ADDR; + cmd[28 + i] = (byte)(addr_dat >> 16); + cmd[29 + i] = CMD_ADDR; + cmd[30 + i] = (byte)(addr_dat >> 8); + cmd[31 + i] = CMD_ADDR; + cmd[32 + i] = (byte)(addr_dat); + cmd[33 + i] = CMD_WR | PAR_SINGLE; + cmd[34 + i] = buff[offset++]; + cmd[35 + i] = buff[offset++]; + cmd[36 + i] = CMD_RY; + + addr_dat++; + } + + port.Write(cmd, 0, cmd.Length); + + } + } } diff --git a/flashkit-md/Form1.Designer.cs b/flashkit-md/Form1.Designer.cs index 6165cda..bfdab49 100644 --- a/flashkit-md/Form1.Designer.cs +++ b/flashkit-md/Form1.Designer.cs @@ -48,9 +48,14 @@ private void InitializeComponent() this.btn_erase29l = new System.Windows.Forms.Button(); this.btn_wr_rom29l = new System.Windows.Forms.Button(); this.btn_rd_rom29l = new System.Windows.Forms.Button(); + this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.btn_erase29lv = new System.Windows.Forms.Button(); + this.btn_wr_rom29lv = new System.Windows.Forms.Button(); + this.btn_rd_rom29lv = new System.Windows.Forms.Button(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); + this.groupBox4.SuspendLayout(); this.SuspendLayout(); // // btn_rd_rom @@ -58,7 +63,7 @@ private void InitializeComponent() this.btn_rd_rom.Location = new System.Drawing.Point(8, 23); this.btn_rd_rom.Margin = new System.Windows.Forms.Padding(4); this.btn_rd_rom.Name = "btn_rd_rom"; - this.btn_rd_rom.Size = new System.Drawing.Size(133, 62); + this.btn_rd_rom.Size = new System.Drawing.Size(85, 62); this.btn_rd_rom.TabIndex = 0; this.btn_rd_rom.Text = "Read ROM"; this.btn_rd_rom.UseVisualStyleBackColor = true; @@ -76,7 +81,7 @@ private void InitializeComponent() this.groupBox1.Margin = new System.Windows.Forms.Padding(4); this.groupBox1.Name = "groupBox1"; this.groupBox1.Padding = new System.Windows.Forms.Padding(4); - this.groupBox1.Size = new System.Drawing.Size(289, 234); + this.groupBox1.Size = new System.Drawing.Size(289, 163); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.Text = "Flash-Cart DIY (29W-series) 2 or 4 MB"; @@ -84,10 +89,10 @@ private void InitializeComponent() // // btn_wr_ram // - this.btn_wr_ram.Location = new System.Drawing.Point(148, 92); + this.btn_wr_ram.Location = new System.Drawing.Point(102, 92); this.btn_wr_ram.Margin = new System.Windows.Forms.Padding(4); this.btn_wr_ram.Name = "btn_wr_ram"; - this.btn_wr_ram.Size = new System.Drawing.Size(133, 62); + this.btn_wr_ram.Size = new System.Drawing.Size(85, 62); this.btn_wr_ram.TabIndex = 3; this.btn_wr_ram.Text = "Write SRAM"; this.btn_wr_ram.UseVisualStyleBackColor = true; @@ -96,22 +101,22 @@ private void InitializeComponent() // btn_erase // this.btn_erase.BackColor = System.Drawing.SystemColors.ButtonFace; - this.btn_erase.Location = new System.Drawing.Point(149, 161); + this.btn_erase.Location = new System.Drawing.Point(195, 23); this.btn_erase.Margin = new System.Windows.Forms.Padding(4); this.btn_erase.Name = "btn_erase"; - this.btn_erase.Size = new System.Drawing.Size(133, 62); + this.btn_erase.Size = new System.Drawing.Size(85, 62); this.btn_erase.TabIndex = 5; - this.btn_erase.Text = "Full Erase only Flash-ROM"; + this.btn_erase.Text = "Erase only Flash ROM"; this.btn_erase.UseVisualStyleBackColor = false; this.btn_erase.Click += new System.EventHandler(this.btn_erase_Click); // // btn_check // this.btn_check.BackColor = System.Drawing.SystemColors.ButtonFace; - this.btn_check.Location = new System.Drawing.Point(8, 161); + this.btn_check.Location = new System.Drawing.Point(195, 93); this.btn_check.Margin = new System.Windows.Forms.Padding(4); this.btn_check.Name = "btn_check"; - this.btn_check.Size = new System.Drawing.Size(133, 62); + this.btn_check.Size = new System.Drawing.Size(85, 62); this.btn_check.TabIndex = 4; this.btn_check.Text = "Cart info"; this.btn_check.UseVisualStyleBackColor = false; @@ -119,12 +124,12 @@ private void InitializeComponent() // // btn_wr_rom // - this.btn_wr_rom.Location = new System.Drawing.Point(148, 23); + this.btn_wr_rom.Location = new System.Drawing.Point(102, 23); this.btn_wr_rom.Margin = new System.Windows.Forms.Padding(4); this.btn_wr_rom.Name = "btn_wr_rom"; - this.btn_wr_rom.Size = new System.Drawing.Size(133, 62); + this.btn_wr_rom.Size = new System.Drawing.Size(85, 62); this.btn_wr_rom.TabIndex = 1; - this.btn_wr_rom.Text = "Write Flash-ROM"; + this.btn_wr_rom.Text = "Write Flash ROM"; this.btn_wr_rom.UseVisualStyleBackColor = true; this.btn_wr_rom.Click += new System.EventHandler(this.btn_wr_rom_Click); // @@ -133,7 +138,7 @@ private void InitializeComponent() this.btn_rd_ram.Location = new System.Drawing.Point(8, 92); this.btn_rd_ram.Margin = new System.Windows.Forms.Padding(4); this.btn_rd_ram.Name = "btn_rd_ram"; - this.btn_rd_ram.Size = new System.Drawing.Size(133, 62); + this.btn_rd_ram.Size = new System.Drawing.Size(85, 62); this.btn_rd_ram.TabIndex = 2; this.btn_rd_ram.Text = "Read SRAM"; this.btn_rd_ram.UseVisualStyleBackColor = true; @@ -175,11 +180,11 @@ private void InitializeComponent() this.groupBox2.Controls.Add(this.btn_erase28); this.groupBox2.Controls.Add(this.btn_wr_rom28); this.groupBox2.Controls.Add(this.btn_rd_rom28); - this.groupBox2.Location = new System.Drawing.Point(16, 430); + this.groupBox2.Location = new System.Drawing.Point(16, 390); this.groupBox2.Margin = new System.Windows.Forms.Padding(4); this.groupBox2.Name = "groupBox2"; this.groupBox2.Padding = new System.Windows.Forms.Padding(4); - this.groupBox2.Size = new System.Drawing.Size(289, 166); + this.groupBox2.Size = new System.Drawing.Size(289, 94); this.groupBox2.TabIndex = 2; this.groupBox2.TabStop = false; this.groupBox2.Text = "OTP-Cart Mod (PA28F400) ½ MB"; @@ -187,23 +192,23 @@ private void InitializeComponent() // btn_erase28 // this.btn_erase28.BackColor = System.Drawing.SystemColors.ButtonFace; - this.btn_erase28.Location = new System.Drawing.Point(148, 92); + this.btn_erase28.Location = new System.Drawing.Point(195, 23); this.btn_erase28.Margin = new System.Windows.Forms.Padding(4); this.btn_erase28.Name = "btn_erase28"; - this.btn_erase28.Size = new System.Drawing.Size(133, 62); + this.btn_erase28.Size = new System.Drawing.Size(85, 62); this.btn_erase28.TabIndex = 5; - this.btn_erase28.Text = "Erase only Flash-ROM"; + this.btn_erase28.Text = "Erase only Flash ROM"; this.btn_erase28.UseVisualStyleBackColor = false; this.btn_erase28.Click += new System.EventHandler(this.btn_erase28_Click); // // btn_wr_rom28 // - this.btn_wr_rom28.Location = new System.Drawing.Point(148, 23); + this.btn_wr_rom28.Location = new System.Drawing.Point(102, 23); this.btn_wr_rom28.Margin = new System.Windows.Forms.Padding(4); this.btn_wr_rom28.Name = "btn_wr_rom28"; - this.btn_wr_rom28.Size = new System.Drawing.Size(133, 62); + this.btn_wr_rom28.Size = new System.Drawing.Size(85, 62); this.btn_wr_rom28.TabIndex = 2; - this.btn_wr_rom28.Text = "Write Flash-ROM"; + this.btn_wr_rom28.Text = "Write Flash ROM"; this.btn_wr_rom28.UseVisualStyleBackColor = true; this.btn_wr_rom28.Click += new System.EventHandler(this.btn_wr_rom28_Click); // @@ -212,7 +217,7 @@ private void InitializeComponent() this.btn_rd_rom28.Location = new System.Drawing.Point(8, 23); this.btn_rd_rom28.Margin = new System.Windows.Forms.Padding(4); this.btn_rd_rom28.Name = "btn_rd_rom28"; - this.btn_rd_rom28.Size = new System.Drawing.Size(133, 62); + this.btn_rd_rom28.Size = new System.Drawing.Size(85, 62); this.btn_rd_rom28.TabIndex = 1; this.btn_rd_rom28.Text = "Read ROM"; this.btn_rd_rom28.UseVisualStyleBackColor = true; @@ -223,11 +228,11 @@ private void InitializeComponent() this.groupBox3.Controls.Add(this.btn_erase29l); this.groupBox3.Controls.Add(this.btn_wr_rom29l); this.groupBox3.Controls.Add(this.btn_rd_rom29l); - this.groupBox3.Location = new System.Drawing.Point(16, 256); + this.groupBox3.Location = new System.Drawing.Point(16, 186); this.groupBox3.Margin = new System.Windows.Forms.Padding(4); this.groupBox3.Name = "groupBox3"; this.groupBox3.Padding = new System.Windows.Forms.Padding(4); - this.groupBox3.Size = new System.Drawing.Size(289, 166); + this.groupBox3.Size = new System.Drawing.Size(289, 94); this.groupBox3.TabIndex = 5; this.groupBox3.TabStop = false; this.groupBox3.Text = "Flash-Cart DIY (MX29L3211) 4 MB"; @@ -235,23 +240,23 @@ private void InitializeComponent() // btn_erase29l // this.btn_erase29l.BackColor = System.Drawing.SystemColors.ButtonFace; - this.btn_erase29l.Location = new System.Drawing.Point(148, 92); + this.btn_erase29l.Location = new System.Drawing.Point(195, 23); this.btn_erase29l.Margin = new System.Windows.Forms.Padding(4); this.btn_erase29l.Name = "btn_erase29l"; - this.btn_erase29l.Size = new System.Drawing.Size(133, 62); + this.btn_erase29l.Size = new System.Drawing.Size(85, 62); this.btn_erase29l.TabIndex = 5; - this.btn_erase29l.Text = "Erase only Flash-ROM"; + this.btn_erase29l.Text = "Erase only Flash ROM"; this.btn_erase29l.UseVisualStyleBackColor = false; this.btn_erase29l.Click += new System.EventHandler(this.btn_erase29l_Click); // // btn_wr_rom29l // - this.btn_wr_rom29l.Location = new System.Drawing.Point(148, 23); + this.btn_wr_rom29l.Location = new System.Drawing.Point(102, 23); this.btn_wr_rom29l.Margin = new System.Windows.Forms.Padding(4); this.btn_wr_rom29l.Name = "btn_wr_rom29l"; - this.btn_wr_rom29l.Size = new System.Drawing.Size(133, 62); + this.btn_wr_rom29l.Size = new System.Drawing.Size(85, 62); this.btn_wr_rom29l.TabIndex = 2; - this.btn_wr_rom29l.Text = "Write Flash-ROM"; + this.btn_wr_rom29l.Text = "Write Flash ROM"; this.btn_wr_rom29l.UseVisualStyleBackColor = true; this.btn_wr_rom29l.Click += new System.EventHandler(this.btn_wr_rom29l_Click); // @@ -260,17 +265,66 @@ private void InitializeComponent() this.btn_rd_rom29l.Location = new System.Drawing.Point(8, 23); this.btn_rd_rom29l.Margin = new System.Windows.Forms.Padding(4); this.btn_rd_rom29l.Name = "btn_rd_rom29l"; - this.btn_rd_rom29l.Size = new System.Drawing.Size(133, 62); + this.btn_rd_rom29l.Size = new System.Drawing.Size(85, 62); this.btn_rd_rom29l.TabIndex = 1; this.btn_rd_rom29l.Text = "Read ROM"; this.btn_rd_rom29l.UseVisualStyleBackColor = true; this.btn_rd_rom29l.Click += new System.EventHandler(this.btn_rd_rom29l_Click); // + // groupBox4 + // + this.groupBox4.Controls.Add(this.btn_erase29lv); + this.groupBox4.Controls.Add(this.btn_wr_rom29lv); + this.groupBox4.Controls.Add(this.btn_rd_rom29lv); + this.groupBox4.Location = new System.Drawing.Point(16, 288); + this.groupBox4.Margin = new System.Windows.Forms.Padding(4); + this.groupBox4.Name = "groupBox4"; + this.groupBox4.Padding = new System.Windows.Forms.Padding(4); + this.groupBox4.Size = new System.Drawing.Size(289, 94); + this.groupBox4.TabIndex = 6; + this.groupBox4.TabStop = false; + this.groupBox4.Text = "Flash-Cart DIY (MX29LV320) 4 MB"; + // + // btn_erase29lv + // + this.btn_erase29lv.BackColor = System.Drawing.SystemColors.ButtonFace; + this.btn_erase29lv.Location = new System.Drawing.Point(195, 23); + this.btn_erase29lv.Margin = new System.Windows.Forms.Padding(4); + this.btn_erase29lv.Name = "btn_erase29lv"; + this.btn_erase29lv.Size = new System.Drawing.Size(85, 62); + this.btn_erase29lv.TabIndex = 5; + this.btn_erase29lv.Text = "Erase only Flash ROM"; + this.btn_erase29lv.UseVisualStyleBackColor = false; + this.btn_erase29lv.Click += new System.EventHandler(this.btn_erase29lv_Click); + // + // btn_wr_rom29lv + // + this.btn_wr_rom29lv.Location = new System.Drawing.Point(102, 23); + this.btn_wr_rom29lv.Margin = new System.Windows.Forms.Padding(4); + this.btn_wr_rom29lv.Name = "btn_wr_rom29lv"; + this.btn_wr_rom29lv.Size = new System.Drawing.Size(85, 62); + this.btn_wr_rom29lv.TabIndex = 2; + this.btn_wr_rom29lv.Text = "Write Flash ROM"; + this.btn_wr_rom29lv.UseVisualStyleBackColor = true; + this.btn_wr_rom29lv.Click += new System.EventHandler(this.btn_wr_rom29lv_Click); + // + // btn_rd_rom29lv + // + this.btn_rd_rom29lv.Location = new System.Drawing.Point(8, 23); + this.btn_rd_rom29lv.Margin = new System.Windows.Forms.Padding(4); + this.btn_rd_rom29lv.Name = "btn_rd_rom29lv"; + this.btn_rd_rom29lv.Size = new System.Drawing.Size(85, 62); + this.btn_rd_rom29lv.TabIndex = 1; + this.btn_rd_rom29lv.Text = "Read ROM"; + this.btn_rd_rom29lv.UseVisualStyleBackColor = true; + this.btn_rd_rom29lv.Click += new System.EventHandler(this.btn_rd_rom29lv_Click); + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(967, 683); + this.Controls.Add(this.groupBox4); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox2); this.Controls.Add(this.consoleBox); @@ -286,6 +340,7 @@ private void InitializeComponent() this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox3.ResumeLayout(false); + this.groupBox4.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -312,6 +367,10 @@ private void InitializeComponent() private System.Windows.Forms.Button btn_erase29l; private System.Windows.Forms.Button btn_wr_rom29l; private System.Windows.Forms.Button btn_rd_rom29l; + private System.Windows.Forms.GroupBox groupBox4; + private System.Windows.Forms.Button btn_erase29lv; + private System.Windows.Forms.Button btn_wr_rom29lv; + private System.Windows.Forms.Button btn_rd_rom29lv; } } diff --git a/flashkit-md/Form1.cs b/flashkit-md/Form1.cs index d9f57ec..16c479e 100644 --- a/flashkit-md/Form1.cs +++ b/flashkit-md/Form1.cs @@ -1,9 +1,9 @@ using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Text; +//using System.Collections.Generic; +//using System.ComponentModel; +//using System.Data; +//using System.Drawing; +//using System.Text; using System.Windows.Forms; using System.IO; using System.Security.Cryptography; @@ -38,7 +38,21 @@ private void btn_check_Click(object sender, EventArgs e) Device.connect(); Device.setDelay(1); + consWriteLine("Connected to: " + Device.getPortName()); + + Device.flash29lReset(); + if (Device.flash29lIdentMfr() != 0xffff) consWriteLine("Manifacture ID: " + Device.flash29lIdentMfr().ToString("X4")); + if (Device.flash29lIdentDev() != 0xffff) consWriteLine("Device ID: " + Device.flash29lIdentDev().ToString("X4")); + Device.flash29lReset(); + + //Device.flash29lvReset(); + //if (Device.flash29lvIdentMfr() != 0xffff) consWriteLine("Manifacture ID: " + Device.flash29lvIdentMfr().ToString("X4")); + //if (Device.flash29lvIdentDev() != 0xffff) consWriteLine("Device ID: " + Device.flash29lvIdentDev().ToString("X4")); + //if (Device.flash29lvFactLock() != 0xffff) consWriteLine("Factory Lock: " + Device.flash29lvFactLock().ToString("X4")); + //Device.flash29lvReset(); + + consWriteLine("-----------------------------------------------------"); consWriteLine("ROM name : " + Cart.getRomName()); consWriteLine("ROM size : " + Cart.getRomSize() / 1024 + "K"); ram_size = Cart.getRamSize(); @@ -229,7 +243,7 @@ private void btn_wr_ram_Click(object sender, EventArgs e) for (int i = 0; i < copy_len; i++) { if (i % 2 == 0) continue; - if (ram[i] != ram2[i]) throw new Exception("Verify error at " + i); + if (ram[i] != ram2[i]) throw new Exception("Verify error at 0x" + i.ToString("X6")); } copy_len /= 2; @@ -315,7 +329,7 @@ private void btn_wr_rom_Click(object sender, EventArgs e) progressBar1.Value = rom_size; for (int i = 0; i < rom_size; i++) { - if (rom[i] != rom2[i]) throw new Exception("Verify error at " + i); + if (rom[i] != rom2[i]) throw new Exception("Verify error at 0x" + i.ToString("X6")); } consWriteLine("OK"); @@ -344,7 +358,7 @@ private void btn_erase_Click(object sender, EventArgs e) int rom_size = 4194304; // max volume int block_len = 32768; Device.connect(); - Device.setDelay(0); + Device.setDelay(1); consWriteLine("-----------------------------------------------------"); progressBar1.Value = 0; @@ -385,7 +399,7 @@ private void btn_erase_Click(object sender, EventArgs e) progressBar1.Value = rom_size; for (int i = 0; i < rom_size; i++) { - if (rom[i] != 0xff) throw new Exception("Verify error at " + i); + if (rom[i] != 0xff) throw new Exception("Verify error at 0x" + i.ToString("X6")); } consWriteLine("OK"); @@ -491,7 +505,7 @@ private void btn_wr_rom28_Click(object sender, EventArgs e) for (int i = 0; i < rom_size; i += 131072) { - consWriteLine("Erase sector from: 0x" + i.ToString("X6")); + consWriteLine("Erase sector at 0x" + i.ToString("X6")); //progressBar1.Value = i; progressBar1.PerformStep(); Device.flash28Erase(i); @@ -563,7 +577,7 @@ private void btn_wr_rom28_Click(object sender, EventArgs e) progressBar1.Value = rom_size; for (int i = 0; i < rom_size; i++) { - if (rom[i] != rom2[i]) throw new Exception("Verify error at " + i); + if (rom[i] != rom2[i]) throw new Exception("Verify error at 0x" + i.ToString("X6")); } time = (double)(DateTime.Now.Ticks - t.Ticks); @@ -609,7 +623,7 @@ private void btn_erase28_Click(object sender, EventArgs e) for (int i = 0; i < rom_size; i += 131072) { - consWriteLine("Erase sector from: 0x" + i.ToString("X6")); + consWriteLine("Erase sector at 0x" + i.ToString("X6")); //progressBar1.Value = i; progressBar1.PerformStep(); Device.flash28Erase(i); @@ -648,7 +662,7 @@ private void btn_erase28_Click(object sender, EventArgs e) progressBar1.Value = rom_size; for (int i = 0; i < rom_size; i++) { - if (rom[i] != 0xff) throw new Exception("Verify error at " + i); + if (rom[i] != 0xff) throw new Exception("Verify error at 0x" + i.ToString("X6")); } consWriteLine("OK"); @@ -824,7 +838,7 @@ private void btn_wr_rom29l_Click(object sender, EventArgs e) { int j = 256 - (i - (i / 256) * 256); int k = (i - (i / 2) * 2) != 0 ? i-- : i; - consWriteLine("... afterburn at " + k.ToString("X6") + " to " + (i + j).ToString("X6")); + consWriteLine("... afterburn at 0x" + k.ToString("X6") + " to 0x" + (i + j).ToString("X6")); Device.flash29lWrite(rom, k, j); Device.flash29lReset(); Device.setAddr(k); @@ -865,8 +879,13 @@ private void btn_erase29l_Click(object sender, EventArgs e) Device.connect(); Device.setDelay(1); - if (Device.flash29lIdentMfr() != 0xC2) - if (Device.flash29lIdentDev() != 0xF9) throw new Exception("Device 29l3211 not found ..."); + Device.flash29lReset(); + + //consWriteLine("Manifacture ID: " + Device.flash29lIdentMfr().ToString("X4")); + //consWriteLine("Device ID: " + Device.flash29lIdentDev().ToString("X4")); + + if (Device.flash29lIdentMfr() != 0xC2) throw new Exception("Device MXIC not found ..."); + if (Device.flash29lIdentDev() != 0xF9) throw new Exception("Device 29l3211 not found ..."); consWriteLine("-----------------------------------------------------"); progressBar1.Value = 0; @@ -907,7 +926,7 @@ private void btn_erase29l_Click(object sender, EventArgs e) progressBar1.Value = rom_size; for (int i = 0; i < rom_size; i++) { - if (rom[i] != 0xff) throw new Exception("Verify error at " + i.ToString("X6")); + if (rom[i] != 0xff) throw new Exception("Verify error at 0x" + i.ToString("X6")); } time = (double)(DateTime.Now.Ticks - t.Ticks); consWriteLine("Time: " + ((time / 10000) / 1000).ToString("F") + "sec"); @@ -928,5 +947,255 @@ private void btn_erase29l_Click(object sender, EventArgs e) } + private void btn_erase29lv_Click(object sender, EventArgs e) + { + try + { + byte[] rom; + int rom_size = 4194304; // max volume + int block_len = 4096; + Device.connect(); + Device.setDelay(1); + + Device.flash29lvReset(); + + //consWriteLine("Manifacture ID: " + Device.flash29lvIdentMfr().ToString("X4")); + //consWriteLine("Device ID: " + Device.flash29lvIdentDev().ToString("X4")); + + if (Device.flash29lvIdentMfr() != 0xC2) throw new Exception("Device MXIC not found ..."); + if ((Device.flash29lvIdentDev() != 0x22A7) && (Device.flash29lvIdentDev() != 0x22A8)) throw new Exception("Device 29lv320 not found ..."); + + consWriteLine("-----------------------------------------------------"); + progressBar1.Value = 0; + progressBar1.Maximum = rom_size; + + consWriteLine("Flash erase..."); + consWriteLine("Wait ... (~25sec average)"); + Device.flash29lvReset(); + DateTime t = DateTime.Now; // start time + + Device.flash29lvEraseAll(); + + double time = (double)(DateTime.Now.Ticks - t.Ticks); // finish time + consWriteLine("Time: " + ((time / 10000) / 1000).ToString("F") + "sec"); + + consWriteLine("OK"); + + consWriteLine("Blank verify..."); + rom = new byte[rom_size]; + Device.flash29lvReset(); + Device.setAddr(0); + t = DateTime.Now; + + for (int i = 0; i < rom_size; i += block_len) + { + Device.read(rom, i, block_len); + progressBar1.Value = i; + this.Update(); + /* + double ctime = (double)(DateTime.Now.Ticks - t.Ticks); + progressBar1.CreateGraphics().DrawString((Math.Floor(ctime / 10000 / 1000)).ToString("G") + "sec", + new Font("Tahoma", (float)10.25, FontStyle.Regular), + Brushes.Blue, new PointF(progressBar1.Width / 2 - 10, + progressBar1.Height / 2 - 7)); + */ + } + progressBar1.Value = rom_size; + for (int i = 0; i < rom_size; i++) + { + if (rom[i] != 0xff) throw new Exception("Verify error at 0x" + i.ToString("X6")); + } + time = (double)(DateTime.Now.Ticks - t.Ticks); + consWriteLine("Time: " + ((time / 10000) / 1000).ToString("F") + "sec"); + + consWriteLine("OK"); + + } + catch (Exception x) + { + try + { + Device.flash29lReset(); + } + catch (Exception) { } + consWriteLine(x.Message); + } + Device.disconnect(); + + } + + private void btn_wr_rom29lv_Click(object sender, EventArgs e) + { + try + { + byte[] rom; + int rom_size; + int block_len = 4096; + Device.connect(); + Device.setDelay(0); + + if (openFileDialog1.ShowDialog() == DialogResult.OK) + { + consWriteLine("-----------------------------------------------------"); + FileStream f = File.OpenRead(openFileDialog1.FileName); + rom_size = (int)f.Length; + if (rom_size % 65536 != 0) rom_size = rom_size / 65536 * 65536 + 65536; + if (rom_size > 0x400000) rom_size = 0x400000; + rom = new byte[rom_size]; + f.Read(rom, 0, rom_size); + f.Close(); + + progressBar1.Value = 0; + progressBar1.Maximum = rom_size; + + Device.flash29lvReset(); + DateTime t = DateTime.Now; // start time + + if (rom_size > 0x300000) // if above 3/4 need erase - fast do complete full chip erase + { + consWriteLine("Flash erase full..."); + consWriteLine("Wait ... (~25sec average)"); + Device.flash29lvEraseAll(); + } + else + { + consWriteLine("Flash erase partial..."); + if (Device.flash29lvIdentDev() == 0x22A8) // Device with Bottom Boot part + { + consWriteLine("Erase small sectors ..."); + Device.flash29lvReset(); + for (int i = 0; i < 8; i++) + { + consWriteLine("Erase small sector at 0x" + (i * 0x1000 * 2).ToString("X6")); + Device.flash29lvErase(i * 0x1000); + } + consWriteLine("Erase standart sector ..."); + } + else // Device with Top Boot Part + { + consWriteLine("Erase standart sector ..."); + consWriteLine("Erase sector at 0x000000"); + Device.flash29lvReset(); + Device.flash29lvErase(0); + } + + for (int i = 0x8000; i < rom_size / 2; i += 0x8000) + { + consWriteLine("Erase sector at 0x" + (i * 2).ToString("X6")); + Device.flash29lvErase(i); + } + } + + double time = (double)(DateTime.Now.Ticks - t.Ticks); // finish time + consWriteLine("Time: " + ((time / 10000) / 1000).ToString("F") + "sec"); + + consWriteLine("OK"); + + progressBar1.Value = 0; + consWriteLine("Flash write..."); + Device.flash29lvReset(); + Device.setAddr(0); + t = DateTime.Now; + + for (int i = 0; i < rom_size; i += block_len) + { + Device.flash29lvWrite(rom, i, block_len); + progressBar1.Value = i; + this.Update(); + } + time = (double)(DateTime.Now.Ticks - t.Ticks); + consWriteLine("Time: " + ((time / 10000) / 1000).ToString("F") + "sec"); + + progressBar1.Value = 0; + + consWriteLine("Flash verify..."); + byte[] rom2 = new byte[rom.Length]; + Device.flash29lvReset(); + Device.setAddr(0); + + for (int i = 0; i < rom_size; i += block_len) + { + Device.read(rom2, i, block_len); + progressBar1.Value = i; + this.Update(); + } + progressBar1.Value = rom_size; + for (int i = 0; i < rom_size; i++) + { + if (rom[i] != rom2[i]) throw new Exception("Verify error at 0x" + i.ToString("X6")); + } + + consWriteLine("OK"); + + } + + } + catch (Exception x) + { + try + { + Device.flash29lvReset(); + } + catch (Exception) { } + consWriteLine(x.Message); + } + Device.disconnect(); + + } + + private void btn_rd_rom29lv_Click(object sender, EventArgs e) + { + try + { + byte[] rom; + int rom_size; + int block_size = 32768; + Device.connect(); + Device.setDelay(1); + string rom_name = Cart.getRomName(); + rom_name += ".bin"; + saveFileDialog1.FileName = rom_name; + if (saveFileDialog1.ShowDialog() == DialogResult.OK) + { + consWriteLine("-----------------------------------------------------"); + rom_size = Cart.getRomSize(); + progressBar1.Value = 0; + progressBar1.Maximum = rom_size; + rom = new byte[rom_size]; + + consWriteLine("Read ROM to " + saveFileDialog1.FileName); + consWriteLine("ROM size : " + rom_size / 1024 + "K"); + + Device.setAddr(0); + DateTime t = DateTime.Now; + for (int i = 0; i < rom_size; i += block_size) + { + //Device.read(rom, i, block_size); + Device.read(rom, i, i + block_size <= rom_size ? block_size : rom_size - (rom_size / block_size) * block_size); + progressBar1.Value = i; + this.Update(); + } + progressBar1.Value = rom_size; + double time = (double)(DateTime.Now.Ticks - t.Ticks); + consWriteLine("Time: " + ((time / 10000) / 1000).ToString("F") + "sec"); + + FileStream f = File.OpenWrite(saveFileDialog1.FileName); + f.Write(rom, 0, rom.Length); + f.Close(); + + printMD5(rom); + + consWriteLine("OK"); + } + + } + catch (Exception x) + { + consWriteLine(x.Message); + } + Device.disconnect(); + + } + } } diff --git a/flashkit-md/Properties/AssemblyInfo.cs b/flashkit-md/Properties/AssemblyInfo.cs index b237575..3cc18cc 100644 --- a/flashkit-md/Properties/AssemblyInfo.cs +++ b/flashkit-md/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.2.0")] -[assembly: AssemblyFileVersion("1.0.2.0")] +[assembly: AssemblyVersion("1.0.3.0")] +[assembly: AssemblyFileVersion("1.0.3.0")]