create_fw.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <string.h>
  8. #include <errno.h>
  9. #include <asm/types.h>
  10. #include <strings.h>
  11. #include <stdint.h>
  12. #include "create_fw.h"
  13. #include "../probe_roms.h"
  14. int write_blob(struct isci_orom *isci_orom)
  15. {
  16. FILE *fd;
  17. int err;
  18. size_t count;
  19. fd = fopen(blob_name, "w+");
  20. if (!fd) {
  21. perror("Open file for write failed");
  22. fclose(fd);
  23. return -EIO;
  24. }
  25. count = fwrite(isci_orom, sizeof(struct isci_orom), 1, fd);
  26. if (count != 1) {
  27. perror("Write data failed");
  28. fclose(fd);
  29. return -EIO;
  30. }
  31. fclose(fd);
  32. return 0;
  33. }
  34. void set_binary_values(struct isci_orom *isci_orom)
  35. {
  36. int ctrl_idx, phy_idx, port_idx;
  37. /* setting OROM signature */
  38. strncpy(isci_orom->hdr.signature, sig, strlen(sig));
  39. isci_orom->hdr.version = version;
  40. isci_orom->hdr.total_block_length = sizeof(struct isci_orom);
  41. isci_orom->hdr.hdr_length = sizeof(struct sci_bios_oem_param_block_hdr);
  42. isci_orom->hdr.num_elements = num_elements;
  43. for (ctrl_idx = 0; ctrl_idx < 2; ctrl_idx++) {
  44. isci_orom->ctrl[ctrl_idx].controller.mode_type = mode_type;
  45. isci_orom->ctrl[ctrl_idx].controller.max_concurrent_dev_spin_up =
  46. max_num_concurrent_dev_spin_up;
  47. isci_orom->ctrl[ctrl_idx].controller.do_enable_ssc =
  48. enable_ssc;
  49. for (port_idx = 0; port_idx < 4; port_idx++)
  50. isci_orom->ctrl[ctrl_idx].ports[port_idx].phy_mask =
  51. phy_mask[ctrl_idx][port_idx];
  52. for (phy_idx = 0; phy_idx < 4; phy_idx++) {
  53. isci_orom->ctrl[ctrl_idx].phys[phy_idx].sas_address.high =
  54. (__u32)(sas_addr[ctrl_idx][phy_idx] >> 32);
  55. isci_orom->ctrl[ctrl_idx].phys[phy_idx].sas_address.low =
  56. (__u32)(sas_addr[ctrl_idx][phy_idx]);
  57. isci_orom->ctrl[ctrl_idx].phys[phy_idx].afe_tx_amp_control0 =
  58. afe_tx_amp_control0;
  59. isci_orom->ctrl[ctrl_idx].phys[phy_idx].afe_tx_amp_control1 =
  60. afe_tx_amp_control1;
  61. isci_orom->ctrl[ctrl_idx].phys[phy_idx].afe_tx_amp_control2 =
  62. afe_tx_amp_control2;
  63. isci_orom->ctrl[ctrl_idx].phys[phy_idx].afe_tx_amp_control3 =
  64. afe_tx_amp_control3;
  65. }
  66. }
  67. }
  68. int main(void)
  69. {
  70. int err;
  71. struct isci_orom *isci_orom;
  72. isci_orom = malloc(sizeof(struct isci_orom));
  73. memset(isci_orom, 0, sizeof(struct isci_orom));
  74. set_binary_values(isci_orom);
  75. err = write_blob(isci_orom);
  76. if (err < 0) {
  77. free(isci_orom);
  78. return err;
  79. }
  80. free(isci_orom);
  81. return 0;
  82. }