igh_ethercat.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. #!/bin/bash
  2. current_path=$(pwd)
  3. work_path=${current_path}/../../work
  4. buildroot_initramfs_sysroot_path=${work_path}/buildroot_initramfs_sysroot
  5. buildroot_rootfs_path=${work_path}/buildroot_rootfs
  6. linux_path=${work_path}/linux
  7. kernel_release_file=${linux_path}/include/config/kernel.release
  8. install_mod_path=${work_path}/module_install_path
  9. toolchains_path=${work_path}/buildroot_initramfs/host/bin
  10. # --------------- Determining whether to compile the SD card image. ---------------
  11. sdcard_img=0
  12. # Determine if compile 'sdcard.img' and check if the root filesystem is compiled.
  13. if [ "$#" -eq 0 ]; then
  14. echo "Compile 'image.fit' only."
  15. echo "If you need to compile 'sdcard.img', usage: '$0 img'"
  16. elif [ "$1" = "img" ]; then
  17. if [ -d "${buildroot_rootfs_path}" ]; then
  18. echo "Compile both 'image.fit' and 'sdcard.img'"
  19. sdcard_img=1
  20. else
  21. echo "Could not add application to sdcard image, please run 'make buildroot_rootfs -j$(nproc)' first."
  22. exit 1
  23. fi
  24. else
  25. echo "The argument is not 'img'"
  26. fi
  27. # --------------- Check if the kernel is on the corresponding branch. ---------------
  28. cd ../../linux
  29. linux_branch=$(git rev-parse --abbrev-ref HEAD)
  30. if [ "$linux_branch" == "rt-ethercat-release" ]; then
  31. echo "Linux source code is on the branch: 'rt-ethercat-release'."
  32. git pull
  33. cd ../
  34. make clean
  35. make -j$(nproc)
  36. cd ${current_path}
  37. else
  38. echo "The Linux source code is not on the 'rt-ethercat-release' branch. Exiting."
  39. cd ${current_path}
  40. exit 1
  41. fi
  42. if [ -d "${buildroot_initramfs_sysroot_path}" ] && [ -d "${linux_path}" ] && [ -d "${install_mod_path}" ]; then
  43. echo "Both directories(${buildroot_initramfs_sysroot_path} and ${linux_path}) exist. Proceeding with the script..."
  44. else
  45. echo "One or both of the directories(${buildroot_initramfs_sysroot_path} and ${linux_path}) do not exist, the SDK may not have been fully compiled. Please check."
  46. exit 1
  47. fi
  48. # --------------- Check EtherCAT repo. ---------------
  49. repo_url="https://gitlab.com/etherlab.org/ethercat.git"
  50. # Don't using stable-1.5, witch will cause:
  51. # Making install in tool
  52. # make[1]: 进入目录“/home/atlas/visionfive/soft_3rdpart/ethercat/tool”
  53. # CXXLD ethercat
  54. # /home/atlas/visionfive/work/buildroot_initramfs/host/lib/gcc/riscv64-buildroot-linux-gnu/12.2.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: ../master/soe_errors.o: can't link soft-float modules with double-float modules
  55. # /home/atlas/visionfive/work/buildroot_initramfs/host/lib/gcc/riscv64-buildroot-linux-gnu/12.2.0/../../../../riscv64-buildroot-linux-gnu/bin/ld: failed to merge target specific data of file ../master/soe_errors.o
  56. # collect2: error: ld returned 1 exit status
  57. # branch_name="stable-1.5"
  58. branch_name="master"
  59. commit_id="775b93de5bab9c572d3e71a9c50b90f25c3edb0e"
  60. check_commit_id() {
  61. local commit_id="$1"
  62. local current_commit=$(git rev-parse HEAD)
  63. if [ "$current_commit" != "$commit_id" ]; then
  64. echo "Switching to the specified commit $commit_id..."
  65. git checkout $commit_id
  66. if [ $? -eq 0 ]; then
  67. echo "Switched to the specified commit $commit_id successfully."
  68. else
  69. echo "Failed to switch to the specified commit $commit_id."
  70. fi
  71. else
  72. echo "The current branch is already on the specified commit $commit_id."
  73. fi
  74. }
  75. if [ -d "ethercat" ]; then
  76. echo "The 'ethercat' directory already exists..."
  77. cd ethercat
  78. current_branch=$(git symbolic-ref --short -q HEAD)
  79. if [ "$current_branch" == "$branch_name" ]; then
  80. echo "The 'ethercat' repository is already cloned and on the '$branch_name' branch."
  81. check_commit_id "$commit_id"
  82. else
  83. git checkout $branch_name
  84. if [ $? -eq 0 ]; then
  85. echo "Switched to the '$branch_name' branch successfully."
  86. make clean
  87. check_commit_id "$commit_id"
  88. else
  89. echo "Failed to switch to the '$branch_name' branch."
  90. fi
  91. fi
  92. cd ../
  93. else
  94. echo "Cloning 'ethercat' repository and checking out the '$branch_name' branch..."
  95. git clone ${repo_url}
  96. if [ $? -eq 0 ]; then
  97. cd ethercat
  98. git checkout $branch_name
  99. check_commit_id "$commit_id"
  100. if [ $? -eq 0 ]; then
  101. echo "Cloned 'ethercat' repository and checked out the '$branch_name' branch successfully."
  102. else
  103. echo "Failed to checkout the '$branch_name' branch."
  104. fi
  105. cd ../
  106. else
  107. echo "Failed to clone the 'ethercat' repository."
  108. exit 1
  109. fi
  110. fi
  111. echo ""
  112. echo "==============================Compiling IgH-EtherCAT=============================="
  113. cd ethercat
  114. ./bootstrap
  115. CC=${toolchains_path}/riscv64-buildroot-linux-gnu-gcc
  116. CXX=${toolchains_path}/riscv64-buildroot-linux-gnu-g++
  117. ./configure --prefix=${buildroot_initramfs_sysroot_path} --with-linux-dir=${linux_path} --enable-8139too=no --enable-generic=yes --enable-hrtimer=yes CC=${CC} CXX=${CXX} --host=riscv64-buildroot-linux-gnu
  118. echo ""
  119. echo "--------------------make--------------------"
  120. make
  121. echo ""
  122. echo "--------------------make modules--------------------"
  123. make ARCH=riscv CROSS_COMPILE=${toolchains_path}/riscv64-buildroot-linux-gnu- modules VERBOSE=1
  124. echo ""
  125. echo "--------------------make install--------------------"
  126. make DESTDIR=${buildroot_initramfs_sysroot_path} install
  127. echo ""
  128. echo "--------------------make modules_install--------------------"
  129. kernel_release=$(cat ${kernel_release_file})
  130. if [ -d "${buildroot_initramfs_sysroot_path}/lib/modules/${kernel_release}" ]; then
  131. echo "The directory exists. Proceeding with make modules_install..."
  132. make INSTALL_MOD_PATH=${install_mod_path} modules_install
  133. echo "modules has been installed in the ${install_mod_path}/lib/modules/${kernel_release}"
  134. else
  135. echo "The directory does not exist. Please check the path."
  136. cd ${current_path}
  137. exit 1
  138. fi
  139. echo ""
  140. echo "==============================Compiling EtherCAT Application=============================="
  141. cd ../application
  142. CC=${CC} make
  143. cp ectest_PV ${buildroot_initramfs_sysroot_path}/root
  144. if [ $sdcard_img -eq 1 ]; then
  145. echo "Copy application to '${buildroot_rootfs_path}/target/root'."
  146. cp ectest_PV ${buildroot_rootfs_path}/target/root
  147. if [ $? -eq 0 ]; then
  148. echo "Copy application to '${buildroot_rootfs_path}/target/root' success."
  149. else
  150. echo "Copy application to '${buildroot_rootfs_path}/target/root' fail."
  151. cd ${current_path}
  152. exit 1
  153. fi
  154. fi
  155. cd ../
  156. echo ""
  157. echo "==============================Copying 'start_ethercat_master.sh'=============================="
  158. chmod +x start_ethercat_master.sh
  159. cp start_ethercat_master.sh ${buildroot_initramfs_sysroot_path}/root
  160. if [ $sdcard_img -eq 1 ]; then
  161. echo "Copy script to '${buildroot_rootfs_path}/target/root'."
  162. cp start_ethercat_master.sh ${buildroot_rootfs_path}/target/root
  163. if [ $? -eq 0 ]; then
  164. echo "Copy script to '${buildroot_rootfs_path}/target/root' success."
  165. else
  166. echo "Copy script to '${buildroot_rootfs_path}/target/root' fail."
  167. cd ${current_path}
  168. exit 1
  169. fi
  170. fi
  171. echo ""
  172. echo "==============================Re-compiling SDK=============================="
  173. cd ${current_path}/../../
  174. make -j$(nproc)
  175. if [ $sdcard_img -eq 1 ]; then
  176. make img
  177. fi
  178. cd ${current_path}