scripts/dtc/fdtoverlay.c

Source file repositories/reference/linux-study-clean/scripts/dtc/fdtoverlay.c

File Facts

System
Linux kernel
Corpus path
scripts/dtc/fdtoverlay.c
Extension
.c
Size
4576 bytes
Lines
215
Domain
Support Tooling And Documentation
Bucket
scripts
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (ret) {
			fprintf(stderr,
				"\nFailed to make temporary copy: %s\n",
				fdt_strerror(ret));
			goto fail;
		}
		ret = fdt_path_offset(tmp, "/__symbols__");
		has_symbols = ret >= 0;

		memcpy(tmpo, overlay, fdt_totalsize(overlay));

		ret = fdt_overlay_apply(tmp, tmpo);
		if (ret == -FDT_ERR_NOSPACE) {
			*buf_len += BUF_INCREMENT;
		}
	} while (ret == -FDT_ERR_NOSPACE);

	if (ret) {
		fprintf(stderr, "\nFailed to apply '%s': %s\n",
			name, fdt_strerror(ret));
		if (!has_symbols) {
			fprintf(stderr,
				"base blob does not have a '/__symbols__' node, "
				"make sure you have compiled the base blob with '-@' option\n");
		}
		goto fail;
	}

	free(base);
	free(tmpo);
	return tmp;

fail:
	free(tmpo);
	if (tmp)
		free(tmp);

	return NULL;
}
static int do_fdtoverlay(const char *input_filename,
			 const char *output_filename,
			 int argc, char *argv[])
{
	char *blob = NULL;
	char **ovblob = NULL;
	size_t buf_len;
	int i, ret = -1;

	blob = utilfdt_read(input_filename, &buf_len);
	if (!blob) {
		fprintf(stderr, "\nFailed to read '%s'\n", input_filename);
		goto out_err;
	}
	if (fdt_totalsize(blob) > buf_len) {
		fprintf(stderr,
 "\nBase blob is incomplete (%lu / %" PRIu32 " bytes read)\n",
			(unsigned long)buf_len, fdt_totalsize(blob));
		goto out_err;
	}

	/* allocate blob pointer array */
	ovblob = xmalloc(sizeof(*ovblob) * argc);
	memset(ovblob, 0, sizeof(*ovblob) * argc);

	/* read and keep track of the overlay blobs */
	for (i = 0; i < argc; i++) {
		size_t ov_len;
		ovblob[i] = utilfdt_read(argv[i], &ov_len);
		if (!ovblob[i]) {
			fprintf(stderr, "\nFailed to read '%s'\n", argv[i]);
			goto out_err;
		}
		if (fdt_totalsize(ovblob[i]) > ov_len) {
			fprintf(stderr,
"\nOverlay '%s' is incomplete (%lu / %" PRIu32 " bytes read)\n",
				argv[i], (unsigned long)ov_len,
				fdt_totalsize(ovblob[i]));
			goto out_err;
		}
	}

	buf_len = fdt_totalsize(blob);

	/* apply the overlays in sequence */
	for (i = 0; i < argc; i++) {
		blob = apply_one(blob, ovblob[i], &buf_len, argv[i]);
		if (!blob)
			goto out_err;
	}

Annotation

Implementation Notes