Copying kernel to a floppy without a filesystem?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
ThisMayWork
Member
Member
Posts: 65
Joined: Sat Mar 22, 2014 1:14 pm
Location: /bin

Copying kernel to a floppy without a filesystem?

Post by ThisMayWork »

I have created a floppy image using dd which has my bootloader on the first sector. Now I need to copy my kernel to the next one but I cannot mount it on OSX (it complains about not recognising the filesystem). Is there any other way to copy it? Thanks in advance! :)
"Programming is an art form that fights back."
-Kudzu
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: Copying kernel to a floppy without a filesystem?

Post by bwat »

ThisMayWork wrote:I have created a floppy image using dd which has my bootloader on the first sector. Now I need to copy my kernel to the next one but I cannot mount it on OSX (it complains about not recognising the filesystem). Is there any other way to copy it? Thanks in advance! :)
Can't you copy it to the second sector (or whatever sector your bootloader expects it to be at)?

If you were on linux and your bootloader binary was called "mbr" and the kernel binary was called "system" and the bootloader wanted the kernel at sector number 2, then you would do the following:

Code: Select all

	dd if=mbr of=/dev/sdb seek=0 conv=sync
	dd if=system of=/dev/sdb seek=1 conv=sync
Actually in the above it isn't the floppy but a harddisk (/dev/sdb). Obviously you would change that.
Every universe of discourse has its logical structure --- S. K. Langer.
User avatar
ThisMayWork
Member
Member
Posts: 65
Joined: Sat Mar 22, 2014 1:14 pm
Location: /bin

Re: Copying kernel to a floppy without a filesystem?

Post by ThisMayWork »

I thought of that but my kernel is not 512B in size (the size of the sector). Will this work as expected?
"Programming is an art form that fights back."
-Kudzu
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: Copying kernel to a floppy without a filesystem?

Post by bwat »

It'll copy however many sectors it needs to.

Here is a tiny kernel which has a build system that installs the system onto a harddisk just like you want to on a floppy. Check out the "build.x86" directory and look at the "Makefile", especially the target "harddisk". Look at the last section of the README file in the top level directory for a wee bit more info on how the disk is prepared.

EDIT: Make sure the conv=sync option is given (linux) or conv=osync (BSD) - I don't know what it is on OSX. If you don't have this set you can get problems with your last sector.
Every universe of discourse has its logical structure --- S. K. Langer.
User avatar
ThisMayWork
Member
Member
Posts: 65
Joined: Sat Mar 22, 2014 1:14 pm
Location: /bin

Re: Copying kernel to a floppy without a filesystem?

Post by ThisMayWork »

This is actually very helpful! However, objcopy is not available for OSX and there doesn't seem to be any decent alternative. Will there be any difference if I just link it as .bin instead of .elf? ELF is flat, right?
"Programming is an art form that fights back."
-Kudzu
User avatar
bwat
Member
Member
Posts: 359
Joined: Fri Jul 03, 2009 6:21 am

Re: Copying kernel to a floppy without a filesystem?

Post by bwat »

PM me with your email address and I'll send you the source code for a wee tool which will flatten an ELF so you can just copy it with dd.
Every universe of discourse has its logical structure --- S. K. Langer.
alexfru
Member
Member
Posts: 1112
Joined: Tue Mar 04, 2014 5:27 am

Re: Copying kernel to a floppy without a filesystem?

Post by alexfru »

ThisMayWork wrote:...
That's a rather large sig!
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Copying kernel to a floppy without a filesystem?

Post by Brendan »

Hi,
ThisMayWork wrote:I thought of that but my kernel is not 512B in size (the size of the sector). Will this work as expected?

Code: Select all

void foo()
{
}
NOT

Code: Select all

void foo() {
}
Neither of these function actually do anything; so your question (whether they work as expected) doesn't really make any sense.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
linguofreak
Member
Member
Posts: 510
Joined: Wed Mar 09, 2011 3:55 am

Re: Copying kernel to a floppy without a filesystem?

Post by linguofreak »

Brendan wrote: Neither of these function actually do anything; so your question (whether they work as expected) doesn't really make any sense.


Cheers,

Brendan
That's his sig, not code that he's asking about.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Copying kernel to a floppy without a filesystem?

Post by Brendan »

Hi,
linguofreak wrote:
Brendan wrote: Neither of these function actually do anything; so your question (whether they work as expected) doesn't really make any sense.
That's his sig, not code that he's asking about.
I never would've noticed - perhaps his signature should be larger so it stands out more, and his post/s smaller to avoid distracting people... :roll:


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
ThisMayWork
Member
Member
Posts: 65
Joined: Sat Mar 22, 2014 1:14 pm
Location: /bin

Kernel compiled, everything linked. Floppy?!

Post by ThisMayWork »

Hello! I am fairly new to OS development and I have successfully managed to compile my *tiny* kernel, assemble my *tiny* bootloader and link everything together in one file called os-image. Now how do I create a floppy and copy that image to it so Virtual PC will boot it? I am running OSX...

EDIT: I managed to create a floppy image using hdiutil, Apple's image tool. However, it contains no file system (that is exactly what I want, as my bootloader using no file system, only jumps to the correct sector and loads the whole floppy after that to memory). However, since it has no filesystem, OSX refuse to mount it so I have no way of copying my os-image to it.
"Programming is an art form that fights back."
-Kudzu
User avatar
sortie
Member
Member
Posts: 931
Joined: Wed Mar 21, 2012 3:01 pm
Libera.chat IRC: sortie

Re: Copying kernel to a floppy without a filesystem?

Post by sortie »

ThisMayWork: I took the liberty of merging your new topic into the old topic as they seem to be a continuation of each other.
User avatar
Bender
Member
Member
Posts: 449
Joined: Wed Aug 21, 2013 3:53 am
Libera.chat IRC: bender|
Location: Asia, Singapore

Re: Copying kernel to a floppy without a filesystem?

Post by Bender »

You can use HxD to copy the sectors, and regardless if it's a floppy with a filesystem, QEMU (or any other sane emulator) should be able to boot it.
I highly recommend to use a well-known filesystem (extN/FATXX etc.) because your kernel will soon turn big enough.
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Copying kernel to a floppy without a filesystem?

Post by max »

ThisMayWork wrote:This is actually very helpful! However, objcopy is not available for OSX and there doesn't seem to be any decent alternative. Will there be any difference if I just link it as .bin instead of .elf? ELF is flat, right?
You can install binutils via brew or port :)
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Copying kernel to a floppy without a filesystem?

Post by bluemoon »

max wrote:
ThisMayWork wrote:This is actually very helpful! However, objcopy is not available for OSX and there doesn't seem to be any decent alternative. Will there be any difference if I just link it as .bin instead of .elf? ELF is flat, right?
You can install binutils via brew or port :)
Build a cross compiler, the toolchain comes with objcopy. This is (still?) the recommended option in this forum.
Search the wiki for detail.
Post Reply