summaryrefslogtreecommitdiffstats
path: root/kexec/arch/ppc64/fdt.c
blob: 8bc6d2d221b777d83b3b69c99607ab3d5a9e43b2 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
 * ppc64 fdt fixups
 *
 * Copyright 2015 Freescale Semiconductor, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation (version 2 of the License).
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <arch/fdt.h>
#include <libfdt.h>
#include <stdio.h>
#include <stdlib.h>

/*
 * Let the kernel know it booted from kexec, as some things (e.g.
 * secondary CPU release) may work differently.
 */
static int fixup_kexec_prop(void *fdt)
{
	int err, nodeoffset;

	nodeoffset = fdt_subnode_offset(fdt, 0, "chosen");
	if (nodeoffset < 0)
		nodeoffset = fdt_add_subnode(fdt, 0, "chosen");
	if (nodeoffset < 0) {
		printf("%s: add /chosen %s\n", __func__,
		       fdt_strerror(nodeoffset));
		return -1;
	}

	err = fdt_setprop(fdt, nodeoffset, "linux,booted-from-kexec",
			  NULL, 0);
	if (err < 0) {
		printf("%s: couldn't write linux,booted-from-kexec: %s\n",
		       __func__, fdt_strerror(err));
		return -1;
	}

	return 0;
}


/*
 * For now, assume that the added content fits in the file.
 * This should be the case when flattening from /proc/device-tree,
 * and when passing in a dtb, dtc can be told to add padding.
 */
int fixup_dt(char **fdt, off_t *size)
{
	int ret;

	*size += 4096;
	*fdt = realloc(*fdt, *size);
	if (!*fdt) {
		fprintf(stderr, "%s: out of memory\n", __func__);
		return -1;
	}

	ret = fdt_open_into(*fdt, *fdt, *size);
	if (ret < 0) {
		fprintf(stderr, "%s: fdt_open_into: %s\n", __func__,
			fdt_strerror(ret));
		return -1;
	}

	ret = fixup_kexec_prop(*fdt);
	if (ret < 0)
		return ret;

	return 0;
}