% $Id$ %

\opt{ipodnano}{\warn{If your Nano has a stainless steel back and plastic front 
it is a 1st generation and is compatible with Rockbox.  If, on the other hand, 
your Nano has a one-piece aluminum body it is a 2nd generation Nano and there 
is currently no Rockbox port available.  Do not attempt to install the 
bootloader on a 2nd generation Nano}}


\warn{These instructions are preliminary and may contain errors! 
Please check the wiki for up-to-date and improved installation instructions!
If you find errors you're of course welcomed to report them so we can fix it
for the next daily builds.}

  Installing the boot loader is the trickiest part of the installation.
  \opt{ipodnano}{First, you need to find out which version of the Apple
    firmware you're running. To do this, start the Apple firmware and go to
    Settings screen. In the ``About'' screen you'll find the version number
    of the Apple firmware. Depending on the version number the installation
    is slightly different.}%
    
  The process is different depending on your operating system, but before
  starting, connect the \dap{} to the computer using either an USB
  %\fixme{or Firewire?} % Firewire is currently not supported.
  cable. Next, create a folder on the computer's hard drive and
  download the following file to that folder:
  \opt{ipodvideo}{\url{http://download.rockbox.org/bootloader/ipod/bootloader-video.bin}}
  \opt{ipodnano}{\url{http://download.rockbox.org/bootloader/ipod/bootloader-nano.bin}}
  \opt{ipodmini}{\url{http://download.rockbox.org/bootloader/ipod/bootloader-mini1g.bin} or
    \url{http://download.rockbox.org/bootloader/ipod/bootloader-mini2g.bin} depending on which
    generation your \dap{} is.\fixme{Describe how to identify 1/2G}}
  \opt{ipodcolor}{\url{http://download.rockbox.org/bootloader/ipod/bootloader-color.bin}}
  \opt{ipod4g}{\url{http://download.rockbox.org/bootloader/ipod/bootloader-4g.bin}}
  \opt{ipod3g}{\url{http://download.rockbox.org/bootloader/ipod/bootloader-3g.bin}}

  When that is done, proceed to the section below that matches the operating
  system on the computer.
  \note{These instructions all require you to have administrator rights
  on your computer, regardless of the operating system.}
  \note{Rockbox only works on FAT32 partitions (called ``Windows formatted'' by
    Apple). So if your \dap{} is Mac formatted (HFS+), you should first convert
    it to FAT32. Information on how to do this can be found on the Rockbox
    website. \fixme{Include these instructions?}}

\subsubsection{Windows users}
\begin{enumerate}
  \item Download the following two programs and save them in the folder just
    created. These programs will be used in the next steps:
    \begin{itemize}
      \item \url{http://download.rockbox.org/bootloader/ipod/ipodpatcher.exe}
      \item \url{http://download.rockbox.org/bootloader/ipod/ipod_fw.exe}
    \end{itemize}
  \item Locate the \dap{} by opening a command window. You can do this by
    clicking ``Start'', ``Execute'' and typing \fname{cmd}. Press Enter to
    execute that command. Now change directory to the
    folder you created and run the following commands:
    \begin{code}
    ipodpatcher 0
    ipodpatcher 1
    ipodpatcher 2
    ipodpatcher 3
    \end{code}
    Keep increasing the number until the \dap{} is located.

    The output for an unsuccessful attempt to contact the \dap{} looks like
    this:
    \begin{code}
    C:\textbackslash{}rockbox>ipodpatcher 0
    ipodpatcher v0.3 - (C) Dave Chapman 2006
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    [INFO] Reading partition table from \textbackslash\textbackslash{}.\textbackslash{}PhysicalDrive0
    Drive is not an iPod, aborting
    \end{code}
    
    A successful connection to the \dap{} will look similar to this...
    \begin{code}
    C:\textbackslash{}rockbox>ipodpatcher 6
    ipodpatcher v0.3 - (C) Dave Chapman 2006
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

    [INFO] Reading partition table from \textbackslash\textbackslash{}.\textbackslash{}PhysicalDrive6
    Part    Start Sector    End Sector    Size (MB)  Type
       0              63        160649        78.4   Empty (0x00)
       1          160650       7984304      3820.1   W95 FAT32 (0x0b)
   \end{code}
    Remember the number that corresponds to your \dap{} -- in the 
    following steps, \emph{N} should be replaced with the number just found.
  \item Now, extract the firmware partition currently on the \dap{} with the
    following command:
    \begin{code}
    ipodpatcher -r \emph{N} bootpartition.bin
    \end{code}
    \note{You should keep a safe backup of this \fname{bootpartition.bin} file
      for use if you ever wish to either upgrade the Rockbox boot loader or
      uninstall Rockbox from your Ipod}
  \item Extract the Apple firmware from the partition image image just created:
    \begin{code}
    ipod_fw -o apple_os.bin -e 0 bootpartition.bin
    \end{code}
  \opt{ipodnano}{\note{The following step is only necessary if your Apple
    firmware has version 1.2. If this doesn't apply to you, simply skip it.}}
\optv{ipodvideo,ipodnano}{
  \item
    Similarly, extract the Broadcom firmware:
    \begin{code}
    ipod_fw -o apple_sw_5g_rcsc.bin -e 1 bootpartition.bin
    \end{code}
}
  \item Merge the Rockbox boot loader you downloaded previously with the Apple
    firm\-ware.%
\optv{ipodnano}{
    If your firmware version is lower than 1.2 this works you need
    this command:
    \begin{code}
    ipod_fw -g nano -o rockboot.bin -i apple_os.bin bootloader-nano.bin
    \end{code}
    If your firmware version is 1.2 you need to use the following command
    instead. Please note that the ``video'' is correct.
    \begin{code}
    ipod_fw -g video -o rockboot.bin -i apple_os.bin bootloader-nano.bin
    \end{code}
}
\optv{ipodvideo}{
    \begin{code}
    ipod_fw -g video -o rockboot.bin -i apple_os.bin bootloader-video.bin
    \end{code}
}
\optv{ipodmini}{
    \begin{code}
    ipod_fw -g mini -o rockboot.bin -i apple_os.bin bootloader-mini1g.bin
    \end{code}
    Or, if you have a 2G mini:
    \begin{code}
    ipod_fw -g mini -o rockboot.bin -i apple_os.bin bootloader-mini2g.bin
    \end{code}
}
\optv{ipodcolor}{
    \begin{code}
    ipod_fw -g color -o rockboot.bin -i apple_os.bin bootloader-color.bin
    \end{code}
}
\optv{ipod4g}{
    \begin{code}
    ipod_fw -g 4g -o rockboot.bin -i apple_os.bin bootloader-4g.bin
    \end{code}
}
\item
    Install the Rockbox-enabled firmware:
    \begin{code}
    ipodpatcher -w \emph{N} rockboot.bin
    \end{code}
\end{enumerate}

Now you can proceed installing the firmware itself.

\subsubsection{Mac OS X users}
\begin{enumerate}
  \item Download the following two programs and save them in the folder just
    created. These programs will be used in the next steps:
    \begin{itemize}
      \item \url{http://download.rockbox.org/bootloader/ipod/diskdump}
      \item \url{http://download.rockbox.org/bootloader/ipod/ipod_fw}
    \end{itemize}
    Start a Terminal and type navigate into the folder you created. Before
    you can continue, you need to ensure that Mac OS knows that the
    \fname{ipod\_fw}
    and diskdump files you downloaded are executable programs. To do this,
    type the following command:
    \begin{code}
    chmod +x ipod_fw diskdump
    \end{code}
  \item Locate the \dap{} by running the following command:
    \begin{code}
    mount
    \end{code}
    The output will look something like this: \fixme{Add full example}
    \begin{code}
    /dev/disk1s2 on /Volumes/DAVE_S IPOD 1 (local, nodev, nosuid)
    \end{code}
    In this example, the \dap\ is located at /dev/disk1s2 Remember the 
    location of your \dap\  -- in the following steps, /dev/disk1s2 should be
    replaced with the location just found.
  \item Before continuing, the \dap\ must be ``unmounted'', which is
    done with the following command:
    \begin{code}
    diskutil unmount /dev/disk1s2
    \end{code}
  \item Now, extract the Apple firmware currently on the \dap{} with the
    following command:
    \note{The last part of the location is left out.}
    \begin{code}
    ./diskdump -r /dev/disk1 bootpartition.bin
    \end{code}
    \note{You should keep a safe backup of this \fname{bootpartition.bin} file
      for use if you ever wish to either upgrade the Rockbox bootloader or
      uninstall Rockbox from your iPod
    }
  \item Extract the Apple firmware from this partition image:
    \begin{code}
    ./ipod_fw -o apple_os.bin -e 0 bootpartition.bin
    \end{code}
  \opt{ipodnano}{\note{The following step is only necessary if your Apple
    firmware has version 1.2. If this doesn't apply to you, simply skip it.}}
\optv{ipodvideo,ipodnano}{
  \item
    Similarly, extract the Broadcom firmware:
    \begin{code}
    ./ipod_fw -o apple_sw_5g_rcsc.bin -e 1 bootpartition.bin
    \end{code}
}
  \item Merge the Rockbox bootloader you downloaded previously with the Apple
    firm\-ware.%
\optv{ipodnano}{
    If your firmware version is lower than 1.2 this works you need
    this command:
    \begin{code}
    ./ipod_fw -g nano -o rockboot.bin -i apple_os.bin bootloader-nano.bin
    \end{code}
    If your firmware version is 1.2 you need to use the following command
    instead. Please note that the ``video'' is correct.
    \begin{code}
    ./ipod_fw -g video -o rockboot.bin -i apple_os.bin bootloader-nano.bin
    \end{code}
}
\optv{ipodvideo}{
    \begin{code}
    ./ipod_fw -g video -o rockboot.bin -i apple_os.bin bootloader-video.bin
    \end{code}
}
\optv{ipodmini}{
    \begin{code}
    ./ipod_fw -g mini -o rockboot.bin -i apple_os.bin bootloader-mini1g.bin
    \end{code}
    Or, if you have a 2G Mini:
    \begin{code}
    ./ipod_fw -g mini -o rockboot.bin -i apple_os.bin bootloader-mini2g.bin
    \end{code}
}
\optv{ipodcolor}{
    \begin{code}
    ./ipod_fw -g color -o rockboot.bin -i apple_os.bin bootloader-color.bin
    \end{code}
}
\optv{ipod4g}{
    \begin{code}
    ./ipod_fw -g 4g -o rockboot.bin -i apple_os.bin bootloader-4g.bin
    \end{code}
}
\optv{ipod3g}{
    \begin{code}
    ./ipod_fw -g 3g -o rockboot.bin -i apple_os.bin bootloader-3g.bin
    \end{code}
}
  \item
    Install the Rockbox-enabled firmware:
    \note{The last part of the location is left out.}
    \begin{code}
    ./diskdump -w /dev/disk1 rockboot.bin
    \end{code}
\end{enumerate}

Now, proceed with installing the firmware itself.

\subsubsection{Linux users}
\begin{enumerate}
  \item Download the following and save it in the folder just
    created:
    \begin{itemize}
      \item \url{http://www.rockbox.org/viewcvs.cgi/*checkout*/tools/ipod_fw.c}
    \end{itemize}
    Now compile it to an executable by opening a command prompt and changing
    to the folder created previously. Then run the following command:
    \begin{code}
    gcc -o ipod_fw ipod_fw.c
    \end{code}
    If you get the message that the command gcc is not found, you need to
    install gcc. How to do this depends on your Linux distribution, and
    you should consult its documentation for help on this.
  \item Locate your Ipod by running the command \verb|dmesg|. In the output
    something like the following should be seen:
\begin{code}
    usb 4-1: new high speed USB device using ehci_hcd and address 7
    scsi4 : SCSI emulation for USB Mass Storage devices
    usb-storage: device found at 7
    usb-storage: waiting for device to settle before scanning
      Vendor: Apple     Model: iPod              Rev: 1.62
      Type:   Direct-Access                      ANSI SCSI revision: 00
    SCSI device sdb: 58605120 512-byte hdwr sectors (30006 MB)
\end{code}
    You need the device name of your \dap, which you can find in the last line.
    In this example, the \dap\ is located on \fname{/dev/sdb}. In the following,
    \fname{/dev/sdb} should be replaced with the location just found.
  \item Run \verb|fdisk -l /dev/sdb|. Verify that the
    output is similar to the one below:
    \begin{code}
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1          10       80293+   0  Empty
    /dev/sdb2              11        3648    29222235    b  W95 FAT32
    \end{code}
  \item Back up the partition table using the following command:
    \note{The last part of the location is left out.}
    \begin{code}
    dd if=/dev/\emph{sdb} of=mbr.bin count=1
    \end{code}

  \item Now, extract the firmware partition currently on the \dap{} with the
    following command:
    \begin{code}
    dd if=/dev/\emph{sdb1} of=bootpartition.bin
    \end{code}
    \note{You should keep a safe backup of this \fname{bootpartition.bin} file
      for use if you ever wish to either upgrade the Rockbox bootloader or
      uninstall Rockbox from your Ipod
    }
  \item Extract the Apple firmware from this partition image:
    \begin{code}
    ./ipod_fw -o apple_os.bin -e 0 bootpartition.bin
    \end{code}
  \opt{ipodnano}{\note{The following step is only necessary if your Apple
    firmware has version 1.2. If this doesn't apply to you, simply skip it.}}
\optv{ipodvideo,ipodnano}{
  \item
    Similarly, extract the Broadcom firmware:
    \begin{code}
    ./ipod_fw -o apple_sw_5g_rcsc.bin -e 1 bootpartition.bin
    \end{code}
}

  \item Merge the Rockbox bootloader you downloaded previously with the Apple
    firm\-ware.%
\optv{ipodnano}{
    If your firmware version is lower than 1.2 this works you need
    this command:
    \begin{code}
    ./ipod_fw -g nano -o rockboot.bin -i apple_os.bin bootloader-nano.bin
    \end{code}
    If your firmware version is 1.2 you need to use the following command
    instead. Please note that the ``video'' is correct.
    \begin{code}
    ./ipod_fw -g video -o rockboot.bin -i apple_os.bin bootloader-nano.bin
    \end{code}

}
\optv{ipodvideo}{
    \begin{code}
    ./ipod_fw -g video -o rockboot.bin -i apple_os.bin bootloader-video.bin
    \end{code}
}
\optv{ipodmini}{
    \begin{code}
    ./ipod_fw -g mini -o rockboot.bin -i apple_os.bin bootloader-mini1g.bin
    \end{code}
    Or, if you have a 2G Mini:
    \begin{code}
    ./ipod_fw -g mini -o rockboot.bin -i apple_os.bin bootloader-mini2g.bin
    \end{code}
}
\optv{ipodcolor}{
    \begin{code}
    ./ipod_fw -g color -o rockboot.bin -i apple_os.bin bootloader-color.bin
    \end{code}
}
\optv{ipod4g}{
    \begin{code}
    ./ipod_fw -g 4g -o rockboot.bin -i apple_os.bin bootloader-4g.bin
    \end{code}
}
  \item
    Install the Rockbox-enabled firmware:
    \begin{code}
    dd if=rockboot.bin of=/dev/\emph{sdb1}
    \end{code}
\end{enumerate}
Now you can install the firmware itself.

