1 /*
2 * Copyright 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include <inttypes.h>
17 #include <stdio.h>
18 #include <string>
19 #include <android-base/file.h>
20 #include <android-base/stringprintf.h>
21
22 struct abl_log_header {
23 uint64_t i;
24 uint64_t size;
25 char buf[];
26 } __attribute__((packed));
27
28 // Gzip binary data and dump in base64 format. Cmd to decode is also attached.
dumpGzippedFileInBase64(const char * title,const char * file_path)29 void dumpGzippedFileInBase64(const char* title, const char* file_path) {
30 auto cmd = android::base::StringPrintf("gzip < %s | base64", file_path);
31 printf("------ %s, %s\n", title, cmd.c_str());
32 printf("base64 -d <<EOF | gunzip\n");
33 system(cmd.c_str());
34 printf("EOF\n");
35 return;
36 }
37
38 // Dump items related to ramdump.
main()39 int main() {
40 setbuf(stdout, NULL);
41 std::string abl_log;
42 if (android::base::ReadFileToString("/mnt/vendor/ramdump/abl.log", &abl_log)) {
43 const struct abl_log_header *header = (const struct abl_log_header*) abl_log.c_str();
44 printf("------ Ramdump misc file: abl.log (i:0x%" PRIx64 " size:0x%" PRIx64 ") ------\n%s\n",
45 header->i, header->size, std::string(header->buf, header->i).c_str());
46 } else {
47 printf("*** Ramdump misc file: abl.log: File not found\n");
48 }
49
50 dumpGzippedFileInBase64("Ramdump misc file: acpm.lst (gzipped in base64)", "/mnt/vendor/ramdump/acpm.lst");
51 dumpGzippedFileInBase64("Ramdump misc file: s2d.lst (gzipped in base64)", "/mnt/vendor/ramdump/s2d.lst");
52 return 0;
53 }
54