00001
00002
00003 #include "edtinc.h"
00004 #include "edt_bitload.h"
00005
00006
00007 int edt_load_mezzfile(EdtDev *edt_p,
00008 const char *basedir,
00009 const char *name,
00010 int bitload_flags,
00011 int skip_load,
00012 int channel)
00013
00014 {
00015
00016 int i;
00017
00018 int rc;
00019 char bitname[MAXPATH];
00020 char workbase[MAXPATH];
00021 EdtBitfileList mezzfiles;
00022 char *bitpath = "";
00023 EdtBitfile data;
00024 edt_bitfile_init(&data);
00025
00026 bf_init(&mezzfiles);
00027
00028 basedir = edt_bitload_basedir(edt_p, basedir, workbase);
00029
00030 ensure_bitfile_name(name, bitname);
00031
00032
00033 if (edt_p->mezz.id == MEZZ_OC192) {
00034 edt_oc192_rev2_fname_hack(edt_p, bitname, bitname);
00035 }
00036
00037
00038 if (edt_get_bitfile_list(
00039 basedir, "", bitname,
00040 mezz_chips,
00041 edt_p->mezz.id,
00042 channel,
00043 &mezzfiles,NULL) == 0)
00044 {
00045
00046 bf_allocate_max_buffer(&mezzfiles, &data);
00047
00048 for (i=0;i<mezzfiles.nbfiles;i++)
00049 {
00050 bitpath = mezzfiles.bitfiles[i].filename;
00051
00052 if (edt_bitfile_load_file(&data,bitpath) == 0)
00053 {
00054 rc = edt_program_mezzanine(edt_p,
00055 data.full_buffer,
00056 data.full_buffer_size,
00057 channel);
00058
00059 if (rc == 0)
00060 {
00061 if (edt_p->mezz.id == MEZZ_OCM || edt_p->mezz.id == MEZZ_NET10G || edt_p->mezz.id == MEZZ_DDSP)
00062 edt_set_mezz_chan_bitpath(edt_p, bitpath, channel);
00063 else
00064 edt_set_mezz_bitpath(edt_p, bitpath);
00065 break;
00066 }
00067 }
00068 }
00069
00070 edt_bitfile_destroy(&data);
00071
00072 }
00073 else
00074 {
00075 static char s[512];
00076 sprintf(s, "ERROR - can't locate bitfile: \"%s\"", name);
00077 edt_msg_perror(EDTAPP_MSG_FATAL, s);
00078 exit(1);
00079 }
00080
00081 if (rc != 0)
00082 {
00083 edt_msg(EDTAPP_MSG_FATAL, "bitload(name=%s, channel=%d) failed\n", bitname, channel);
00084 if (edt_get_verbosity() < 2)
00085 edt_msg(EDTAPP_MSG_FATAL, " (run with -v to look for the cause of the failure)\n");
00086 else edt_msg(EDTAPP_MSG_FATAL, "\n");
00087 exit(1);
00088 } else {
00089 edt_msg(DEBUG1,"Successfully loaded mezzanine channel %d bitfile '%s'.\n", channel, bitname);
00090 edt_msg(EDTAPP_MSG_WARNING,"Loaded: %s\n", mezzfiles.bitfiles[i].promstr);
00091 rc = edt_get_board_description(edt_p, 0);
00092 if (rc == -1) {
00093 edt_msg(EDTAPP_MSG_FATAL, "ERROR: edt_get_board_description failed.\n");
00094 exit(1);
00095 }
00096 }
00097
00098 bf_destroy(&mezzfiles);
00099
00100 return 0;
00101 }
00102
00103 int edt_program_mezzanine(EdtDev *edt_p, const u_char *buf, u_int size, int channel)
00104
00105 {
00106
00107 #ifdef DO_DIRECT_LOAD
00108 return edt_program_mezzanine_direct(edt_p, buf, size, channel);
00109 #else
00110
00111 int ret;
00112 buf_args args;
00113
00114 memset(&args, 0, sizeof(args));
00115 args.addr = (uint64_t) (buf);
00116 args.size = size;
00117 args.index = channel;
00118
00119 ret = edt_ioctl(edt_p, EDTS_MEZZLOAD, &args);
00120
00121 return args.index;
00122 #endif
00123
00124 }
00125