blob: ddaa999af5bce040abf1399c444e5ad883c6a14e [file] [log] [blame]
Steven Moreland1dba6a82024-02-16 22:32:43 +00001/*
2 * Copyright (C) 2024 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 <bootloader_message/bootloader_message.h>
17#include <log/log.h>
18
19#include <string>
20
21#include <cstdio>
22
23static void log(const char* fmt, ...) __attribute__((format(printf, 1, 2)));
24static void log(const char* fmt, ...) {
25 va_list va;
26 va_start(va, fmt);
27
28 va_list vb;
29 va_copy(vb, va);
30
31 __android_log_vprint(ANDROID_LOG_ERROR, "misctrl", fmt, va);
32 va_end(va);
33
34 vfprintf(stderr, fmt, vb);
35 fprintf(stderr, "\n");
36 va_end(vb);
37}
38
39static int check_reserved_space() {
40 bool empty;
41 std::string err;
42 bool success = CheckReservedSystemSpaceEmpty(&empty, &err);
43 if (!success) {
44 log("Could not read reserved space: %s", err.c_str());
45 return 1;
46 }
47 log("System reserved space empty? %d.", empty);
48
49 if (!err.empty()) {
50 constexpr size_t kPrintChunkSize = 256;
51 for (size_t i = 0; i < err.size(); i += kPrintChunkSize) {
52 log("DATA: %s", err.substr(i, kPrintChunkSize).c_str());
53 }
54 }
55
56 return empty ? 0 : 1;
57}
58
59int main() {
60 return check_reserved_space();
61}