diff options
Diffstat (limited to 'firmware/target/arm/imx233/mmc-imx233.c')
-rw-r--r-- | firmware/target/arm/imx233/mmc-imx233.c | 71 |
1 files changed, 43 insertions, 28 deletions
diff --git a/firmware/target/arm/imx233/mmc-imx233.c b/firmware/target/arm/imx233/mmc-imx233.c index 889ba0cb82..d2e76e7f6c 100644 --- a/firmware/target/arm/imx233/mmc-imx233.c +++ b/firmware/target/arm/imx233/mmc-imx233.c | |||
@@ -41,9 +41,15 @@ | |||
41 | /** When set, this values restrict the windows of the read and writes */ | 41 | /** When set, this values restrict the windows of the read and writes */ |
42 | static unsigned mmc_window_start = 0; | 42 | static unsigned mmc_window_start = 0; |
43 | static unsigned mmc_window_end = INT_MAX; | 43 | static unsigned mmc_window_end = INT_MAX; |
44 | static bool mmc_window_enable = true; | ||
44 | 45 | ||
45 | static struct mutex mmc_mutex; | 46 | static struct mutex mmc_mutex; |
46 | 47 | ||
48 | void imx233_mmc_disable_window(void) | ||
49 | { | ||
50 | mmc_window_enable = false; | ||
51 | } | ||
52 | |||
47 | int mmc_init(void) | 53 | int mmc_init(void) |
48 | { | 54 | { |
49 | mutex_init(&mmc_mutex); | 55 | mutex_init(&mmc_mutex); |
@@ -123,34 +129,37 @@ int mmc_init(void) | |||
123 | imx233_ssp_set_timings(MMC_SSP, 2, 0, 0xffff); | 129 | imx233_ssp_set_timings(MMC_SSP, 2, 0, 0xffff); |
124 | 130 | ||
125 | #ifdef SANSA_FUZEPLUS | 131 | #ifdef SANSA_FUZEPLUS |
126 | /** | 132 | if(mmc_window_enable) |
127 | * The Fuze+ uses a strange layout: is has a first MBR at sector 0 with four entries: | 133 | { |
128 | * 1) Actual user partition | 134 | /** |
129 | * 2) Sigmatel boot partition | 135 | * The Fuze+ uses a strange layout: is has a first MBR at sector 0 with four entries: |
130 | * 3)4) Other (certificate related ?) partitions | 136 | * 1) Actual user partition |
131 | * The partition 1) has type 1 but it's actually a type 5 (logical partition) with | 137 | * 2) Sigmatel boot partition |
132 | * a second partition table with usually one entry which is the FAT32 one. | 138 | * 3)4) Other (certificate related ?) partitions |
133 | * The first table uses 512-byte sector size and the second one usually uses | 139 | * The partition 1) has type 1 but it's actually a type 5 (logical partition) with |
134 | * 2048-byte logical sector size. | 140 | * a second partition table with usually one entry which is the FAT32 one. |
135 | * | 141 | * The first table uses 512-byte sector size and the second one usually uses |
136 | * We restrict mmc window to the user partition */ | 142 | * 2048-byte logical sector size. |
137 | uint8_t mbr[512]; | 143 | * |
138 | mmc_window_start = 0; | 144 | * We restrict mmc window to the user partition */ |
139 | mmc_window_end = INT_MAX; | 145 | uint8_t mbr[512]; |
140 | ret = mmc_read_sectors(IF_MD2(0,) 0, 1, mbr); | 146 | mmc_window_start = 0; |
141 | if(ret != 0) | 147 | mmc_window_end = INT_MAX; |
142 | return -100; | 148 | ret = mmc_read_sectors(IF_MD2(0,) 0, 1, mbr); |
143 | if(mbr[510] != 0x55 || mbr[511] != 0xAA) | 149 | if(ret != 0) |
144 | return -101; /* invalid MBR */ | 150 | return -100; |
145 | /* sanity check that the first partition is greater than 2Gib */ | 151 | if(mbr[510] != 0x55 || mbr[511] != 0xAA) |
146 | uint8_t *ent = &mbr[446]; | 152 | return -101; /* invalid MBR */ |
147 | mmc_window_start = ent[8] | ent[9] << 8 | ent[10] << 16 | ent[11] << 24; | 153 | /* sanity check that the first partition is greater than 2Gib */ |
148 | mmc_window_end = (ent[12] | ent[13] << 8 | ent[14] << 16 | ent[15] << 24) + | 154 | uint8_t *ent = &mbr[446]; |
149 | mmc_window_start; | 155 | mmc_window_start = ent[8] | ent[9] << 8 | ent[10] << 16 | ent[11] << 24; |
150 | if(ent[4] == 0x53) | 156 | mmc_window_end = (ent[12] | ent[13] << 8 | ent[14] << 16 | ent[15] << 24) + |
151 | return -102; /* sigmatel partition */ | 157 | mmc_window_start; |
152 | if((mmc_window_end - mmc_window_start) < 4 * 1024 * 1024) | 158 | if(ent[4] == 0x53) |
153 | return -103; /* partition too small */ | 159 | return -102; /* sigmatel partition */ |
160 | if((mmc_window_end - mmc_window_start) < 4 * 1024 * 1024) | ||
161 | return -103; /* partition too small */ | ||
162 | } | ||
154 | #endif | 163 | #endif |
155 | 164 | ||
156 | return 0; | 165 | return 0; |
@@ -221,3 +230,9 @@ bool mmc_present(IF_MD(int drive)) | |||
221 | IF_MD((void) drive); | 230 | IF_MD((void) drive); |
222 | return true; | 231 | return true; |
223 | } | 232 | } |
233 | |||
234 | bool mmc_removable(IF_MD(int drive)) | ||
235 | { | ||
236 | IF_MD((void) drive); | ||
237 | return false; | ||
238 | } | ||