1 /***************************************************************************
2 * Copyright (C) 2007 by Arep *
3 * Support is provided through the forums at *
4 * http://wii.console-tribe.com *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
23 * \brief Memory dump functions specific to drives based on the Hitachi MN103 chip.
25 * Drives which are supported by this set of functions are, for instance, the LG GDR-8161B, GDR-8162B, GDR-8163B and GDR-8164B. All testing has been performed
26 * with the latter model, so I'm not really sure about the others, but they should work ;). Please report any issues and more compatible drives!
28 * This file contains code derived from the work of Kevin East (SeventhSon), kev@kev.nu, http://www.kev.nu/360/ , which, in turn, derives from work by
29 * a lot of other people. See his page for full details.
33 #include <sys/types.h>
35 #include "dvd_drive.h"
37 /*! \brief Memory offset at which the drive cache memory is mapped.
39 * During READ, sector data is cached beginning at this address.
42 #define HITACHI_MEM_BASE 0x80000000
46 * Dumps a single block (with arbitrary size) of the address space of the MN103 microcontroller within the Hitachi-LG Xbox 360 DVD drive and similar drives.
47 * This function is derived from the work of Kevin East (SeventhSon), kev@kev.nu, http://www.kev.nu/360/.
48 * @param dvd The DVD drive the command should be exectued on.
49 * @param offset The absolute memory offset to start dumping.
50 * @param block_size The block size for the dump.
51 * @param buf Where to place the dumped data. This must have been setup by the caller to store up to block_size bytes.
52 * @return < 0 if an error occurred, 0 otherwise.
54 int hitachi_dvd_dump_memblock (dvd_drive *dvd, u_int32_t offset, u_int32_t block_size, u_int8_t *buf) {
59 error ("NULL buffer");
61 } else if (!block_size || block_size > 65535) {
62 error ("invalid block_size (valid: 1 - 65535)");
65 dvd_init_command (&mmc, buf, block_size, NULL);
66 mmc.cmd[0] = 0xE7; // vendor specific command (discovered by DaveX)
67 mmc.cmd[1] = 0x48; // H
68 mmc.cmd[2] = 0x49; // I
69 mmc.cmd[3] = 0x54; // T
70 mmc.cmd[4] = 0x01; // read MCU memory sub-command
71 mmc.cmd[6] = (unsigned char) ((offset & 0xFF000000) >> 24); // address MSB
72 mmc.cmd[7] = (unsigned char) ((offset & 0x00FF0000) >> 16); // address
73 mmc.cmd[8] = (unsigned char) ((offset & 0x0000FF00) >> 8); // address
74 mmc.cmd[9] = (unsigned char) (offset & 0x000000FF); // address LSB
75 mmc.cmd[10] = (unsigned char) ((block_size & 0xFF00) >> 8); // length MSB
76 mmc.cmd[11] = (unsigned char) (block_size & 0x00FF); // length LSB
78 out = dvd_execute_cmd (dvd, &mmc, false);
86 * Dumps a given portion of the address space of the MN103 microcontroller within the Hitachi-LG Xbox 360 DVD drive.
87 * WARNING: it can take a while to dump a lot of data.
88 * @param dvd The DVD drive the command should be exectued on.
89 * @param offset The absolute memory offset to start dumping.
90 * @param block_len The number of blocks to dump.
91 * @param block_size The block size for the dump.
92 * @param buf Where to place the dumped data. This must have been setup by the caller to store up to block_size bytes.
93 * @return < 0 if an error occurred, 0 otherwise.
95 int hitachi_dvd_dump_mem_generic (dvd_drive *dvd, u_int32_t offset, u_int32_t block_len, u_int32_t block_size, u_int8_t *buf) {
100 error ("NULL buffer");
104 for (i = 0; i < block_len; i++) {
105 if ((r = hitachi_dvd_dump_memblock (dvd, offset + i * block_size, block_size, buf + i * block_size)) < 0) {
106 error ("hitachi_dvd_read_block() failed with %d", r);
118 * Dumps a given portion of the address space of the MN103 microcontroller within the Hitachi-LG Xbox 360 DVD drive, starting at the offset at which
119 * sector data are cached.
120 * WARNING: it can take a while to dump a lot of data.
121 * @param dvd The DVD drive the command should be exectued on.
122 * @param offset The memory offset to start dumping, relative to the cache start offset.
123 * @param block_len The number of blocks to dump.
124 * @param block_size The block size for the dump.
125 * @param buf Where to place the dumped data. This must have been setup by the caller to store up to block_size bytes.
126 * @return < 0 if an error occurred, 0 otherwise.
128 int hitachi_dvd_dump_mem (dvd_drive *dvd, u_int32_t offset, u_int32_t block_len, u_int32_t block_size, u_int8_t *buf) {
134 error ("NULL buffer");
137 base = dvd_get_hlds_e7_cache_base (dvd);
139 base = HITACHI_MEM_BASE;
141 for (i = 0; i < block_len; i++) {
142 if ((r = hitachi_dvd_dump_memblock (dvd, base + offset + i * block_size, block_size, buf + i * block_size)) < 0) {
143 error ("hitachi_dvd_read_block() failed with %d", r);