blob: 6149eb0c9cd3ec8bd6666c03d556d9ab6da9fa7b [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001/*
2 * Copyright (c) 2018 MediaTek Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24#include <lib/bio.h>
25#include <malloc.h>
26#include <platform/mtk_mrdump.h>
27#include <stddef.h>
28#include <stdint.h>
29#include "aee.h"
30#include "kdump.h"
31#include "kdump_sdhc.h"
32
33static char *part_device_init(struct mrdump_dev *dev, const char *part_name)
34{
35 dev->bdev = bio_open_by_label(part_name);
36
37 if (!dev->bdev)
38 return NULL;
39
40 voprintf_info("%s size: %lu Mb\n", part_name, (dev->bdev->total_size) / 0x100000UL);
41
42 return (char *) part_name;
43}
44
45static bool part_device_read(struct mrdump_dev *dev, uint64_t offset, uint8_t *buf, int32_t len)
46{
47 if (dev == NULL) {
48 voprintf_error("%s dev is NULL!\n", __func__);
49 return false;
50 } else {
51 return bio_read(dev->bdev, buf, offset, len) == len;
52 }
53}
54
55static bool part_device_write(struct mrdump_dev *dev, uint64_t offset, uint8_t *buf, int32_t len)
56{
57 if (dev == NULL) {
58 voprintf_error("%s dev is NULL!\n", __func__);
59 return false;
60 } else {
61 return bio_write(dev->bdev, buf, offset, len) == len;
62 }
63}
64
65struct mrdump_dev *mrdump_dev_emmc_vfat(void)
66{
67 char *fatpart;
68 struct mrdump_dev *dev = malloc(sizeof(struct mrdump_dev));
69 if (!dev) {
70 voprintf_error("%s: malloc() failed!\n", __func__);
71 return NULL;
72 }
73
74 fatpart = part_device_init(0, "intsd");
75 if (fatpart == NULL) {
76 voprintf_error("No VFAT partition found!\n");
77 free(dev);
78 return NULL;
79 }
80 dev->name = "emmc";
81 dev->handle = fatpart;
82 dev->read = part_device_read;
83 dev->write = part_device_write;
84 return dev;
85}
86
87static char *mrdump_get_ext4_partition(struct mrdump_dev *dev)
88{
89 char *ext4part;
90
91 ext4part = part_device_init(dev, MRDUMP_OUTPUT_PARTITION);
92 if (ext4part != NULL)
93 return ext4part;
94
95 return NULL;
96}
97
98struct mrdump_dev *mrdump_dev_emmc_ext4(void)
99{
100 char *ext4part;
101 struct mrdump_dev *dev = malloc(sizeof(struct mrdump_dev));
102 if (!dev) {
103 voprintf_error("%s: malloc() failed!\n", __func__);
104 return NULL;
105 }
106
107 ext4part = mrdump_get_ext4_partition(dev);
108 if (ext4part == NULL) {
109 voprintf_error("No EXT4 partition found!\n");
110 free(dev);
111 return NULL;
112 }
113 dev->name = "emmc";
114 dev->handle = ext4part;
115 dev->read = part_device_read;
116 dev->write = part_device_write;
117 return dev;
118}
119
120
121#if 0
122static bool mrdump_dev_sdcard_read(struct mrdump_dev *dev, uint32_t sector_addr, uint8_t *pdBuf, int32_t blockLen)
123{
124 return mmc_wrap_bread(1, sector_addr, blockLen, pdBuf) == 1;
125}
126
127static bool mrdump_dev_sdcard_write(struct mrdump_dev *dev, uint32_t sector_addr, uint8_t *pdBuf, int32_t blockLen)
128{
129 return mmc_wrap_bwrite(1, sector_addr, blockLen, pdBuf) == 1;
130}
131
132struct mrdump_dev *mrdump_dev_sdcard(void)
133{
134 struct mrdump_dev *dev = malloc(sizeof(struct mrdump_dev));
135 dev->name = "sdcard";
136 dev->handle = NULL;
137 dev->read = mrdump_dev_sdcard_read;
138 dev->write = mrdump_dev_sdcard_write;
139
140 mmc_legacy_init(2);
141 return dev;
142}
143#endif