| /* |
| * Copyright (c) 2018 MediaTek Inc. |
| * |
| * Permission is hereby granted, free of charge, to any person obtaining |
| * a copy of this software and associated documentation files |
| * (the "Software"), to deal in the Software without restriction, |
| * including without limitation the rights to use, copy, modify, merge, |
| * publish, distribute, sublicense, and/or sell copies of the Software, |
| * and to permit persons to whom the Software is furnished to do so, |
| * subject to the following conditions: |
| * |
| * The above copyright notice and this permission notice shall be |
| * included in all copies or substantial portions of the Software. |
| * |
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| */ |
| |
| #include <lib/bio.h> |
| #include <malloc.h> |
| #include <platform/mtk_mrdump.h> |
| #include <stddef.h> |
| #include <stdint.h> |
| #include "aee.h" |
| #include "kdump.h" |
| #include "kdump_sdhc.h" |
| |
| static char *part_device_init(struct mrdump_dev *dev, const char *part_name) |
| { |
| dev->bdev = bio_open_by_label(part_name); |
| |
| if (!dev->bdev) |
| return NULL; |
| |
| voprintf_info("%s size: %lu Mb\n", part_name, (dev->bdev->total_size) / 0x100000UL); |
| |
| return (char *) part_name; |
| } |
| |
| static bool part_device_read(struct mrdump_dev *dev, uint64_t offset, uint8_t *buf, int32_t len) |
| { |
| if (dev == NULL) { |
| voprintf_error("%s dev is NULL!\n", __func__); |
| return false; |
| } else { |
| return bio_read(dev->bdev, buf, offset, len) == len; |
| } |
| } |
| |
| static bool part_device_write(struct mrdump_dev *dev, uint64_t offset, uint8_t *buf, int32_t len) |
| { |
| if (dev == NULL) { |
| voprintf_error("%s dev is NULL!\n", __func__); |
| return false; |
| } else { |
| return bio_write(dev->bdev, buf, offset, len) == len; |
| } |
| } |
| |
| struct mrdump_dev *mrdump_dev_emmc_vfat(void) |
| { |
| char *fatpart; |
| struct mrdump_dev *dev = malloc(sizeof(struct mrdump_dev)); |
| if (!dev) { |
| voprintf_error("%s: malloc() failed!\n", __func__); |
| return NULL; |
| } |
| |
| fatpart = part_device_init(0, "intsd"); |
| if (fatpart == NULL) { |
| voprintf_error("No VFAT partition found!\n"); |
| free(dev); |
| return NULL; |
| } |
| dev->name = "emmc"; |
| dev->handle = fatpart; |
| dev->read = part_device_read; |
| dev->write = part_device_write; |
| return dev; |
| } |
| |
| static char *mrdump_get_ext4_partition(struct mrdump_dev *dev) |
| { |
| char *ext4part; |
| |
| ext4part = part_device_init(dev, MRDUMP_OUTPUT_PARTITION); |
| if (ext4part != NULL) |
| return ext4part; |
| |
| return NULL; |
| } |
| |
| struct mrdump_dev *mrdump_dev_emmc_ext4(void) |
| { |
| char *ext4part; |
| struct mrdump_dev *dev = malloc(sizeof(struct mrdump_dev)); |
| if (!dev) { |
| voprintf_error("%s: malloc() failed!\n", __func__); |
| return NULL; |
| } |
| |
| ext4part = mrdump_get_ext4_partition(dev); |
| if (ext4part == NULL) { |
| voprintf_error("No EXT4 partition found!\n"); |
| free(dev); |
| return NULL; |
| } |
| dev->name = "emmc"; |
| dev->handle = ext4part; |
| dev->read = part_device_read; |
| dev->write = part_device_write; |
| return dev; |
| } |
| |
| |
| #if 0 |
| static bool mrdump_dev_sdcard_read(struct mrdump_dev *dev, uint32_t sector_addr, uint8_t *pdBuf, int32_t blockLen) |
| { |
| return mmc_wrap_bread(1, sector_addr, blockLen, pdBuf) == 1; |
| } |
| |
| static bool mrdump_dev_sdcard_write(struct mrdump_dev *dev, uint32_t sector_addr, uint8_t *pdBuf, int32_t blockLen) |
| { |
| return mmc_wrap_bwrite(1, sector_addr, blockLen, pdBuf) == 1; |
| } |
| |
| struct mrdump_dev *mrdump_dev_sdcard(void) |
| { |
| struct mrdump_dev *dev = malloc(sizeof(struct mrdump_dev)); |
| dev->name = "sdcard"; |
| dev->handle = NULL; |
| dev->read = mrdump_dev_sdcard_read; |
| dev->write = mrdump_dev_sdcard_write; |
| |
| mmc_legacy_init(2); |
| return dev; |
| } |
| #endif |