Main Site Documentation

Bad Memory Detected


#1

With a G120, if i program the module over serial, the program load is successful. If I load from a USB drive, with SystemUpdate, I get the following error:

[quote]GHI Electronics, LLC
G120™ GHI low-level loader Rev 1.01

Bad Memory Detected!! Please Contact GHI[/quote]

GHI?


#2

@ stevepx -

What do you mean “with SystemUpdate” ?


#3

I mean when I use the SystemUpdate class from the GHI.Premium.System namespace.


#4

@ stevepx -

You mean IFU?

I don’t think IFU caused that problem!
Show us your code, please?

And after the bug happened, using serial then it comes back normally?


#5

Yes, IFU leaves this module blank and the low level loader generates the error message I included in the first post.

This code works with no error on other modules, only this one, so far, produces an error.

Here is the code (modified from the example):

using System;
using System.IO;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.IO;

using GHI.Premium.Hardware.LowLevel;
using GHI.Premium.System;
using wd = GHI.Premium.Hardware.LowLevel.Watchdog;

namespace GHITest
{
	class Update
	{
		public Update(String fileName, Lcd8Wire lcd)
		{
			lcd.SendAllLines("Updating...", "", "", "");

			SystemUpdate.Initialize(/*SystemUpdate.SystemUpdateType.Config | 
									SystemUpdate.SystemUpdateType.Firmware |*/
									SystemUpdate.SystemUpdateType.Deployment);

			LoadDataFromUsb(fileName, SystemUpdate.SystemUpdateType.Deployment);

			if (SystemUpdate.CanUpdate)
			{
				lcd.SendAllLines("Update successful,", "restarting...", "", "");
				wd.ResetCounter();				
				SystemUpdate.FlashAndReset();
			}
			else
			{
				lcd.SendAllLines("Update FAILED,", "Shutting down...", "", "");
				wd.ResetCounter();
				Thread.Sleep(5000);
				Program.ShutDown();
			}
		}


		static void LoadDataFromUsb(string filename, SystemUpdate.SystemUpdateType ifutype)
		{
			int rest;
			byte[] hex;
			long len;
			int blocknum;
			FileStream fs = null;
			const int BLOCK_SIZE = 10 * 1024;

			try
			{
				fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
				len = fs.Length;

				blocknum = (int)len / BLOCK_SIZE;
				rest = (int)len % BLOCK_SIZE;
				hex = new byte[BLOCK_SIZE];

				for (int i = 0; i < blocknum; i++)
				{
					wd.ResetCounter();
					Debug.Print("Loading file " + filename + ", block " + i + "/" + blocknum);

					fs.Read(hex, 0, BLOCK_SIZE);
					hex = Program.DecryptData(hex);
					SystemUpdate.Load(ifutype, hex, BLOCK_SIZE);
				}

				Debug.Print("Loading file " + filename + ", block " + blocknum + "/" + blocknum);
				fs.Read(hex, 0, rest);
				hex = Program.DecryptData(hex);
				wd.ResetCounter();
				SystemUpdate.Load(ifutype, hex, rest);				
			}
			catch (Exception ex)
			{
				Debug.Print(ex.Message);
			}
			finally
			{
				if (fs != null)
				{
					fs.Close();
					fs.Dispose();
				}

				fs = null;
				hex = null;
			}
			wd.ResetCounter();
			Debug.GC(true);
		}
	}
}

#6

[quote=“stevepx”]This code works with no error on other modules, only this one, so far, produces an error.
[/quote]
So is it correct to conclude that only one of a number of G120 modules gave you this bad memory error?

Interesting to know that there could be a memory problem in the G120 units and you stumbled on way to detect that! I wonder if it was the external RAM?

It’s a good idea for someone (not me!) to write a diagnostics code that will check all memory (internal and external RAM, Flash, and EEPROM) in any module or main-board for errors, like the diagnostics programs we used to use to check PC memory.