2 * purgatory: Runs between two kernels
4 * Copyright (C) 2014 Red Hat Inc.
7 * Vivek Goyal <vgoyal@redhat.com>
9 * This source code is licensed under the GNU General Public License,
10 * Version 2. See the file COPYING for more details.
13 #include <linux/bug.h>
14 #include <linux/sha256.h>
15 #include <asm/purgatory.h>
17 #include "../boot/string.h"
19 unsigned long purgatory_backup_dest
__section(.kexec
-purgatory
);
20 unsigned long purgatory_backup_src
__section(.kexec
-purgatory
);
21 unsigned long purgatory_backup_sz
__section(.kexec
-purgatory
);
23 u8 purgatory_sha256_digest
[SHA256_DIGEST_SIZE
] __section(.kexec
-purgatory
);
25 struct kexec_sha_region purgatory_sha_regions
[KEXEC_SEGMENT_MAX
] __section(.kexec
-purgatory
);
28 * On x86, second kernel requries first 640K of memory to boot. Copy
29 * first 640K to a backup region in reserved memory range so that second
30 * kernel can use first 640K.
32 static int copy_backup_region(void)
34 if (purgatory_backup_dest
) {
35 memcpy((void *)purgatory_backup_dest
,
36 (void *)purgatory_backup_src
, purgatory_backup_sz
);
41 static int verify_sha256_digest(void)
43 struct kexec_sha_region
*ptr
, *end
;
44 u8 digest
[SHA256_DIGEST_SIZE
];
45 struct sha256_state sctx
;
48 end
= purgatory_sha_regions
+ ARRAY_SIZE(purgatory_sha_regions
);
50 for (ptr
= purgatory_sha_regions
; ptr
< end
; ptr
++)
51 sha256_update(&sctx
, (uint8_t *)(ptr
->start
), ptr
->len
);
53 sha256_final(&sctx
, digest
);
55 if (memcmp(digest
, purgatory_sha256_digest
, sizeof(digest
)))
65 ret
= verify_sha256_digest();