A blog by Devendra Tewari
I use an 8 GB class 4 SD Card to run the Ubuntu distribution for OMAP4 on a PandaBoard. This post details the procedure I use to prepare the SD Card on Windows.
You’ll need the following tools
Here’s the procedure to prepare the SD Card
Win32DiskImager.exe
- it requests admin privileges on Windows 7Win32 Disk Imager can also be used to read an SD Card. You can write the image file to the same or another SD Card.
The SD Card will be partitioned after the procedure above. To restore it to its original state i.e. create a single partition with all the available space, you’ll need to use the GParted Partition Editor on a Linux box, or from a live CD. Windows 8 Disk Management tool may also work.
Version 0.3 binary of Win32 Disk Imager has a bug in a call to Win32 SetFilePointer
function. The image read is about half the size of my 8 GB SD Card. I built it from source using QT Creator after patching the following two functions in disk.cpp
char *readSectorDataFromHandle(HANDLE handle, unsigned long long startsector, unsigned long long numsectors, unsigned long long sectorsize)
{
unsigned long bytesread;
char *data = new char[sectorsize * numsectors];
LARGE_INTEGER li;
li.QuadPart = startsector * sectorsize;
SetFilePointer(handle, li.LowPart, &li.HighPart, FILE_BEGIN);
if (!ReadFile(handle, data, sectorsize * numsectors, &bytesread, NULL))
{
char *errormessage=NULL;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPSTR)&errormessage, 0, NULL);
QMessageBox::critical(NULL, "Read Error", QString("An error occurred when attempting to read data from handle.\nError %1: %2").arg(GetLastError()).arg(errormessage));
LocalFree(errormessage);
delete data;
data = NULL;
}
return data;
}
bool writeSectorDataToHandle(HANDLE handle, char *data, unsigned long long startsector, unsigned long long numsectors, unsigned long long sectorsize)
{
unsigned long byteswritten;
BOOL bResult;
LARGE_INTEGER li;
li.QuadPart = startsector * sectorsize;
SetFilePointer(handle, li.LowPart, &li.HighPart, FILE_BEGIN);
bResult = WriteFile(handle, data, sectorsize * numsectors, &byteswritten, NULL);
if (!bResult)
{
char *errormessage=NULL;
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPSTR)&errormessage, 0, NULL);
QMessageBox::critical(NULL, "Write Error", QString("An error occurred when attempting to write data from handle.\nError %1: %2").arg(GetLastError()).arg(errormessage));
LocalFree(errormessage);
}
return (bResult == TRUE);
}
That fixes the problem with reading and writing large SD Cards.