-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathandroid.c
More file actions
40 lines (31 loc) · 1.31 KB
/
Copy pathandroid.c
File metadata and controls
40 lines (31 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2017 lambdadroid
#include "android.h"
#include <efilib.h>
EFI_STATUS android_open_image(struct android_image *image) {
EFI_STATUS err = image_read(&image->image, 0, &image->header, sizeof(image->header));
if (err) {
return err;
}
if (CompareMem(image->header.magic, ANDROID_BOOT_MAGIC, ANDROID_BOOT_MAGIC_SIZE)) {
Print(L"Partition does not appear to be an Android boot partition\n");
return EFI_VOLUME_CORRUPTED;
}
return EFI_SUCCESS;
}
EFI_STATUS android_copy_cmdline(const struct android_image *image, CHAR8* cmdline, UINTN max_length) {
if (max_length <= ANDROID_BOOT_ARGS_SIZE + ANDROID_BOOT_EXTRA_ARGS_SIZE) {
return EFI_BUFFER_TOO_SMALL;
}
// Note: Command line is *not* null-terminated
CopyMem(cmdline, image->header.cmdline, ANDROID_BOOT_ARGS_SIZE);
if (cmdline[ANDROID_BOOT_ARGS_SIZE - 1]) {
// Copy extra command line as well
CopyMem(&cmdline[ANDROID_BOOT_ARGS_SIZE], image->header.extra_cmdline, ANDROID_BOOT_EXTRA_ARGS_SIZE);
if (image->header.extra_cmdline[ANDROID_BOOT_EXTRA_ARGS_SIZE - 1]) {
// Ensure to add null terminator
cmdline[ANDROID_BOOT_ARGS_SIZE + ANDROID_BOOT_EXTRA_ARGS_SIZE] = 0;
}
}
return EFI_SUCCESS;
}