1 /*
2  * Copyright (C) 2021 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 
17 #ifndef LIBXBC_H_
18 #define LIBXBC_H_
19 
20 // memcpy and strncmp
21 #include <common.h>
22 
23 /*
24  * Add a string of boot config parameters to memory appended by the trailer.
25  * This memory needs to be immediately following the end of the ramdisks.
26  * The new boot config trailer will be written to the end of the entire
27  * parameter section(previous + new). The trailer contains a 4 byte size of the
28  * parameters, followed by a 4 byte checksum of the parameters, followed by a 12
29  * byte magic string.
30  *
31  * @param params pointer to string of boot config parameters
32  * @param params_size size of params string in bytes
33  * @param bootconfig_start_addr address that the boot config section is starting
34  *        at in memory.
35  * @param bootconfig_size size of the current bootconfig section in bytes.
36  * @return number of bytes added to the boot config section. -1 for error.
37  */
38 int addBootConfigParameters(char *params, uint32_t params_size,
39                             uint64_t bootconfig_start_addr,
40                             uint32_t bootconfig_size);
41 
42 /*
43  * Add the boot config trailer to the end of the boot config parameter section.
44  * This can be used after the vendor bootconfig section has been placed into
45  * memory if there are no additional parameters that need to be added.
46  * The new boot config trailer will be written to the end of the entire
47  * parameter section at (bootconfig_start_addr + bootconfig_size).
48  * The trailer contains a 4 byte size of the parameters, followed by a 4 byte
49  * checksum of the parameters, followed by a 12 byte magic string.
50  *
51  * @param bootconfig_start_addr address that the boot config section is starting
52  *        at in memory.
53  * @param bootconfig_size size of the current bootconfig section in bytes.
54  * @return number of bytes added to the boot config section. -1 for error.
55  */
56 int addBootConfigTrailer(uint64_t bootconfig_start_addr,
57                          uint32_t bootconfig_size);
58 
59 #endif /* LIBXBC_H_ */
60