diff options
author | Alexander Tarasikov <alexander.tarasikov@gmail.com> | 2012-07-03 20:40:42 +0400 |
---|---|---|
committer | Paul Kocialkowski <contact@paulk.fr> | 2012-07-04 17:53:02 +0200 |
commit | 698f40a05bf4b170cf326fd138144378108b3bbf (patch) | |
tree | f54b5982dc2390b8edd7f74afd390a07bee54ca5 | |
parent | 364343a86c168d0211e29720665bc0f58737a09c (diff) | |
download | external_libsamsung-ipc-698f40a05bf4b170cf326fd138144378108b3bbf.zip external_libsamsung-ipc-698f40a05bf4b170cf326fd138144378108b3bbf.tar.gz external_libsamsung-ipc-698f40a05bf4b170cf326fd138144378108b3bbf.tar.bz2 |
Allow EFS path to be overriden per-board
-rw-r--r-- | samsung-ipc/device/xmm6260/xmm6260_ipc.c | 8 | ||||
-rw-r--r-- | samsung-ipc/ipc.c | 2 | ||||
-rw-r--r-- | samsung-ipc/ipc_devices.c | 54 | ||||
-rw-r--r-- | samsung-ipc/ipc_devices.h | 4 | ||||
-rw-r--r-- | samsung-ipc/ipc_private.h | 9 | ||||
-rw-r--r-- | samsung-ipc/rfs.c | 131 |
6 files changed, 170 insertions, 38 deletions
diff --git a/samsung-ipc/device/xmm6260/xmm6260_ipc.c b/samsung-ipc/device/xmm6260/xmm6260_ipc.c index cc39b6f..8fdc388 100644 --- a/samsung-ipc/device/xmm6260/xmm6260_ipc.c +++ b/samsung-ipc/device/xmm6260/xmm6260_ipc.c @@ -431,4 +431,12 @@ struct ipc_ops xmm6260_rfs_ops = { .bootstrap = NULL, }; +struct ipc_fs_ops xmm6260_i9250_fs_ops = { + .nv_data_path = "/factory/nv_data.bin", + .nv_data_md5_path = "/factory/nv_data.bin.md5", + .nv_state_path = "/factory/.nv_state", + .nv_data_bak_path = "/factory/.nv_data.bak", + .nv_data_md5_bak_path = "/factory/.nv_data.bak.md5", +}; + // vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c index 301f452..6bfcc8f 100644 --- a/samsung-ipc/ipc.c +++ b/samsung-ipc/ipc.c @@ -140,6 +140,8 @@ struct ipc_client* ipc_client_new(int client_type) break; } + client->fs_ops = ipc_devices[device_index].fs_ops; + client->handlers = (struct ipc_handlers *) malloc(sizeof(struct ipc_handlers)); client->log_handler = log_handler_default; diff --git a/samsung-ipc/ipc_devices.c b/samsung-ipc/ipc_devices.c index 60ca767..e1c12aa 100644 --- a/samsung-ipc/ipc_devices.c +++ b/samsung-ipc/ipc_devices.c @@ -23,12 +23,54 @@ #include "ipc_devices.h" struct ipc_device_desc ipc_devices[] = { - { "galaxys2", "i9100", &xmm6260_default_handlers, &xmm6260_i9100_fmt_ops, &xmm6260_rfs_ops }, - { "galaxys2", "smdk4210", &xmm6260_default_handlers, &xmm6260_i9100_fmt_ops, &xmm6260_rfs_ops }, - { "maguro", "tuna", &xmm6260_default_handlers, &xmm6260_i9250_fmt_ops, &xmm6260_rfs_ops }, - { "crespo", "herring", &crespo_default_handlers, &crespo_fmt_ops, &crespo_rfs_ops }, - { "aries", "aries", &aries_default_handlers, &aries_fmt_ops, &aries_rfs_ops }, - { "aries", "gt-p1000", &aries_default_handlers, &aries_fmt_ops, &aries_rfs_ops } + { + .name = "galaxys2", + .board_name = "i9100", + .handlers = &xmm6260_default_handlers, + .fmt_ops = &xmm6260_i9100_fmt_ops, + .rfs_ops = &xmm6260_rfs_ops, + .fs_ops = NULL, + }, + { + .name = "galaxys2", + .board_name = "smdk4210", + .handlers = &xmm6260_default_handlers, + .fmt_ops = &xmm6260_i9100_fmt_ops, + .rfs_ops = &xmm6260_rfs_ops, + .fs_ops = NULL, + }, + { + .name = "maguro", + .board_name = "tuna", + .handlers = &xmm6260_default_handlers, + .fmt_ops = &xmm6260_i9250_fmt_ops, + .rfs_ops = &xmm6260_rfs_ops, + .fs_ops = &xmm6260_i9250_fs_ops, + }, + { + .name = "crespo", + .board_name = "herring", + .handlers = &crespo_default_handlers, + .fmt_ops = &crespo_fmt_ops, + .rfs_ops = &crespo_rfs_ops, + .fs_ops = NULL, + }, + { + .name = "aries", + .board_name = "aries", + .handlers = &aries_default_handlers, + .fmt_ops = &aries_fmt_ops, + .rfs_ops = &aries_rfs_ops, + .fs_ops = NULL, + }, + { + .name = "aries", + .board_name = "gt-p1000", + .handlers = &aries_default_handlers, + .fmt_ops = &aries_fmt_ops, + .rfs_ops = &aries_rfs_ops, + .fs_ops = NULL, + } }; int ipc_devices_count = sizeof(ipc_devices) / sizeof(struct ipc_device_desc); diff --git a/samsung-ipc/ipc_devices.h b/samsung-ipc/ipc_devices.h index 6050bf5..6c987f4 100644 --- a/samsung-ipc/ipc_devices.h +++ b/samsung-ipc/ipc_devices.h @@ -30,6 +30,7 @@ struct ipc_device_desc { struct ipc_handlers *handlers; struct ipc_ops *fmt_ops; struct ipc_ops *rfs_ops; + struct ipc_fs_ops *fs_ops; }; extern struct ipc_device_desc ipc_devices[]; @@ -40,9 +41,10 @@ extern int ipc_devices_count; // Galaxy Nexus (I9250) extern struct ipc_handlers xmm6260_default_handlers; +extern struct ipc_ops xmm6260_rfs_ops; extern struct ipc_ops xmm6260_i9100_fmt_ops; extern struct ipc_ops xmm6260_i9250_fmt_ops; -extern struct ipc_ops xmm6260_rfs_ops; +extern struct ipc_fs_ops xmm6260_i9250_fs_ops; // h1 diff --git a/samsung-ipc/ipc_private.h b/samsung-ipc/ipc_private.h index c43833c..5c349b4 100644 --- a/samsung-ipc/ipc_private.h +++ b/samsung-ipc/ipc_private.h @@ -63,6 +63,14 @@ struct ipc_handlers { int (*common_data_get_fd)(void *io_data); }; +struct ipc_fs_ops { + char *nv_data_path; + char *nv_data_md5_path; + char *nv_state_path; + char *nv_data_bak_path; + char *nv_data_md5_bak_path; +}; + struct ipc_client { int type; @@ -71,6 +79,7 @@ struct ipc_client { struct ipc_ops *ops; struct ipc_handlers *handlers; + struct ipc_fs_ops *fs_ops; }; void ipc_client_log(struct ipc_client *client, const char *message, ...); diff --git a/samsung-ipc/rfs.c b/samsung-ipc/rfs.c index 79950c0..97434ec 100644 --- a/samsung-ipc/rfs.c +++ b/samsung-ipc/rfs.c @@ -33,6 +33,73 @@ #include "ipc_private.h" +static inline char *nv_data_path(struct ipc_client *client) { + if (!client) { + ipc_client_log(client, "%s: client is NULL\n", __func__); + goto fail; + } + + if (client->fs_ops && client->fs_ops->nv_data_path) + return client->fs_ops->nv_data_path; + +fail: + return "/efs/nv_data.bin"; +} + +static inline char *nv_data_md5_path(struct ipc_client *client) { + if (!client) { + ipc_client_log(client, "%s: client is NULL\n", __func__); + goto fail; + } + + if (client->fs_ops && client->fs_ops->nv_data_md5_path) + return client->fs_ops->nv_data_md5_path; + +fail: + return "/efs/nv_data.bin.md5"; +} + +static inline char *nv_state_path(struct ipc_client *client) { + if (!client) { + ipc_client_log(client, "%s: client is NULL\n", __func__); + goto fail; + } + + if (client->fs_ops && client->fs_ops->nv_state_path) + return client->fs_ops->nv_state_path; + +fail: + return "/efs/.nv_state"; +} + +static inline char *nv_data_bak_path(struct ipc_client *client) { + if (!client) { + ipc_client_log(client, "%s: client is NULL\n", __func__); + goto fail; + } + + if (client->fs_ops && client->fs_ops->nv_data_bak_path) { + return client->fs_ops->nv_data_bak_path; + } + +fail: + return "/efs/.nv_data.bak"; +} + +static inline char *nv_data_md5_bak_path(struct ipc_client *client) { + if (!client) { + ipc_client_log(client, "%s: client is NULL\n", __func__); + goto fail; + } + + if (client->fs_ops && client->fs_ops->nv_data_md5_bak_path) { + return client->fs_ops->nv_data_md5_bak_path; + } + +fail: + return "/efs/.nv_data.bak.md5"; +} + void md5hash2string(char *out, uint8_t *in) { int i; @@ -78,7 +145,8 @@ void nv_data_md5_generate(struct ipc_client *client) ipc_client_log(client, "nv_data_md5_generate: enter\n"); ipc_client_log(client, "nv_data_md5_generate: generating MD5 hash\n"); - nv_data_p=ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, NV_DATA_SIZE / 10); + nv_data_p=ipc_file_read(client, nv_data_path(client), + NV_DATA_SIZE, NV_DATA_SIZE / 10); nv_data_md5_compute(nv_data_p, NV_DATA_SIZE, nv_data_md5_hash); free(nv_data_p); @@ -92,7 +160,7 @@ void nv_data_md5_generate(struct ipc_client *client) ipc_client_log(client, "nv_data_md5_generate: writing MD5 hash\n"); /* Write the MD5 hash in nv_data.bin.md5. */ - fd = open("/efs/nv_data.bin.md5", O_RDWR | O_CREAT | O_TRUNC, 0644); + fd = open(nv_data_md5_path(client), O_RDWR | O_CREAT | O_TRUNC, 0644); if (fd < 0) { @@ -127,7 +195,7 @@ void nv_data_backup_create(struct ipc_client *client) ipc_client_log(client, "nv_data_backup_create: enter\n"); - if (stat("/efs/nv_data.bin", &nv_stat) < 0) + if (stat(nv_data_path(client), &nv_stat) < 0) { ipc_client_log(client, "nv_data_backup_create: nv_data.bin missing\n"); nv_data_generate(client); @@ -140,7 +208,7 @@ void nv_data_backup_create(struct ipc_client *client) return; } - if (stat("/efs/nv_data.bin.md5", &nv_stat) < 0) + if (stat(nv_data_md5_path(client), &nv_stat) < 0) { ipc_client_log(client, "nv_data_backup_create: nv_data.bin.md5 missing\n"); nv_data_generate(client); @@ -155,14 +223,15 @@ void nv_data_backup_create(struct ipc_client *client) memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); /* Read the content of the backup file. */ - nv_data_p=ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, NV_DATA_SIZE / 10); + nv_data_p=ipc_file_read(client, nv_data_path(client), + NV_DATA_SIZE, NV_DATA_SIZE / 10); /* Compute the backup file MD5 hash. */ nv_data_md5_compute(nv_data_p, NV_DATA_SIZE, nv_data_md5_hash); md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); /* Read the stored backup file MD5 hash. */ - fd=open("/efs/nv_data.bin.md5", O_RDONLY); + fd=open(nv_data_md5_path(client), O_RDONLY); read(fd, nv_data_md5_hash_read, MD5_STRING_SIZE); close(fd); @@ -177,7 +246,7 @@ void nv_data_backup_create(struct ipc_client *client) ipc_client_log(client, "nv_data_backup_create: MD5 hash mismatch on backup file\n"); ipc_client_log(client, "nv_data_backup_create: Consider the computed one as correct\n"); - fd=open("/efs/nv_data.bin.md5", O_WRONLY); + fd=open(nv_data_md5_path(client), O_WRONLY); read(fd, nv_data_md5_hash_string, MD5_STRING_SIZE); close(fd); @@ -197,7 +266,7 @@ nv_data_backup_create_write: { ipc_client_log(client, "nv_data_backup_create: .nv_data.bak write try #%d\n", nv_data_write_tries + 1); - fd=open("/efs/.nv_data.bak", O_RDWR | O_CREAT | O_TRUNC, 0644); + fd=open(nv_data_bak_path(client), O_RDWR | O_CREAT | O_TRUNC, 0644); if (fd < 0) { ipc_client_log(client, "nv_data_backup_create: negative fd while opening /efs/.nv_data.bak, error: %s\n", strerror(errno)); @@ -221,12 +290,12 @@ nv_data_backup_create_write: if (nv_data_write_tries == 5) { ipc_client_log(client, "nv_data_backup_create: writing nv_data.bin to .nv_data.bak failed too many times\n"); - unlink("/efs/.nv_data.bak"); + unlink(nv_data_bak_path(client)); goto exit; } /* Read the newly-written .nv_data.bak. */ - nv_data_bak_p=ipc_file_read(client, "/efs/.nv_data.bak", NV_DATA_SIZE, NV_DATA_SIZE / 10); + nv_data_bak_p=ipc_file_read(client, nv_data_bak_path(client), NV_DATA_SIZE, NV_DATA_SIZE / 10); /* Compute the MD5 hash for nv_data.bin. */ nv_data_md5_compute(nv_data_bak_p, NV_DATA_SIZE, nv_data_md5_hash); @@ -247,12 +316,12 @@ nv_data_backup_create_write: } /* Write the MD5 hash in .nv_data.bak.md5. */ - fd=open("/efs/.nv_data.bak.md5", O_WRONLY | O_CREAT | O_TRUNC, 0644); + fd=open(nv_data_md5_bak_path(client), O_WRONLY | O_CREAT | O_TRUNC, 0644); write(fd, nv_data_md5_hash_read, MD5_STRING_SIZE); close(fd); /* Write the correct .nv_state. */ - fd=open("/efs/.nv_state", O_WRONLY | O_CREAT | O_TRUNC, 0644); + fd=open(nv_state_path(client), O_WRONLY | O_CREAT | O_TRUNC, 0644); data='1'; write(fd, &data, sizeof(data)); close(fd); @@ -283,7 +352,7 @@ void nv_data_backup_restore(struct ipc_client *client) ipc_client_log(client, "nv_data_backup_restore: enter\n"); - if (stat("/efs/.nv_data.bak", &nv_stat) < 0) + if (stat(nv_data_bak_path(client), &nv_stat) < 0) { ipc_client_log(client, "nv_data_backup_restore: .nv_data.bak missing\n"); nv_data_generate(client); @@ -299,7 +368,7 @@ void nv_data_backup_restore(struct ipc_client *client) return; } - if (stat("/efs/.nv_data.bak.md5", &nv_stat) < 0) + if (stat(nv_data_md5_bak_path(client), &nv_stat) < 0) { ipc_client_log(client, "nv_data_backup_restore: .nv_data.bak.md5 missing\n"); nv_data_generate(client); @@ -315,14 +384,14 @@ void nv_data_backup_restore(struct ipc_client *client) memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); /* Read the content of the backup file. */ - nv_data_bak_p=ipc_file_read(client, "/efs/.nv_data.bak", NV_DATA_SIZE, NV_DATA_SIZE / 10); + nv_data_bak_p=ipc_file_read(client, nv_data_bak_path(client), NV_DATA_SIZE, NV_DATA_SIZE / 10); /* Compute the backup file MD5 hash. */ nv_data_md5_compute(nv_data_bak_p, NV_DATA_SIZE, nv_data_md5_hash); md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash); /* Read the stored backup file MD5 hash. */ - fd=open("/efs/.nv_data.bak.md5", O_RDONLY); + fd=open(nv_data_md5_bak_path(client), O_RDONLY); read(fd, nv_data_md5_hash_read, MD5_STRING_SIZE); close(fd); @@ -337,7 +406,7 @@ void nv_data_backup_restore(struct ipc_client *client) ipc_client_log(client, "nv_data_backup_restore: MD5 hash mismatch on backup file\n"); ipc_client_log(client, "nv_data_backup_restore: Consider the computed one as correct\n"); - fd=open("/efs/.nv_data.bak.md5", O_WRONLY); + fd=open(nv_data_md5_bak_path(client), O_WRONLY); read(fd, nv_data_md5_hash_string, MD5_STRING_SIZE); close(fd); @@ -357,7 +426,7 @@ nv_data_backup_restore_write: { ipc_client_log(client, "nv_data_backup_restore: nv_data.bin write try #%d\n", nv_data_write_tries + 1); - fd=open("/efs/nv_data.bin", O_RDWR | O_CREAT | O_TRUNC, 0644); + fd=open(nv_data_path(client), O_RDWR | O_CREAT | O_TRUNC, 0644); if (fd < 0) { ipc_client_log(client, "nv_data_backup_restore: negative fd while opening /efs/nv_data.bin, error: %s\n", strerror(errno)); @@ -381,13 +450,13 @@ nv_data_backup_restore_write: if (nv_data_write_tries == 5) { ipc_client_log(client, "nv_data_backup_restore: writing the backup to nv_data.bin failed too many times\n"); - unlink("/efs/nv_data.bin"); + unlink(nv_data_path(client)); goto exit; } /* Read the newly-written nv_data.bin. */ - nv_data_p=ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, NV_DATA_SIZE / 10); + nv_data_p=ipc_file_read(client, nv_data_path(client), NV_DATA_SIZE, NV_DATA_SIZE / 10); /* Compute the MD5 hash for nv_data.bin. */ nv_data_md5_compute(nv_data_p, NV_DATA_SIZE, nv_data_md5_hash); @@ -408,12 +477,12 @@ nv_data_backup_restore_write: } /* Write the MD5 hash in nv_data.bin.md5. */ - fd=open("/efs/nv_data.bin.md5", O_WRONLY | O_CREAT | O_TRUNC, 0644); + fd=open(nv_data_md5_path(client), O_WRONLY | O_CREAT | O_TRUNC, 0644); write(fd, nv_data_md5_hash_read, MD5_STRING_SIZE); close(fd); /* Write the correct .nv_state. */ - fd=open("/efs/.nv_state", O_WRONLY | O_CREAT | O_TRUNC, 0644); + fd=open(nv_state_path(client), O_WRONLY | O_CREAT | O_TRUNC, 0644); data='1'; write(fd, &data, sizeof(data)); close(fd); @@ -434,11 +503,11 @@ void nv_data_check(struct ipc_client *client) ipc_client_log(client, "nv_data_check: enter\n"); - if (stat("/efs/nv_data.bin", &nv_stat) < 0) + if (stat(nv_data_path(client), &nv_stat) < 0) { ipc_client_log(client, "nv_data_check: nv_data.bin missing\n"); nv_data_backup_restore(client); - stat("/efs/nv_data.bin", &nv_stat); + stat(nv_data_path(client), &nv_stat); } if (nv_stat.st_size != NV_DATA_SIZE) @@ -447,19 +516,19 @@ void nv_data_check(struct ipc_client *client) nv_data_backup_restore(client); } - if (stat("/efs/nv_data.bin.md5", &nv_stat) < 0) + if (stat(nv_data_md5_path(client), &nv_stat) < 0) { ipc_client_log(client, "nv_data_check: nv_data.bin.md5 missing\n"); nv_data_backup_restore(client); } - if (stat("/efs/.nv_data.bak", &nv_stat) < 0 || stat("/efs/.nv_data.bak.md5", &nv_stat) < 0) + if (stat(nv_data_bak_path(client), &nv_stat) < 0 || stat(nv_data_md5_bak_path(client), &nv_stat) < 0) { ipc_client_log(client, "nv_data_check: .nv_data.bak or .nv_data.bak.md5 missing\n"); nv_data_backup_create(client); } - nv_state_fd=open("/efs/.nv_state", O_RDONLY); + nv_state_fd=open(nv_state_path(client), O_RDONLY); if (nv_state_fd < 0 || fstat(nv_state_fd, &nv_stat) < 0) { @@ -500,7 +569,7 @@ void nv_data_md5_check(struct ipc_client *client) memset(nv_data_md5_hash_read, 0, MD5_STRING_SIZE); memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE); - nv_data_p=ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, 1024); + nv_data_p=ipc_file_read(client, nv_data_path(client), NV_DATA_SIZE, 1024); data_p=nv_data_p; nv_data_md5_compute(data_p, NV_DATA_SIZE, nv_data_md5_hash); @@ -509,7 +578,7 @@ void nv_data_md5_check(struct ipc_client *client) free(nv_data_p); - fd=open("/efs/nv_data.bin.md5", O_RDONLY); + fd=open(nv_data_md5_path(client), O_RDONLY); /* Read the md5 stored in the file. */ read(fd, nv_data_md5_hash_read, MD5_STRING_SIZE); @@ -551,7 +620,7 @@ int nv_data_read(struct ipc_client *client, int offset, int length, char *buf) nv_data_check(client); - fd = open("/efs/nv_data.bin", O_RDONLY); + fd = open(nv_data_path(client), O_RDONLY); if (fd < 0) { ipc_client_log(client, "nv_data_read: nv_data file fd is negative\n"); @@ -591,7 +660,7 @@ int nv_data_write(struct ipc_client *client, int offset, int length, char *buf) nv_data_check(client); - fd = open("/efs/nv_data.bin", O_WRONLY); + fd = open(nv_data_path(client), O_WRONLY); if (fd < 0) { ipc_client_log(client, "nv_data_write: nv_data file fd is negative\n"); |