xref: /aosp_15_r20/system/libufdt/include/ufdt_overlay.h (revision 13e8728f0cffde9369df671f7b293a048a99c7ed)
1 /*
2  * Copyright (C) 2016-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 
17 #ifndef UFDT_OVERLAY_H
18 #define UFDT_OVERLAY_H
19 
20 #include <libfdt.h>
21 
22 /* Given a buffer in RAM containing the contents of a .dtb file,
23  * it initializes an FDT in-place and returns a pointer to the
24  * given buffer, or NULL in case of error.
25  * In case of error, it may printf() diagnostic messages.
26  */
27 struct fdt_header *ufdt_install_blob(void *blob, size_t blob_size);
28 
29 /* Given a main_fdt_header buffer and an overlay_fdtp buffer containing the
30  * contents of a .dtbo file, it creates a new FDT containing the applied
31  * overlay_fdtp in a dto_malloc'd buffer and returns it, or NULL in case of
32  * error.
33  * It is allowed to modify the buffers (both main_fdt_header and overlay_fdtp
34  * buffer) passed in.
35  * It does not dto_free main_fdt_header and overlay_fdtp buffer passed in.
36  */
37 struct fdt_header *ufdt_apply_overlay(struct fdt_header *main_fdt_header,
38                                       size_t main_fdt_size,
39                                       void *overlay_fdtp,
40                                       size_t overlay_size);
41 
42 /*
43  * Apply device tree `overlays` to `main_fdt_header` fdt buffer. (API is unstable)
44  *
45  * `main_fdt_header` is getting overrided by result tree, so it must
46  * have enough space (provided by `main_fdt_buffer_size`) to store it.
47  * `main_fdt_header` and all `overlays` must be 8 bytes aligned.
48  *
49  * `dto_malloc` is used for:
50  * - ufdt structures around main fdt and overlays.
51  * - result tree temporary buffer at most `main_fdt_buffer_size` size.
52  *
53  * TODO(b/362830550): expose a more comprehensive error type.
54  * Returns 0 or -1 in case of error.
55  */
56 int ufdt_apply_multioverlay(struct fdt_header *main_fdt_header,
57                             size_t main_fdt_buffer_size, void *const *overlays,
58                             size_t overlays_count);
59 
60 #endif /* UFDT_OVERLAY_H */
61