7

Possible Duplicate:
How can i put a compiled boot sector onto a USB stick or disk?

I'm busy creating a basic boot loader, it is for software that needs to run without an OS

I also want to write a small console app that moves the compiled bootloader to my SD card.

The problem I am running into is writing that specific boot loader to Sector0 on an SD card. The SD card is slotted into my SD Card slot on my laptop.

Can I accomplish this using a C# console app ? if not, what are my options on getting that boot loader on the SD card?

Update: The bootloader is written in C, I would like the console app that transfers the boot loader to be in C#

Community
  • 1
  • 1
stoic
  • 4,700
  • 13
  • 58
  • 88
  • 3
    A bootloader in C#!? I would rather go for a low level assembly loader that can run another exe file – GETah Jun 03 '12 at 20:58
  • 3
    nope... bootloader is in c, i would like the app that transfer the bootloader to be in C# – stoic Jun 03 '12 at 20:59
  • 3
    There is another [question here](http://stackoverflow.com/questions/1894843/how-can-i-put-a-compiled-boot-sector-onto-a-usb-stick-or-disk) with an answer that use a specific utilty. – Steve Jun 03 '12 at 21:07
  • 2
    I would be *really surprised* if there were not existing tools for this: e.g. wouldn't cygwin + [dd](http://linux.die.net/man/1/dd) work? (That is, don't reinvent the wheel just to copy it over :-) –  Jun 03 '12 at 21:07
  • While not an "exact" duplicate, as it doesn't mandate C#, I feel the duplicate question would sufficiently accomplish this task: if the question is about *how* to do this sort of operation in C# (e.g. use the appropriate WinAPI/elevations) then please open up a new more focused question... –  Jun 03 '12 at 21:10
  • @Steve, might not be in C# but it's the alternative i've been looking for. Thanx – stoic Jun 03 '12 at 21:12
  • 2
    why vote for close? I do not see any duplicate asking to write to boot sector using C#? If there is a duplicate, please post the link. @steve, your link is an alternative – stoic Jun 03 '12 at 21:23
  • Check out code from here http://dev64.wordpress.com/2012/02/28/physical-sector-read-windows/ – Blablablaster Jun 03 '12 at 21:24

2 Answers2

2

You could use low level IO API to write a file to a specific sector. Have a look at WriteFile documentation for more info.

GETah
  • 20,922
  • 7
  • 61
  • 103
  • 1
    this seems to be the answer, reading through it i see that i can write to the boot sectors using the writefile method.. – stoic Jun 03 '12 at 21:19
1

A much easier idea would be to create an image file with your bootloader (and optionally, partition table and/or file systems) and use an external tool like dd or Image Writer to actually write the image to the SD card.

Adam Maras
  • 26,269
  • 6
  • 65
  • 91