ipanic_emmc.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include <sd_misc.h>
  2. #include <linux/slab.h>
  3. #include <linux/kernel.h>
  4. #include <linux/module.h>
  5. #include "ipanic.h"
  6. #define EMMC_BLOCK_SIZE 0x200
  7. #define EMMC_EXPDB_PART_SIZE 0xa00000
  8. #define IPANIC_MAX_OFFSET 0
  9. __weak int card_dump_func_read(unsigned char *buf, unsigned int len, unsigned long long offset,
  10. int dev)
  11. {
  12. return 0;
  13. }
  14. __weak int card_dump_func_write(unsigned char *buf, unsigned int len, unsigned long long offset,
  15. int dev)
  16. {
  17. return 0;
  18. }
  19. __weak unsigned int reset_boot_up_device(int type) /* force to re-initialize the emmc host controller */
  20. {
  21. return 0;
  22. }
  23. char *ipanic_read_size(int off, int len)
  24. {
  25. int size;
  26. char *buff = NULL;
  27. if (len == 0)
  28. return NULL;
  29. size = ALIGN(len, EMMC_BLOCK_SIZE);
  30. buff = kzalloc(size, GFP_KERNEL);
  31. if (buff == NULL) {
  32. LOGE("%s: cannot allocate buffer(len:%d)\n", __func__, len);
  33. return NULL;
  34. }
  35. if (card_dump_func_read(buff, size, off, DUMP_INTO_BOOT_CARD_IPANIC) != 0) {
  36. LOGE("%s: read failed(offset:%d,size:%d)\n", __func__, off, size);
  37. kfree(buff);
  38. return NULL;
  39. }
  40. return buff;
  41. }
  42. EXPORT_SYMBOL(ipanic_read_size);
  43. int ipanic_write_size(void *buf, int off, int len)
  44. {
  45. if (len & (EMMC_BLOCK_SIZE - 1))
  46. return -2;
  47. if (len > 0) {
  48. if (card_dump_func_write
  49. ((unsigned char *)buf, len, off, DUMP_INTO_BOOT_CARD_IPANIC))
  50. return -1;
  51. }
  52. return len;
  53. }
  54. EXPORT_SYMBOL(ipanic_write_size);
  55. static int bufsize;
  56. static u64 buf;
  57. void ipanic_msdc_init(void)
  58. {
  59. bufsize = ALIGN(PAGE_SIZE, EMMC_BLOCK_SIZE);
  60. buf = (u64) (unsigned long)kmalloc(bufsize, GFP_KERNEL);
  61. }
  62. EXPORT_SYMBOL(ipanic_msdc_init);
  63. int ipanic_msdc_info(struct ipanic_header *iheader)
  64. {
  65. iheader->blksize = EMMC_BLOCK_SIZE;
  66. iheader->partsize = EMMC_EXPDB_PART_SIZE;
  67. iheader->buf = buf;
  68. iheader->bufsize = bufsize;
  69. if (iheader->buf == 0) {
  70. LOGE("kmalloc fail[%x]\n", iheader->bufsize);
  71. iheader = NULL;
  72. return -1;
  73. }
  74. if (oops_in_progress)
  75. reset_boot_up_device(0);
  76. return 0;
  77. }
  78. EXPORT_SYMBOL(ipanic_msdc_info);
  79. void ipanic_erase(void)
  80. {
  81. char *zero = kzalloc(PAGE_SIZE, GFP_KERNEL);
  82. ipanic_write_size(zero, 0, PAGE_SIZE);
  83. kfree(zero);
  84. }
  85. EXPORT_SYMBOL(ipanic_erase);