summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/imx233/partitions-imx233.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-10-22 00:03:04 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-10-22 00:07:07 +0200
commit7d62a78af47e77e3d4f6b8b37545d1abcc436f57 (patch)
tree0a47e503470ba46b2db5e9da8004b431ca3f399f /firmware/target/arm/imx233/partitions-imx233.c
parent5c7167c79c369973969f2199efa191cdf857a1a4 (diff)
downloadrockbox-7d62a78af47e77e3d4f6b8b37545d1abcc436f57.tar.gz
rockbox-7d62a78af47e77e3d4f6b8b37545d1abcc436f57.zip
imx233: extend partition window support to be more generic
The new code can select among several types of window (user, system, ...). Furthermore, the type of partitions to use is selectable in config file. Currently, two types are support: Freescale style MBR and Creative MBLK Change-Id: I969d60a3d08f2c9448fb4b9c440051b7801b94cd
Diffstat (limited to 'firmware/target/arm/imx233/partitions-imx233.c')
-rw-r--r--firmware/target/arm/imx233/partitions-imx233.c139
1 files changed, 123 insertions, 16 deletions
diff --git a/firmware/target/arm/imx233/partitions-imx233.c b/firmware/target/arm/imx233/partitions-imx233.c
index 06c5a48f32..ebc7b9a6e6 100644
--- a/firmware/target/arm/imx233/partitions-imx233.c
+++ b/firmware/target/arm/imx233/partitions-imx233.c
@@ -19,6 +19,7 @@
*
****************************************************************************/
#include "partitions-imx233.h"
+#include "string.h"
static bool enable_window = true;
@@ -32,8 +33,79 @@ bool imx233_partitions_is_window_enabled(void)
return enable_window;
}
-int imx233_partitions_compute_window(uint8_t mbr[512], unsigned *start, unsigned *end)
+#if (IMX233_PARTITIONS & IMX233_CREATIVE)
+#define MBLK_MAGIC 0x4d424c4b /* MBLK */
+#define MBLK_COUNT 31
+/* MBLK is not located in the first sector !
+ * Creative code uses the hard-coded *absolute* address 0x3ffe00,
+ * bypassing all partition related information !!
+ * NOTE: for some reason, the ZEN uses a different value ?! */
+#ifdef CREATIVE_ZEN
+#define MBLK_ADDR 0x400000
+#else
+#define MBLK_ADDR 0x3ffe00
+#endif
+
+struct mblk_header_t
+{
+ uint32_t magic;
+ uint32_t block_size;
+ uint64_t total_size;
+} __attribute__((packed));
+
+struct mblk_partition_t
+{
+ uint32_t size;
+ uint32_t start;
+ char name[8];
+} __attribute__((packed));
+
+static const char *creative_part_name(enum imx233_part_t part)
+{
+ switch(part)
+ {
+ case IMX233_PART_USER: return "cfs";
+ case IMX233_PART_CFS: return "cfs";
+ case IMX233_PART_MINIFS: return "minifs";
+ default: return "";
+ }
+}
+
+static int compute_window_creative(IF_MD(int drive,) enum imx233_part_t part,
+ unsigned *start, unsigned *end)
{
+ uint8_t mblk[512];
+ int ret = storage_read_sectors(IF_MD(drive,) MBLK_ADDR / 512, 1, mblk);
+ if(ret < 0)
+ return ret;
+ struct mblk_header_t *hdr = (void *)mblk;
+ if(hdr->magic != MBLK_MAGIC)
+ return -70; /* bad magic */
+ struct mblk_partition_t *ent = (void *)(hdr + 1);
+ const char *name = creative_part_name(part);
+ for(int i = 0; i < MBLK_COUNT; i++)
+ {
+ if(ent[i].name[0] == 0)
+ continue;
+ if(strcmp(ent[i].name, name) == 0)
+ {
+ *start = ent[i].start * hdr->block_size / 512;
+ *end = *start + ent[i].size * hdr->block_size / 512;
+ return 0;
+ }
+ }
+ return -80; /* not found */
+}
+#endif /* #(IMX233_PARTITIONS & IMX233_CREATIVE) */
+
+#if (IMX233_PARTITIONS & IMX233_FREESCALE)
+static int compute_window_freescale(IF_MD(int drive,) enum imx233_part_t part,
+ unsigned *start, unsigned *end)
+{
+ uint8_t mbr[512];
+ int ret = storage_read_sectors(IF_MD(drive,) 0, 1, mbr);
+ if(ret < 0)
+ return ret;
/**
* Freescale uses a strange layout: is has a first MBR at sector 0 with four entries:
* 1) Actual user partition
@@ -54,19 +126,54 @@ int imx233_partitions_compute_window(uint8_t mbr[512], unsigned *start, unsigned
* it seems that it is similarly truncated. */
if(mbr[510] != 0x55 || mbr[511] != 0xAA)
return -101; /* invalid MBR */
- /* sanity check that the first partition is greater than 2Gib */
- uint8_t *ent = &mbr[446];
- *start = ent[8] | ent[9] << 8 | ent[10] << 16 | ent[11] << 24;
- /* ignore two lowest bits(see comment above) */
- *start &= ~3;
- *end = (ent[12] | ent[13] << 8 | ent[14] << 16 | ent[15] << 24);
- *end &= ~3;
- /* ignore two lowest bits(order is important, first truncate then add start) */
- *end += *start;
-
- if(ent[4] == 0x53)
- return -102; /* sigmatel partition */
- if((*end - *start) < 4 * 1024 * 1024)
- return -103; /* partition too small */
- return 0;
+ if(part == IMX233_PART_USER)
+ {
+ /* sanity check that the first partition is greater than 2Gib */
+ uint8_t *ent = &mbr[446];
+ *start = ent[8] | ent[9] << 8 | ent[10] << 16 | ent[11] << 24;
+ /* ignore two lowest bits(see comment above) */
+ *start &= ~3;
+ *end = (ent[12] | ent[13] << 8 | ent[14] << 16 | ent[15] << 24);
+ *end &= ~3;
+ /* ignore two lowest bits(order is important, first truncate then add start) */
+ *end += *start;
+
+ if(ent[4] == 0x53)
+ return -102; /* sigmatel partition */
+ if((*end - *start) < 4 * 1024 * 1024)
+ return -103; /* partition too small */
+ return 0;
+ }
+ else if(part == IMX233_PART_BOOT)
+ {
+ /* sanity check that the second partition is correct */
+ uint8_t *ent = &mbr[462];
+ if(ent[4] != 0x53)
+ return -104; /* wrong type */
+ *start = ent[8] | ent[9] << 8 | ent[10] << 16 | ent[11] << 24;
+ *end = (ent[12] | ent[13] << 8 | ent[14] << 16 | ent[15] << 24);
+ *end += *start;
+
+ return 0;
+ }
+ else
+ return -50;
+}
+#endif /* (IMX233_PARTITIONS & IMX233_FREESCALE) */
+
+int imx233_partitions_compute_window(IF_MD(int drive,) enum imx233_part_t part,
+ unsigned *start, unsigned *end)
+{
+ int ret = -1;
+#if (IMX233_PARTITIONS & IMX233_CREATIVE)
+ ret = compute_window_creative(IF_MD(drive,) part, start, end);
+ if(ret >= 0)
+ return ret;
+#endif
+#if (IMX233_PARTITIONS & IMX233_FREESCALE)
+ ret = compute_window_freescale(IF_MD(drive,) part, start, end);
+ if(ret >= 0)
+ return ret;
+#endif
+ return ret;
}