void miner_gen_nonce2_work(struct mm_work *mw, uint32_t nonce2, struct work *work) { uint8_t merkle_root[32], merkle_sha[64]; uint32_t *data32, *swap32, tmp32; int i; tmp32 = bswap_32(nonce2); memcpy(mw->coinbase + mw->nonce2_offset, (uint8_t *)(&tmp32), sizeof(uint32_t)); work->nonce2 = nonce2; dsha256(mw->coinbase, mw->coinbase_len, merkle_root); memcpy(merkle_sha, merkle_root, 32); for (i = 0; i < mw->nmerkles; i++) { memcpy(merkle_sha + 32, mw->merkles[i], 32); dsha256(merkle_sha, 64, merkle_root); memcpy(merkle_sha, merkle_root, 32); } data32 = (uint32_t *)merkle_sha; swap32 = (uint32_t *)merkle_root; flip32(swap32, data32); memcpy(mw->header + mw->merkle_offset, merkle_root, 32); memcpy(work->header, mw->header, 128); calc_midstate(mw, work); }
static int64_t serial_fpga_scanwork(struct thr_info *thr) { struct cgpu_info *serial_fpga; int fd; int ret; struct FPGA_INFO *info; unsigned char ob_bin[44], nonce_buf[SERIAL_READ_SIZE]; char *ob_hex; uint32_t nonce; int64_t hash_count; struct timeval tv_start, tv_finish, elapsed, tv_end, diff; int curr_hw_errors, i, j; uint32_t * ob; ob = (uint32_t *)ob_bin; int count; double Hs, W, fullnonce; int read_count; int64_t estimate_hashes; uint32_t values; int64_t hash_count_range; struct work *work; applog(LOG_DEBUG, "serial_fpga_scanwork..."); if (thr->cgpu->deven == DEV_DISABLED) return -1; serial_fpga = thr->cgpu; info = serial_fpga->device_data; work = get_work(thr, thr->id); if (info->device_fd == -1) { applog(LOG_INFO, "Attemping to Reopen Serial FPGA on %s", serial_fpga->device_path); fd = serial_open(serial_fpga->device_path, SERIAL_IO_SPEED, SERIAL_READ_TIMEOUT, false); if (unlikely(-1 == fd)) { applog(LOG_ERR, "Failed to open Serial FPGA on %s", serial_fpga->device_path); return -1; } else info->device_fd = fd; } fd = info->device_fd; memset(ob_bin, 0, sizeof(ob_bin)); // Currently, extra nonces are not supported // memset((unsigned char*)work->data + 144, 0, 12); // // calc_midstate(work); memcpy(ob_bin, work->midstate, 32); // Midstate memcpy(ob_bin + 32, work->data + 128, 12); // Remaining Bytes From Block Header // Send Bytes To FPGA In Reverse Order unsigned char swap[44]; uint32_t * sw; sw = (uint32_t *)swap; for (j=0; j<8; j++) { sw[j] = swab32(ob[j]); } memcpy(swap + 32, ob_bin + 32, 12); for (j=0; j<44; j++) { ob_bin[j] = swap[j]; } //unsigned char* b = (unsigned char*)(ob_bin); //applog(LOG_WARNING, "swap: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", b[28],b[29],b[30],b[31],b[32],b[33],b[34],b[35],b[36],b[37],b[38],b[39],b[40],b[41],b[42],b[43]); //applog(LOG_WARNING, "swap: %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", b[0],b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8],b[9],b[10],b[11],b[12],b[13],b[14],b[15],b[16],b[17],b[18],b[19],b[20],b[21],b[22],b[23],b[24],b[25],b[26],b[27],b[28],b[29],b[30],b[31],b[32],b[33],b[34],b[35],b[36],b[37],b[38],b[39],b[40],b[41],b[42],b[43]); //#ifndef WIN32 // tcflush(fd, TCOFLUSH); //#endif // Send Data To FPGA ret = write(fd, ob_bin, sizeof(ob_bin)); if (ret != sizeof(ob_bin)) { applog(LOG_ERR, "%s%i: Serial Send Error (ret=%d)", serial_fpga->drv->name, serial_fpga->device_id, ret); serial_fpga_close(thr); dev_error(serial_fpga, REASON_DEV_COMMS_ERROR); return 0; } if (opt_debug) { ob_hex = bin2hex(ob_bin, sizeof(ob_bin)); applog(LOG_DEBUG, "Serial FPGA %d sent: %s", serial_fpga->device_id, ob_hex); free(ob_hex); } elapsed.tv_sec = 0; elapsed.tv_usec = 0; cgtime(&tv_start); applog(LOG_DEBUG, "%s%i: Begin Scan For Nonces", serial_fpga->drv->name, serial_fpga->device_id); while (thr && !thr->work_restart) { memset(nonce_buf,0,4); // Check Serial Port For 1/10 Sec For Nonce ret = read(fd, nonce_buf, SERIAL_READ_SIZE); // Calculate Elapsed Time cgtime(&tv_end); timersub(&tv_end, &tv_start, &elapsed); if (ret == 0) { // No Nonce Found if (elapsed.tv_sec > info->timeout) { applog(LOG_DEBUG, "%s%i: End Scan For Nonces - Time = %d sec", serial_fpga->drv->name, serial_fpga->device_id, elapsed.tv_sec); break; } continue; } else if (ret < SERIAL_READ_SIZE) { applog(LOG_ERR, "%s%i: Serial Read Error (ret=%d)", serial_fpga->drv->name, serial_fpga->device_id, ret); serial_fpga_close(thr); dev_error(serial_fpga, REASON_DEV_COMMS_ERROR); break; } memcpy((char *)&nonce, nonce_buf, SERIAL_READ_SIZE); #if !defined (__BIG_ENDIAN__) && !defined(MIPSEB) nonce = swab32(nonce); #endif curr_hw_errors = serial_fpga->hw_errors; applog(LOG_INFO, "%s%i: Nonce Found - %08X (%5.1fMhz)", serial_fpga->drv->name, serial_fpga->device_id, nonce, (double)(1/(info->Hs * 1000000))); submit_nonce(thr, work, nonce); // Update Hashrate if (serial_fpga->hw_errors == curr_hw_errors) info->Hs = ((double)(elapsed.tv_sec) + ((double)(elapsed.tv_usec))/((double)1000000)) / (double)nonce; } // Estimate Number Of Hashes hash_count = ((double)(elapsed.tv_sec) + ((double)(elapsed.tv_usec))/((double)1000000)) / info->Hs; free_work(work); return hash_count; }
void miner_gen_nonce2_work(struct mm_work *mw, uint32_t nonce2, struct work *work) { uint8_t merkle_root[32], merkle_sha[64]; uint32_t *data32, *swap32, tmp32; int i; tmp32 = bswap_32(nonce2); memcpy(mw->coinbase + mw->nonce2_offset, (uint8_t *)(&tmp32), sizeof(uint32_t)); work->nonce2 = nonce2; gen_hash(mw->coinbase, merkle_root, mw->coinbase_len); memcpy(merkle_sha, merkle_root, 32); for (i = 0; i < mw->nmerkles; i++) { memcpy(merkle_sha + 32, mw->merkles[i], 32); gen_hash(merkle_sha, merkle_root, 64); memcpy(merkle_sha, merkle_root, 32); } data32 = (uint32_t *)merkle_sha; swap32 = (uint32_t *)merkle_root; flip32(swap32, data32); memcpy(mw->header + mw->merkle_offset, merkle_root, 32); debug32("D: Work nonce2: %08x\n", work->nonce2); calc_midstate(mw, work); uint8_t work_t[44]; #ifdef HW_PRE_CALC uint8_t work_t[] = { 0x05, 0x4e, 0x53, 0xc3, 0xc4, 0xd4, 0xba, 0x3e, 0x65, 0x40, 0x99, 0x4f, 0x06, 0x67, 0x91, 0x31, 0xa7, 0x2d, 0x66, 0xaa, 0x68, 0x4f, 0x0e, 0xdb, 0xc3, 0x6d, 0x95, 0x8a, 0x46, 0x6e, 0x4d, 0xb2, 0x1c, 0x26, 0x52, 0xfb, 0x52, 0xa0, 0x26, 0xf4, 0x19, 0x06, 0x12, 0x42}; #endif memcpy(work_t, work->data, 44); rev(work_t, 32); rev(work_t + 32, 12); memcpy(work->data, work_t, 44); #ifdef HW_PRE_CALC calc_prepare(work, work_t); memcpy((uint8_t *)(&tmp32), work->a1, 4); debug32("%08x,", tmp32); memcpy((uint8_t *)(&tmp32), work->a0, 4); debug32("%08x,", tmp32); memcpy((uint8_t *)(&tmp32), work->e2, 4); debug32("%08x,", tmp32); memcpy((uint8_t *)(&tmp32), work->e1, 4); debug32("%08x,", tmp32); memcpy((uint8_t *)(&tmp32), work->e0, 4); debug32("%08x,", tmp32); memcpy((uint8_t *)(&tmp32), work->a2, 4); debug32("%08x", tmp32); debug32("\n"); #endif calc_prepare1(work, work->data); memcpy((uint8_t *)(&tmp32), work->a1, 4); memcpy((uint8_t *)(&tmp32), work->a0, 4); memcpy((uint8_t *)(&tmp32), work->e2, 4); memcpy((uint8_t *)(&tmp32), work->e1, 4); memcpy((uint8_t *)(&tmp32), work->e0, 4); memcpy((uint8_t *)(&tmp32), work->a2, 4); }