kexec-tools-002-add-arch-arm.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. diff -rduNp kexec-tools-1.101.orig/configure kexec-tools-1.101/configure
  2. --- kexec-tools-1.101.orig/configure 2006-09-20 04:39:38.000000000 +0200
  3. +++ kexec-tools-1.101/configure 2007-01-22 15:54:14.000000000 +0100
  4. @@ -1381,6 +1381,9 @@ case $host_cpu in
  5. i?86 )
  6. host_cpu="i386"
  7. ;;
  8. + arm* )
  9. + host_cpu="arm"
  10. + ;;
  11. powerpc )
  12. host_cpu="ppc"
  13. ;;
  14. @@ -1395,7 +1398,7 @@ case $host_cpu in
  15. ;;
  16. esac
  17. case $host_cpu in
  18. - i386|ppc|x86_64|alpha|ppc64|ia64|s390)
  19. + i386|ppc|x86_64|alpha|ppc64|ia64|s390|arm)
  20. ;;
  21. * )
  22. { { echo "$as_me:$LINENO: error: unsupported architecture $host_cpu" >&5
  23. diff -rduNp kexec-tools-1.101.orig/kexec/arch/arm/Makefile kexec-tools-1.101/kexec/arch/arm/Makefile
  24. --- kexec-tools-1.101.orig/kexec/arch/arm/Makefile 1970-01-01 01:00:00.000000000 +0100
  25. +++ kexec-tools-1.101/kexec/arch/arm/Makefile 2007-01-22 15:54:14.000000000 +0100
  26. @@ -0,0 +1,8 @@
  27. +#
  28. +# kexec arm (linux booting linux)
  29. +#
  30. +KEXEC_C_SRCS+= kexec/arch/arm/kexec-elf-rel-arm.c
  31. +KEXEC_C_SRCS+= kexec/arch/arm/kexec-zImage-arm.c
  32. +KEXEC_C_SRCS+= kexec/arch/arm/kexec-arm.c
  33. +
  34. +KEXEC_S_SRCS+=
  35. diff -rduNp kexec-tools-1.101.orig/kexec/arch/arm/include/arch/options.h kexec-tools-1.101/kexec/arch/arm/include/arch/options.h
  36. --- kexec-tools-1.101.orig/kexec/arch/arm/include/arch/options.h 1970-01-01 01:00:00.000000000 +0100
  37. +++ kexec-tools-1.101/kexec/arch/arm/include/arch/options.h 2007-01-22 15:54:14.000000000 +0100
  38. @@ -0,0 +1,11 @@
  39. +#ifndef KEXEC_ARCH_ARM_OPTIONS_H
  40. +#define KEXEC_ARCH_ARM_OPTIONS_H
  41. +
  42. +#define OPT_ARCH_MAX (OPT_MAX+0)
  43. +
  44. +#define KEXEC_ARCH_OPTIONS \
  45. + KEXEC_OPTIONS \
  46. +
  47. +#define KEXEC_ARCH_OPT_STR KEXEC_OPT_STR ""
  48. +
  49. +#endif /* KEXEC_ARCH_ARM_OPTIONS_H */
  50. diff -rduNp kexec-tools-1.101.orig/kexec/arch/arm/kexec-arm.c kexec-tools-1.101/kexec/arch/arm/kexec-arm.c
  51. --- kexec-tools-1.101.orig/kexec/arch/arm/kexec-arm.c 1970-01-01 01:00:00.000000000 +0100
  52. +++ kexec-tools-1.101/kexec/arch/arm/kexec-arm.c 2007-01-22 15:54:14.000000000 +0100
  53. @@ -0,0 +1,130 @@
  54. +/*
  55. + * kexec: Linux boots Linux
  56. + *
  57. + * modified from kexec-ppc.c
  58. + *
  59. + */
  60. +
  61. +#define _GNU_SOURCE
  62. +#include <stddef.h>
  63. +#include <stdio.h>
  64. +#include <errno.h>
  65. +#include <stdint.h>
  66. +#include <string.h>
  67. +#include <getopt.h>
  68. +#include <sys/utsname.h>
  69. +#include "../../kexec.h"
  70. +#include "../../kexec-syscall.h"
  71. +#include "kexec-arm.h"
  72. +#include <arch/options.h>
  73. +
  74. +#define MAX_MEMORY_RANGES 64
  75. +#define MAX_LINE 160
  76. +static struct memory_range memory_range[MAX_MEMORY_RANGES];
  77. +
  78. +/* Return a sorted list of available memory ranges. */
  79. +int get_memory_ranges(struct memory_range **range, int *ranges, unsigned long kexec_flags)
  80. +{
  81. + const char iomem[]= "/proc/iomem";
  82. + int memory_ranges = 0;
  83. + char line[MAX_LINE];
  84. + FILE *fp;
  85. + fp = fopen(iomem, "r");
  86. + if (!fp) {
  87. + fprintf(stderr, "Cannot open %s: %s\n",
  88. + iomem, strerror(errno));
  89. + return -1;
  90. + }
  91. +
  92. + while(fgets(line, sizeof(line), fp) != 0) {
  93. + unsigned long long start, end;
  94. + char *str;
  95. + int type;
  96. + int consumed;
  97. + int count;
  98. + if (memory_ranges >= MAX_MEMORY_RANGES)
  99. + break;
  100. + count = sscanf(line, "%Lx-%Lx : %n",
  101. + &start, &end, &consumed);
  102. + if (count != 2)
  103. + continue;
  104. + str = line + consumed;
  105. + end = end + 1;
  106. +
  107. + if (memcmp(str, "System RAM\n", 11) == 0) {
  108. + type = RANGE_RAM;
  109. + }
  110. + else if (memcmp(str, "reserved\n", 9) == 0) {
  111. + type = RANGE_RESERVED;
  112. + }
  113. + else {
  114. + continue;
  115. + }
  116. +
  117. + memory_range[memory_ranges].start = start;
  118. + memory_range[memory_ranges].end = end;
  119. + memory_range[memory_ranges].type = type;
  120. + memory_ranges++;
  121. + }
  122. + fclose(fp);
  123. + *range = memory_range;
  124. + *ranges = memory_ranges;
  125. + return 0;
  126. +}
  127. +
  128. +/* Supported file types and callbacks */
  129. +struct file_type file_type[] = {
  130. + {"zImage", zImage_arm_probe, zImage_arm_load, zImage_arm_usage},
  131. +};
  132. +int file_types = sizeof(file_type) / sizeof(file_type[0]);
  133. +
  134. +
  135. +void arch_usage(void)
  136. +{
  137. +}
  138. +
  139. +int arch_process_options(int argc, char **argv)
  140. +{
  141. + static const struct option options[] = {
  142. + KEXEC_ARCH_OPTIONS
  143. + { 0, 0, NULL, 0 },
  144. + };
  145. + static const char short_options[] = KEXEC_ARCH_OPT_STR;
  146. + int opt;
  147. +
  148. + opterr = 0; /* Don't complain about unrecognized options here */
  149. + while((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) {
  150. + switch(opt) {
  151. + default:
  152. + break;
  153. + }
  154. + }
  155. + /* Reset getopt for the next pass; called in other source modules */
  156. + opterr = 1;
  157. + optind = 1;
  158. + return 0;
  159. +}
  160. +
  161. +int arch_compat_trampoline(struct kexec_info *info)
  162. +{
  163. + int result;
  164. + struct utsname utsname;
  165. + result = uname(&utsname);
  166. + if (result < 0) {
  167. + fprintf(stderr, "uname failed: %s\n",
  168. + strerror(errno));
  169. + return -1;
  170. + }
  171. + if (strncmp(utsname.machine, "arm",3) != 0)
  172. + {
  173. + fprintf(stderr, "Unsupported machine type: %s\n",
  174. + utsname.machine);
  175. + return -1;
  176. + }
  177. + return 0;
  178. +}
  179. +
  180. +void arch_update_purgatory(struct kexec_info *info)
  181. +{
  182. +}
  183. +
  184. diff -rduNp kexec-tools-1.101.orig/kexec/arch/arm/kexec-arm.h kexec-tools-1.101/kexec/arch/arm/kexec-arm.h
  185. --- kexec-tools-1.101.orig/kexec/arch/arm/kexec-arm.h 1970-01-01 01:00:00.000000000 +0100
  186. +++ kexec-tools-1.101/kexec/arch/arm/kexec-arm.h 2007-01-22 15:54:14.000000000 +0100
  187. @@ -0,0 +1,9 @@
  188. +#ifndef KEXEC_ARM_H
  189. +#define KEXEC_ARM_H
  190. +
  191. +int zImage_arm_probe(const char *buf, off_t len);
  192. +int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
  193. + struct kexec_info *info);
  194. +void zImage_arm_usage(void);
  195. +
  196. +#endif /* KEXEC_ARM_H */
  197. diff -rduNp kexec-tools-1.101.orig/kexec/arch/arm/kexec-elf-rel-arm.c kexec-tools-1.101/kexec/arch/arm/kexec-elf-rel-arm.c
  198. --- kexec-tools-1.101.orig/kexec/arch/arm/kexec-elf-rel-arm.c 1970-01-01 01:00:00.000000000 +0100
  199. +++ kexec-tools-1.101/kexec/arch/arm/kexec-elf-rel-arm.c 2007-01-22 15:54:14.000000000 +0100
  200. @@ -0,0 +1,35 @@
  201. +#include <stdio.h>
  202. +#include <elf.h>
  203. +#include "../../kexec.h"
  204. +#include "../../kexec-elf.h"
  205. +
  206. +int machine_verify_elf_rel(struct mem_ehdr *ehdr)
  207. +{
  208. + if (ehdr->ei_data != ELFDATA2MSB) {
  209. + return 0;
  210. + }
  211. + if (ehdr->ei_class != ELFCLASS32) {
  212. + return 0;
  213. + }
  214. + if (ehdr->e_machine != EM_ARM)
  215. + {
  216. + return 0;
  217. + }
  218. + return 1;
  219. +}
  220. +
  221. +void machine_apply_elf_rel(struct mem_ehdr *ehdr, unsigned long r_type,
  222. + void *location, unsigned long address, unsigned long value)
  223. +{
  224. + switch(r_type) {
  225. + case R_ARM_ABS32:
  226. + *((uint32_t *)location) += value;
  227. + break;
  228. + case R_ARM_REL32:
  229. + *((uint32_t *)location) += value - address;
  230. + break;
  231. + default:
  232. + die("Unknown rel relocation: %lu\n", r_type);
  233. + break;
  234. + }
  235. +}
  236. diff -rduNp kexec-tools-1.101.orig/kexec/arch/arm/kexec-zImage-arm.c kexec-tools-1.101/kexec/arch/arm/kexec-zImage-arm.c
  237. --- kexec-tools-1.101.orig/kexec/arch/arm/kexec-zImage-arm.c 1970-01-01 01:00:00.000000000 +0100
  238. +++ kexec-tools-1.101/kexec/arch/arm/kexec-zImage-arm.c 2007-01-22 15:54:14.000000000 +0100
  239. @@ -0,0 +1,34 @@
  240. +#define _GNU_SOURCE
  241. +#include <stdio.h>
  242. +#include <string.h>
  243. +#include <stdlib.h>
  244. +#include <errno.h>
  245. +#include <limits.h>
  246. +#include "../../kexec.h"
  247. +
  248. +int zImage_arm_probe(const char *buf, off_t len)
  249. +{
  250. + /*
  251. + * Only zImage loading is supported. Do not check if
  252. + * the buffer is valid kernel image
  253. + */
  254. + return 0;
  255. +}
  256. +void zImage_arm_usage(void)
  257. +{
  258. +}
  259. +int zImage_arm_load(int argc, char **argv, const char *buf, off_t len,
  260. + struct kexec_info *info)
  261. +{
  262. + unsigned long base;
  263. + unsigned int offset = 0x8000; /* 32k offset from memory start */
  264. + base = locate_hole(info,len+offset,0,0,ULONG_MAX,INT_MAX);
  265. + if (base == ULONG_MAX)
  266. + {
  267. + return -1;
  268. + }
  269. + base += offset;
  270. + add_segment(info,buf,len,base,len);
  271. + info->entry = (void*)base;
  272. + return 0;
  273. +}
  274. diff -rduNp kexec-tools-1.101.orig/kexec/kexec-syscall.h kexec-tools-1.101/kexec/kexec-syscall.h
  275. --- kexec-tools-1.101.orig/kexec/kexec-syscall.h 2006-09-20 04:39:38.000000000 +0200
  276. +++ kexec-tools-1.101/kexec/kexec-syscall.h 2007-01-22 15:54:14.000000000 +0100
  277. @@ -43,6 +43,9 @@
  278. #ifdef __s390__
  279. #define __NR_kexec_load 277
  280. #endif
  281. +#ifdef __arm__
  282. +#define __NR_kexec_load __NR_SYSCALL_BASE + 189
  283. +#endif
  284. #ifndef __NR_kexec_load
  285. #error Unknown processor architecture. Needs a kexec_load syscall number.
  286. #endif
  287. @@ -74,6 +77,7 @@ static inline long kexec_reboot(void)
  288. #define KEXEC_ARCH_PPC64 (21 << 16)
  289. #define KEXEC_ARCH_IA_64 (50 << 16)
  290. #define KEXEC_ARCH_S390 (22 << 16)
  291. +#define KEXEC_ARCH_ARM (40 << 16)
  292. #define KEXEC_MAX_SEGMENTS 16
  293. diff -rduNp kexec-tools-1.101.orig/purgatory/arch/arm/Makefile kexec-tools-1.101/purgatory/arch/arm/Makefile
  294. --- kexec-tools-1.101.orig/purgatory/arch/arm/Makefile 1970-01-01 01:00:00.000000000 +0100
  295. +++ kexec-tools-1.101/purgatory/arch/arm/Makefile 2007-01-22 15:54:14.000000000 +0100
  296. @@ -0,0 +1,7 @@
  297. +#
  298. +# Purgatory arm
  299. +#
  300. +
  301. +PURGATORY_S_SRCS +=
  302. +PURGATORY_C_SRCS +=
  303. +
  304. diff -rduNp kexec-tools-1.101.orig/purgatory/arch/arm/include/limits.h kexec-tools-1.101/purgatory/arch/arm/include/limits.h
  305. --- kexec-tools-1.101.orig/purgatory/arch/arm/include/limits.h 1970-01-01 01:00:00.000000000 +0100
  306. +++ kexec-tools-1.101/purgatory/arch/arm/include/limits.h 2007-01-22 15:54:14.000000000 +0100
  307. @@ -0,0 +1,58 @@
  308. +#ifndef LIMITS_H
  309. +#define LIMITS_H 1
  310. +
  311. +
  312. +/* Number of bits in a `char' */
  313. +#define CHAR_BIT 8
  314. +
  315. +/* Minimum and maximum values a `signed char' can hold */
  316. +#define SCHAR_MIN (-128)
  317. +#define SCHAR_MAX 127
  318. +
  319. +/* Maximum value an `unsigned char' can hold. (Minimum is 0.) */
  320. +#define UCHAR_MAX 255
  321. +
  322. +/* Minimum and maximum values a `char' can hold */
  323. +#define CHAR_MIN SCHAR_MIN
  324. +#define CHAR_MAX SCHAR_MAX
  325. +
  326. +/* Minimum and maximum values a `signed short int' can hold */
  327. +#define SHRT_MIN (-32768)
  328. +#define SHRT_MAX 32767
  329. +
  330. +/* Maximum value an `unsigned short' can hold. (Minimum is 0.) */
  331. +#define USHRT_MAX 65535
  332. +
  333. +
  334. +/* Minimum and maximum values a `signed int' can hold */
  335. +#define INT_MIN (-INT_MAX - 1)
  336. +#define INT_MAX 2147483647
  337. +
  338. +/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */
  339. +#define UINT_MAX 4294967295U
  340. +
  341. +
  342. +/* Minimum and maximum values a `signed int' can hold */
  343. +#define INT_MIN (-INT_MAX - 1)
  344. +#define INT_MAX 2147483647
  345. +
  346. +/* Maximum value an `unsigned int' can hold. (Minimum is 0.) */
  347. +#define UINT_MAX 4294967295U
  348. +
  349. +/* Minimum and maximum values a `signed long' can hold */
  350. +#define LONG_MAX 2147483647L
  351. +#define LONG_MIN (-LONG_MAX - 1L)
  352. +
  353. +/* Maximum value an `unsigned long' can hold. (Minimum is 0.) */
  354. +#define ULONG_MAX 4294967295UL
  355. +
  356. +/* Minimum and maximum values a `signed long long' can hold */
  357. +#define LLONG_MAX 9223372036854775807LL
  358. +#define LLONG_MIN (-LONG_MAX - 1LL)
  359. +
  360. +
  361. +/* Maximum value an `unsigned long long' can hold. (Minimum is 0.) */
  362. +#define ULLONG_MAX 18446744073709551615ULL
  363. +
  364. +
  365. +#endif /* LIMITS_H */
  366. diff -rduNp kexec-tools-1.101.orig/purgatory/arch/arm/include/stdint.h kexec-tools-1.101/purgatory/arch/arm/include/stdint.h
  367. --- kexec-tools-1.101.orig/purgatory/arch/arm/include/stdint.h 1970-01-01 01:00:00.000000000 +0100
  368. +++ kexec-tools-1.101/purgatory/arch/arm/include/stdint.h 2007-01-22 15:54:14.000000000 +0100
  369. @@ -0,0 +1,16 @@
  370. +#ifndef STDINT_H
  371. +#define STDINT_H
  372. +
  373. +typedef unsigned long size_t;
  374. +
  375. +typedef unsigned char uint8_t;
  376. +typedef unsigned short uint16_t;
  377. +typedef unsigned int uint32_t;
  378. +typedef unsigned long long uint64_t;
  379. +
  380. +typedef signed char int8_t;
  381. +typedef signed short int16_t;
  382. +typedef signed int int32_t;
  383. +typedef signed long long int64_t;
  384. +
  385. +#endif /* STDINT_H */
  386. --- kexec-tools-1.101/kexec/kexec-syscall.h.orig 2007-10-18 14:28:44.000000000 +1000
  387. +++ kexec-tools-1.101/kexec/kexec-syscall.h 2007-10-18 14:28:57.000000000 +1000
  388. @@ -44,7 +44,7 @@
  389. #define __NR_kexec_load 277
  390. #endif
  391. #ifdef __arm__
  392. -#define __NR_kexec_load __NR_SYSCALL_BASE + 189
  393. +#define __NR_kexec_load __NR_SYSCALL_BASE + 347
  394. #endif
  395. #ifndef __NR_kexec_load
  396. #error Unknown processor architecture. Needs a kexec_load syscall number.