igh_ethercat.sh 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. sdcard_img=0
  11. # Determine if compile 'sdcard.img' and check if the root filesystem is compiled.
  12. if [ "$#" -eq 0 ]; then
  13. echo "Compile 'image.fit' only."
  14. echo "If you need to compile 'sdcard.img', usage: '$0 img'"
  15. elif [ "$1" = "img" ]; then
  16. if [ -d "${buildroot_rootfs_path}" ]; then
  17. echo "Compile both 'image.fit' and 'sdcard.img'"
  18. sdcard_img=1
  19. else
  20. echo "Could not add application to sdcard image, please run 'make buildroot_rootfs -j$(nproc)' first."
  21. exit 1
  22. fi
  23. else
  24. echo "The argument is not 'img'"
  25. fi
  26. cd ../../linux
  27. linux_branch=$(git rev-parse --abbrev-ref HEAD)
  28. if [ "$linux_branch" == "rt-ethercat-release" ]; then
  29. echo "Linux source code is on the branch: 'rt-ethercat-release'."
  30. git pull
  31. cd ../
  32. make clean
  33. make -j$(nproc)
  34. else
  35. echo "The Linux source code is not on the 'rt-ethercat-release' branch. Exiting."
  36. cd ${current_path}
  37. exit 1
  38. fi
  39. cd ${current_path}
  40. if [ -d "${buildroot_initramfs_sysroot_path}" ] && [ -d "${linux_path}" ] && [ -d "${install_mod_path}" ]; then
  41. echo "Both directories(${buildroot_initramfs_sysroot_path} and ${linux_path}) exist. Proceeding with the script..."
  42. else
  43. 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."
  44. exit 1
  45. fi
  46. repo_url="https://gitlab.com/etherlab.org/ethercat.git"
  47. # Don't using stable-1.5, witch will cause:
  48. # Making install in tool
  49. # make[1]: 进入目录“/home/atlas/visionfive/soft_3rdpart/ethercat/tool”
  50. # CXXLD ethercat
  51. # /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
  52. # /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
  53. # collect2: error: ld returned 1 exit status
  54. # branch_name="stable-1.5"
  55. branch_name="master"
  56. commit_id="775b93de5bab9c572d3e71a9c50b90f25c3edb0e"
  57. check_commit_id() {
  58. local commit_id="$1"
  59. local current_commit=$(git rev-parse HEAD)
  60. if [ "$current_commit" != "$commit_id" ]; then
  61. echo "Switching to the specified commit $commit_id..."
  62. git checkout $commit_id
  63. if [ $? -eq 0 ]; then
  64. echo "Switched to the specified commit $commit_id successfully."
  65. else
  66. echo "Failed to switch to the specified commit $commit_id."
  67. fi
  68. else
  69. echo "The current branch is already on the specified commit $commit_id."
  70. fi
  71. }
  72. if [ -d "ethercat" ]; then
  73. echo "The 'ethercat' directory already exists..."
  74. cd ethercat
  75. current_branch=$(git symbolic-ref --short -q HEAD)
  76. if [ "$current_branch" == "$branch_name" ]; then
  77. echo "The 'ethercat' repository is already cloned and on the '$branch_name' branch."
  78. check_commit_id "$commit_id"
  79. else
  80. git checkout $branch_name
  81. if [ $? -eq 0 ]; then
  82. echo "Switched to the '$branch_name' branch successfully."
  83. make clean
  84. check_commit_id "$commit_id"
  85. else
  86. echo "Failed to switch to the '$branch_name' branch."
  87. fi
  88. fi
  89. cd ../
  90. else
  91. echo "Cloning 'ethercat' repository and checking out the '$branch_name' branch..."
  92. git clone ${repo_url} ${directory_name}
  93. if [ $? -eq 0 ]; then
  94. cd "$directory_name"
  95. git checkout $branch_name
  96. check_commit_id "$commit_id"
  97. if [ $? -eq 0 ]; then
  98. echo "Cloned 'ethercat' repository and checked out the '$branch_name' branch successfully."
  99. else
  100. echo "Failed to checkout the '$branch_name' branch."
  101. fi
  102. else
  103. echo "Failed to clone the 'ethercat' repository."
  104. fi
  105. fi
  106. echo ""
  107. echo "==============================Compiling IgH-EtherCAT=============================="
  108. cd ethercat
  109. ./bootstrap
  110. CC=${toolchains_path}/riscv64-buildroot-linux-gnu-gcc
  111. CXX=${toolchains_path}/riscv64-buildroot-linux-gnu-g++
  112. ./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
  113. echo ""
  114. echo "--------------------make--------------------"
  115. make
  116. echo ""
  117. echo "--------------------make modules--------------------"
  118. make ARCH=riscv CROSS_COMPILE=${toolchains_path}/riscv64-buildroot-linux-gnu- modules VERBOSE=1
  119. echo ""
  120. echo "--------------------make install--------------------"
  121. make DESTDIR=${buildroot_initramfs_sysroot_path} install
  122. echo ""
  123. echo "--------------------make modules_install--------------------"
  124. kernel_release=$(cat ${kernel_release_file})
  125. if [ -d "${buildroot_initramfs_sysroot_path}/lib/modules/${kernel_release}" ]; then
  126. echo "The directory exists. Proceeding with make modules_install..."
  127. make INSTALL_MOD_PATH=${install_mod_path} modules_install
  128. echo "modules has been installed in the ${install_mod_path}/lib/modules/${kernel_release}"
  129. else
  130. echo "The directory does not exist. Please check the path."
  131. fi
  132. echo ""
  133. echo "==============================Compiling EtherCAT Application=============================="
  134. cd ../application
  135. CC=${CC} make
  136. cp ectest_PV ${buildroot_initramfs_sysroot_path}/root
  137. if [ $sdcard_img -eq 1 ]; then
  138. echo "Copy application to '${buildroot_rootfs_path}/target/root'."
  139. cp ectest_PV ${buildroot_rootfs_path}/target/root
  140. fi
  141. echo ""
  142. echo "==============================Generating 'start_ethercat_master.sh'=============================="
  143. cd ${buildroot_initramfs_sysroot_path}/root
  144. cat <<EOF > start_ethercat_master.sh
  145. #!/bin/bash
  146. if [ \$# -eq 0 ]; then
  147. echo "Usage: $0 <MAC address>"
  148. exit 1
  149. fi
  150. mac_address="\$1"
  151. modprobe phylink
  152. insmod /lib/modules/${kernel_release}/ethercat/master/ec_master.ko main_devices="\$mac_address"
  153. insmod /lib/modules/${kernel_release}/ethercat/devices/ec_generic.ko
  154. modprobe pcs_xpcs
  155. cd /lib/modules/${kernel_release}/kernel/drivers/net/ethernet/stmicro/stmmac/
  156. insmod stmmac.ko
  157. insmod stmmac-platform.ko
  158. insmod dwmac-starfive-plat.ko
  159. cd /root
  160. EOF
  161. chmod +x start_ethercat_master.sh
  162. if [ $sdcard_img -eq 1 ]; then
  163. echo "Copy script to '${buildroot_rootfs_path}/target/root'."
  164. cp start_ethercat_master.sh ${buildroot_rootfs_path}/target/root
  165. fi
  166. echo ""
  167. echo "==============================Re-compiling SDK=============================="
  168. cd ${current_path}/../../
  169. make -j$(nproc)
  170. if [ $sdcard_img -eq 1 ]; then
  171. make img
  172. fi
  173. cd ${current_path}