blob: 5b10fdca46eb7b5da706fbbc29b242153f43cf7b [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001/*
2 * Copyright (c) 2010, Code Aurora Forum. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of Code Aurora Forum, Inc. nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#ifndef MMCUTILS_H_
31#define MMCUTILS_H_
32
33/* Some useful define used to access the MBR/EBR table */
34#define BLOCK_SIZE 0x200
35#define TABLE_ENTRY_0 0x1BE
36#define TABLE_ENTRY_1 0x1CE
37#define TABLE_ENTRY_2 0x1DE
38#define TABLE_ENTRY_3 0x1EE
39#define TABLE_SIGNATURE 0x1FE
40#define TABLE_ENTRY_SIZE 0x010
41
42#define OFFSET_STATUS 0x00
43#define OFFSET_TYPE 0x04
44#define OFFSET_FIRST_SEC 0x08
45#define OFFSET_SIZE 0x0C
46#define COPYBUFF_SIZE (1024 * 16)
47#define BINARY_IN_TABLE_SIZE (16 * 512)
48#define MAX_FILE_ENTRIES 20
49
50#define MMC_BOOT_TYPE 0x48
51#define MMC_SYSTEM_TYPE 0x82
52#define MMC_USERDATA_TYPE 0x83
53#define MMC_RECOVERY_TYPE 0x71
54
55#define MMC_RCA 2
56
57#define MAX_PARTITIONS 64
58
59#define GET_LWORD_FROM_BYTE(x) ((unsigned)*(x) | \
60 ((unsigned)*((x)+1) << 8) | \
61 ((unsigned)*((x)+2) << 16) | \
62 ((unsigned)*((x)+3) << 24))
63
64#define PUT_LWORD_TO_BYTE(x, y) do{*(x) = (y) & 0xff; \
65 *((x)+1) = ((y) >> 8) & 0xff; \
66 *((x)+2) = ((y) >> 16) & 0xff; \
67 *((x)+3) = ((y) >> 24) & 0xff; }while(0)
68
69#define GET_PAR_NUM_FROM_POS(x) ((((x) & 0x0000FF00) >> 8) + ((x) & 0x000000FF))
70
71#define MMC_BOOT_TYPE 0x48
72#define MMC_EXT3_TYPE 0x83
73#define MMC_VFAT_TYPE 0xC
74typedef struct MmcPartition MmcPartition;
75
76/* Functions */
77int mmc_scan_partitions();
78const MmcPartition *mmc_find_partition_by_name(const char *name);
79int mmc_format_ext3 (MmcPartition *partition);
80int mmc_mount_partition(const MmcPartition *partition, const char *mount_point, \
81 int read_only);
82int mmc_raw_copy (const MmcPartition *partition, char *in_file);
83int mmc_raw_read (const MmcPartition *partition, char *data, int data_size);
84int mmc_raw_write (const MmcPartition *partition, char *data, int data_size);
85
86int format_ext2_device(const char *device);
87int format_ext3_device(const char *device);
88
89#endif // MMCUTILS_H_
90
91