blob: 4fece7981bb6d8c58aab250ac4bcc55a6a6fb2eb [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 */
Ethan Yonker58f21322018-08-24 11:17:36 -050034#ifndef BLOCK_SIZE
Dees_Troy51a0e822012-09-05 15:24:24 -040035#define BLOCK_SIZE 0x200
Ethan Yonker58f21322018-08-24 11:17:36 -050036#endif
Dees_Troy51a0e822012-09-05 15:24:24 -040037#define TABLE_ENTRY_0 0x1BE
38#define TABLE_ENTRY_1 0x1CE
39#define TABLE_ENTRY_2 0x1DE
40#define TABLE_ENTRY_3 0x1EE
41#define TABLE_SIGNATURE 0x1FE
42#define TABLE_ENTRY_SIZE 0x010
43
44#define OFFSET_STATUS 0x00
45#define OFFSET_TYPE 0x04
46#define OFFSET_FIRST_SEC 0x08
47#define OFFSET_SIZE 0x0C
48#define COPYBUFF_SIZE (1024 * 16)
49#define BINARY_IN_TABLE_SIZE (16 * 512)
50#define MAX_FILE_ENTRIES 20
51
52#define MMC_BOOT_TYPE 0x48
53#define MMC_SYSTEM_TYPE 0x82
54#define MMC_USERDATA_TYPE 0x83
55#define MMC_RECOVERY_TYPE 0x71
56
57#define MMC_RCA 2
58
59#define MAX_PARTITIONS 64
60
61#define GET_LWORD_FROM_BYTE(x) ((unsigned)*(x) | \
62 ((unsigned)*((x)+1) << 8) | \
63 ((unsigned)*((x)+2) << 16) | \
64 ((unsigned)*((x)+3) << 24))
65
66#define PUT_LWORD_TO_BYTE(x, y) do{*(x) = (y) & 0xff; \
67 *((x)+1) = ((y) >> 8) & 0xff; \
68 *((x)+2) = ((y) >> 16) & 0xff; \
69 *((x)+3) = ((y) >> 24) & 0xff; }while(0)
70
71#define GET_PAR_NUM_FROM_POS(x) ((((x) & 0x0000FF00) >> 8) + ((x) & 0x000000FF))
72
73#define MMC_BOOT_TYPE 0x48
74#define MMC_EXT3_TYPE 0x83
75#define MMC_VFAT_TYPE 0xC
76typedef struct MmcPartition MmcPartition;
77
78/* Functions */
79int mmc_scan_partitions();
80const MmcPartition *mmc_find_partition_by_name(const char *name);
Ethan Yonker58f21322018-08-24 11:17:36 -050081int mmc_format_ext3 (const MmcPartition *partition);
Dees_Troy51a0e822012-09-05 15:24:24 -040082int mmc_mount_partition(const MmcPartition *partition, const char *mount_point, \
83 int read_only);
Ethan Yonker58f21322018-08-24 11:17:36 -050084int mmc_raw_copy (const MmcPartition *partition, const char *in_file);
Dees_Troy51a0e822012-09-05 15:24:24 -040085int mmc_raw_read (const MmcPartition *partition, char *data, int data_size);
86int mmc_raw_write (const MmcPartition *partition, char *data, int data_size);
87
Ethan Yonker58f21322018-08-24 11:17:36 -050088int format_ext2_device(char *device);
89int format_ext3_device(char *device);
Dees_Troy51a0e822012-09-05 15:24:24 -040090
91#endif // MMCUTILS_H_
92
93