4
0

build.rs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. use std::{env, path::PathBuf};
  2. fn main() {
  3. let out = PathBuf::from(env::var_os("OUT_DIR").unwrap());
  4. let ld = &out.join("rustsbi-prototyper.ld");
  5. std::fs::write(ld, LINKER_SCRIPT).unwrap();
  6. println!("cargo:rerun-if-env-changed=RUST_LOG,PROTOTYPER_FDT,PROTOTYPER_IMAGE");
  7. println!("cargo:rustc-link-arg=-T{}", ld.display());
  8. println!("cargo:rustc-link-search={}", out.display());
  9. }
  10. #[cfg(feature = "payload")]
  11. const LINKER_SCRIPT: &[u8] = b"OUTPUT_ARCH(riscv)
  12. ENTRY(_start)
  13. SECTIONS {
  14. . = 0x80000000;
  15. .text : ALIGN(8) {
  16. *(.text.entry)
  17. *(.text .text.*)
  18. }
  19. .rodata : ALIGN(8) {
  20. srodata = .;
  21. *(.rodata .rodata.*)
  22. *(.srodata .srodata.*)
  23. . = ALIGN(8);
  24. erodata = .;
  25. }
  26. .data : ALIGN(8) {
  27. sdata = .;
  28. *(.data .data.*)
  29. *(.sdata .sdata.*)
  30. . = ALIGN(8);
  31. edata = .;
  32. }
  33. sidata = LOADADDR(.data);
  34. .bss (NOLOAD) : ALIGN(8) {
  35. *(.bss.uninit)
  36. sbss = .;
  37. *(.bss .bss.*)
  38. *(.sbss .sbss.*)
  39. ebss = .;
  40. }
  41. /DISCARD/ : {
  42. *(.eh_frame)
  43. }
  44. .text 0x80100000 : ALIGN(8) {
  45. *(.fw_fdt)
  46. }
  47. .text 0x80200000 : ALIGN(8) {
  48. *(.payload)
  49. }
  50. }";
  51. #[cfg(not(feature = "payload"))]
  52. const LINKER_SCRIPT: &[u8] = b"OUTPUT_ARCH(riscv)
  53. ENTRY(_start)
  54. SECTIONS {
  55. . = 0x80100000;
  56. .text : ALIGN(8) {
  57. *(.text.entry)
  58. *(.text .text.*)
  59. }
  60. .rodata : ALIGN(8) {
  61. srodata = .;
  62. *(.rodata .rodata.*)
  63. *(.srodata .srodata.*)
  64. . = ALIGN(8);
  65. erodata = .;
  66. }
  67. .data : ALIGN(8) {
  68. sdata = .;
  69. *(.data .data.*)
  70. *(.sdata .sdata.*)
  71. . = ALIGN(8);
  72. edata = .;
  73. }
  74. sidata = LOADADDR(.data);
  75. .bss (NOLOAD) : ALIGN(8) {
  76. *(.bss.uninit)
  77. sbss = .;
  78. *(.bss .bss.*)
  79. *(.sbss .sbss.*)
  80. ebss = .;
  81. }
  82. /DISCARD/ : {
  83. *(.eh_frame)
  84. }
  85. }";