PJRC.COM Offline Archive, February 07, 2004 Visit this page on the live site |
| ||
Shopping Cart Checkout Shipping Cost Download Website |
Home | MP3 Player | 8051 Tools | All Projects | PJRC Store | Site Map |
You are here: MP3 Player Technical Docs Old MP3 Player Design HD Write Script | Search PJRC |
The format is pretty simple. The first 256 sectors are reserved for a table that tells where each MP3 file begins on the drive. The firmware only reads the first 8 of these sectors, but it could be modified to read more of them, if needed. The MP3 files are written, in order, beginning at the 257th sector. Zeros are appended to each file so that it fills an integral number of sectors. All the files must be written in a continuous group of sectors, and unused sectors are not allowed between files. This simple format is not very flexible, since it basically means that it is impossible to remove a file without rearranging all of the sectors that follow it. It also means that you must completely dedicate a drive to the player. Because the data begins at sector 0, which is ordinarily the master boot record with the drive's partition table, the drives partitioning is ignored and gets completely erased by writing the MP3 files.
This script just copies all the files from a directory onto the drive, writing the 256 sector table and then all of the data. Though it is possible to add additional files after originally writing, this script doesn't provide a way to do it.
This code is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
#! /usr/bin/perl # make a "raw" hard drive image for use with my # initial attempts at the mp3 player. # see http://www.pjrc.com/tech/mp3/ for more info. # WARNING: be very careful using this program. All it # does is create a massive stream of data, but by using # the shell's redirect to /dev/hdc (or whatever device # represents your raw drive drive), you will completely # overwrite all data on the hard drive. If you type # the wrong device filename, you could easily destroy # all of the data on your computer!! Be careful. # Of course, this script is useless without an operating # system that provides a raw device that can accept the # data.... Linux works very nicely. If all you have is # crap from Microsoft, maybe this is a good time to # consider upgrading! # This code is an original work by Paul Stoffregen, written # in December 1999. This code has been placed in the # public domain. You may use it without any restrictions. # You may include it in your own projects, even commercial # (for profit) products. # This code is distributed in the hope that they will be useful, # but without any warranty; without even the implied warranty of # merchantability or fitness for a particular purpose. $usage = "Typical Usage: mk_hdimg <directory> > /dev/hdc\n"; $dir = $ARGV[0]; $#ARGV >= 0 || die $usage; -d $dir || die $usage; opendir(DIR, $dir) || die "Unable to read $dir\n"; @dirfile = readdir(DIR); closedir(DIR); @dirfile = sort @dirfile; $n = 0; $blk = 256; for ($i=0; $i < $#dirfile; $i++) { $f = "$dir/$dirfile[$i]"; next unless -f $f && -r $f; $s = -s $f; $block[$n] = $blk; $file[$n] = $f; $blk += int(($s + 511) / 512); $n++; } $n = 32767 if $n > 32767; warn "$n files to copy\n"; for ($i=0; $i < $n; $i++) { print pack("I", $block[$i]); } for ( ; $i < 32768; $i++) { print pack("I", 0); } for ($i=0; $i < $n; $i++) { $f = $file[$i]; $s = -s $f; $r = int(($s + 511) / 512) * 512 - $s; warn "Copy file $f, $s bytes, $r pad bytes\n"; open(FILE, $f); $ss = read(FILE, $mp3, $s); $ss == $s || die "Error, $ss bytes read, should be $s\n"; print $mp3; close(FILE); print pack("x$r"); }