Pages:
Author

Topic: Baikal X10 ⚡OVERCLOCK⚡ Claim reward 0.2 BTC for TUTORIAL HOW TO :)⚡⚡⚡⚡ - page 7. (Read 22759 times)

jr. member
Activity: 56
Merit: 1
Uploaded the three firmwares I have here:

https://drive.google.com/open?id=1Xyn5R6X38Jx4i9J50pF_upwgs0hdoXGN

Files are PiZero_GX10_171111_V1.0.img, PiZero_GX10_171229_V1.1.img, PiZero_GB_180105_V1.0.img
newbie
Activity: 87
Merit: 0
If anyone have the Giant B and Giant x10 and don't mind doing a little work, can you take out the controller board (the board that goes on top of the 3 hash boards) and also the orange pi and swap them?

Want to see if the 3 hashing boards on the Giant B and Giant x10 are the same. If it works, then that means you will only need to update the controller board first, since just swapping out SD Cards does nothing.

It will be pointless trying to compile a custom sgminer if you require to update the controller board first.

We tryed it.  It does not work.  They are different!
member
Activity: 311
Merit: 69
PowerMining.pw
Ive been able to recompile sgminer based on files from X10 and CN, however some problems at hand with USB communcation to the boards, guess ill figure out those in a while. As an example i found nothing less than 33 different versions of driver-baikalu.c, so there will be some sorting before everythings ok.

Code:
sgminer 5.6.2-cod3gen - Started: [2018-03-25 16:45:04] - [0 days 00:00:16]
--------------------------------------------------------------------------------
(5s):0.000 (avg):0.000h/s | A:0  R:0  HW:0  WU:0.000/m
ST: 1  SS: 0  NB: 1  LW: 17  GF: 0  RF: 0
Connected to quark.eu.nicehash.com (stratum) diff 40 as user XXX
Block: 51abe371...  Diff:101M  Started: [16:45:03]  Best share: 0
--------------------------------------------------------------------------------
 [U]SB management [P]ool management [S]ettings [D]isplay options [Q]uit
--------------------------------------------------------------------------------
 [2018-03-25 16:45:02.877] Started sgminer 5.6.2-cod3gen
 [2018-03-25 16:45:02.877] * using Jansson 2.7
 [2018-03-25 16:45:02.878] Loaded configuration file /opt/scripta/etc/miner.conf

[b] [2018-03-25 16:45:03.098] No devices detected!
 [2018-03-25 16:45:03.099] Waiting for USB hotplug devices or press q to quit[/b]
 [2018-03-25 16:45:03.099] Probing for an alive pool
 [2018-03-25 16:45:03.480] Startup BaikalMiner initialization... Using settings
from pool quark.eu.nicehash.com.
 [2018-03-25 16:45:03.480] Startup Pool No = 0
 [2018-03-25 16:45:03.498] quark.eu.nicehash.com difficulty changed to 40.960
 [2018-03-25 16:45:09.102] API running in IP access mode on port 4028 (11)

If anyone have the Giant B and Giant x10 and don't mind doing a little work, can you take out the controller board (the board that goes on top of the 3 hash boards) and also the orange pi and swap them?

Want to see if the 3 hashing boards on the Giant B and Giant x10 are the same. If it works, then that means you will only need to update the controller board first, since just swapping out SD Cards does nothing.

It will be pointless trying to compile a custom sgminer if you require to update the controller board first.

X10, B and CN all have different chips, so i dont think it will be possible to cross them, i would not suggest that any one tries this unless they have no problem risking their hardware.

X10 seems to be able to support additional coins: groestl, nist5, x11-gost and veltor, thats atleast what im trying to figure out.
sr. member
Activity: 544
Merit: 250
If anyone have the Giant B and Giant x10 and don't mind doing a little work, can you take out the controller board (the board that goes on top of the 3 hash boards) and also the orange pi and swap them?

Want to see if the 3 hashing boards on the Giant B and Giant x10 are the same. If it works, then that means you will only need to update the controller board first, since just swapping out SD Cards does nothing.

It will be pointless trying to compile a custom sgminer if you require to update the controller board first.
newbie
Activity: 50
Merit: 0

I just used photorec to recovery any/all deleted files, then used astrogrep to do some searching.  The file names do not correlate.  Photorec just gives them a generic name.  We'll need more people searching for the other source files, my brain hurts.  ;o)  

Can someone post the very first image file for the X10? I have v1.0 and v1.1, but was thinking I heard someone mention an earlier one.

Nice find!
Actually the c file source code looks like that it belongs to a Giant B based on the static bool baikal_send_work function. And the DEVICE_BAIKAL_H header file that you posted seems to belong to a MINI or CUBE miner. Strange...

Could you please upload the v1.0 image file to mega.nz or google drive?

Here's a link to the undeleted bin (PiZero_GX10_171229_V1.1.img) file:

https://drive.google.com/file/d/14__gwiueXt-OBfkveUK_eMqmNhKxajni/view?usp=sharing

I haven't started uploading the 4 gig (PiZero_GX10_171229_V1.0.img) file.  I'll do it if you really need it and of course if no one else uploads it!
newbie
Activity: 11
Merit: 0
Hey guys,


two things to say,

We need to work on two things, overclocking to 420MHz and to recover the data of the two algorithms. missing:

1) Will upload to Mega the recovered data so you can see for yourself what you can work with..

2) Will it help (overclocking) this info found in the SD Image?

root@Baikal:/sys/bus/cpu/devices/cpu0/cpufreq# ls                         
affected_cpus      cpuinfo_transition_latency   scaling_governor         
boot_lock          dvfs_debug                   scaling_max_freq         
cpuinfo_boot_freq  related_cpus                 scaling_min_freq         
cpuinfo_cur_freq   scaling_available_governors  scaling_setspeed         
cpuinfo_max_freq   scaling_cur_freq             stats
cpuinfo_min_freq   scaling_driver     

---------------------------------
  GNU nano 2.5.3          File: cpuinfo_cur_freq                         
                                                                         
816000                                                                   
                --

Also while messing with the terminal, an auto generated mail went to the root folder saying

Subject: *** SECURITY information for baikal ***                         

baikal : Feb 10 07:34:20 : www-data : user NOT in sudoers ; TTY=unknown ;$
                                                                         
From www-data@baikal  Fri Feb 10 07:35:24 2017                           
Return-Path:                                            
Received: from baikal (baikal [127.0.0.1])                               
        by baikal (8.15.2/8.15.2/Debian-3) with ESMTP id v1A7ZOC3017405   
        for ; Fri, 10 Feb 2017 07:35:24 GMT                 
Received: (from www-data@localhost)                                       
        by baikal (8.15.2/8.15.2/Submit) id v1A7ZOLM017255;               
        Fri, 10 Feb 2017 07:35:24 GMT                                     
Date: Fri, 10 Feb 2017 07:35:24 GMT                                       
Message-Id: <201702100735.v1A7ZOLM017255@baikal>                         
To: root@baikal                                                           
From: www-data@baikal                                                     
Auto-Submitted: auto-generated                                           
Subject: *** SECURITY information for baikal ***                         
                                                                         
baikal : Feb 10 07:34:24 : www-data : user NOT in sudoers ; TTY=unknown ;$

jr. member
Activity: 42
Merit: 25
Of particular interest is this line:
Code:
msg.data[0] = (clk == 0) ? clk : ((clk / 10) % 20) + 2;
It looks like calling baikal_setoption() allows the clock to be set to an arbitrary value.

To be honest I don't get the point of this part ((clk / 10) % 20) + 2
It just doesn't make any sense to me. If the clock is set to 400 MHz, then the msg.data[0] value will be 2. While if the clock is 300 MHz, then msg.data[0] is 12.
What is the logic here?

[divide by 10] indicates 10MHz increments, [mod 20] indicates a lookup table with 20 items, [+ 2] indicates the list begins at index #2:

Code:
2    400 (Giant B stock)
3    410/210
4    420/220
5    430/230
6    440/240
7    450/250
8    460/260
9    470/270
10   480/280
11   490/290
12   300 (Giant x10 stock)
13   310
14   320
15   330
16   340
17   350
18   360
19   370
20   380
21   390

Not sure whether, for example, #7 would give 450 or 250MHz - an experiment is needed.
member
Activity: 311
Merit: 69
PowerMining.pw
Nice find! Actually the source code looks like that it belongs to a Giant B, is that correct?

From what ive found, source code is same for X10, B and CN.
newbie
Activity: 43
Merit: 0
Of particular interest is this line:
Code:
msg.data[0] = (clk == 0) ? clk : ((clk / 10) % 20) + 2;
It looks like calling baikal_setoption() allows the clock to be set to an arbitrary value.

To be honest I don't get the point of this part ((clk / 10) % 20) + 2
It just doesn't make any sense to me. If the clock is set to 400 MHz, then the msg.data[0] value will be 2. While if the clock is 300 MHz, then msg.data[0] is 12.
What is the logic here?
newbie
Activity: 43
Merit: 0

I just used photorec to recovery any/all deleted files, then used astrogrep to do some searching.  The file names do not correlate.  Photorec just gives them a generic name.  We'll need more people searching for the other source files, my brain hurts.  ;o)  

Can someone post the very first image file for the X10? I have v1.0 and v1.1, but was thinking I heard someone mention an earlier one.

Nice find!
Actually the c file source code looks like that it belongs to a Giant B based on the static bool baikal_send_work function. And the DEVICE_BAIKAL_H header file that you posted seems to belong to a MINI or CUBE miner. Strange...

Could you please upload the v1.0 image file to mega.nz or google drive?
newbie
Activity: 50
Merit: 0
Here it is.  A slightly modified algorithm.h file:

Thanks. Now I'm interested in:
Code:
int to_baikal_algorithm(algorithm_type_t type);

In a different file:
Code:
#ifdef USE_BAIKAL
int to_baikal_algorithm(algorithm_type_t type)
{
    switch (type) {
    case ALGO_X11:
        return 1;
    case ALGO_X13:
        return 2;
    case ALGO_X14:
        return 3;
    case ALGO_X15:           
        return 4;
    case ALGO_QUARK:       
        return 5;
    case ALGO_QUBIT:
        return 6;   
    default:
        return 0;
        break;
    }
}
#endif

Looks like this is a pretty old version of the source as that list doesn't contain Skein or MGroestl, as the x10 is known to have. This looks like the same list of algorithms that Baikal's older Mini Miner and Giant A900 Dash Miner had so it may not have any new code at all for the x10/B/N (in this deleted version). Maybe it's just as easy as adding a few cases in there for the missing ones and using guess-and-check to get the right values.

Did those earlier generations use pi's also?  I've never messed with them.

Here's a couple snippets from another version that do contain Skein and Myriad Groestl:

Code:
...
static bool baikal_send_work(struct cgpu_info *baikal, int miner_id)
{
    struct baikal_info *info = baikal->device_data;
    struct miner_info *miner = &info->miners[miner_id];
    struct thr_info *thr = mining_thr[miner->thr_id];
    struct work *work;
    uint32_t target;
    baikal_msg msg;
    uint8_t algo;
    uint32_t * mdata,*wdata;

    /* Do not send */
    if (miner->overheated == true) {
        return (true);
    }

    mutex_lock(baikal->mutex);
    if (info->works[info->work_idx] == NULL) {
        work = get_work(thr, miner->thr_id);                             
        info->works[info->work_idx] = work;

#if 0   /* TODO : Performance Check */
        if (thr->work_restart) {                   
            free_work(info->works[info->work_idx]);
            info->works[info->work_idx] = NULL;   
            applog(LOG_ERR, "work restart\n");     
            mutex_unlock(baikal->mutex);           
            return true;                           
        }                                         
#endif
    }
   
    if (work->pool->algorithm.type != thr->cgpu->algorithm.type) {
        thr->cgpu->algorithm.type = work->pool->algorithm.type;
    }

    work->device_diff = MAX(miner->working_diff, work->work_difficulty);
    //work->device_diff = MIN(miner->working_diff, work->work_difficulty);
    set_target(work->device_target, work->device_diff, work->pool->algorithm.diff_multiplier2, work->thr_id);

    memset(msg.data, 0x0, 512);
    msg.data[0] = to_baikal_algorithm(thr->cgpu->algorithm.type);
    msg.data[1] = miner_id;
    memcpy(&msg.data[2], &work->device_target[24], 8);
    if (*((uint32_t *)&msg.data[6]) != 0x0) { // TripleS
        memset(&msg.data[2], 0xFF, 4);
    }

    switch (baikal->algorithm.type) {
    case ALGO_BLAKECOIN:        // blake256r8
        if (work->pool->algorithm.calc_midstate) {   // use midstate
            msg.data[0] += 1;

            memcpy(&msg.data[10], work->midstate, 32);
            memcpy(&msg.data[42], &work->data[64], 16);
            be32enc_vect((uint32_t *)&msg.data[42], (const uint32_t *)&msg.data[42], 4);
            *((uint32_t *)&msg.data[58]) = 0x00000080;
            *((uint32_t *)&msg.data[94]) = 0x01000000;
            *((uint32_t *)&msg.data[102]) = 0x80020000;
            msg.len = 106;
        }
        else {
            memcpy(&msg.data[10], work->data, 80);
            be32enc_vect((uint32_t *)&msg.data[10], (const uint32_t *)&msg.data[10], 20);
            msg.len = 90;
        }
        break;

    case ALGO_DECRED:           // blake256r14
        if (work->pool->algorithm.calc_midstate) {   // use midstate
            msg.data[0] += 1;

            memcpy(&msg.data[10], work->midstate, 32);
            memcpy(&msg.data[42], &work->data[128], 52);
            *((uint32_t *)&msg.data[94]) = 0x01000080UL;
            *((uint32_t *)&msg.data[98]) = 0x00000000UL;
            *((uint32_t *)&msg.data[102]) = 0xa0050000UL;
            msg.len = 106;
        }
        else {
            memcpy(&msg.data[10], work->data, 180);
            msg.len = 190;
        }
        break;
    case ALGO_SIA:              // blake2b
        memcpy(&msg.data[10], work->data, 80);
        be32enc_vect((uint32_t *)&msg.data[10], (const uint32_t *)&msg.data[10], 20);
        msg.len = 90;
        break;

    case ALGO_LBRY:             // lbry-all
        memcpy(&msg.data[10], work->data, 112);
        be32enc_vect((uint32_t *)&msg.data[10], (const uint32_t *)&msg.data[10], 27);
        msg.len = 122;
        break;

    case ALGO_PASCAL:           // lbry-sha
        memcpy(&msg.data[10], work->data, 200);
        msg.len = 210;
        break;

    case ALGO_X11:
    case ALGO_X11GOST:
    case ALGO_SKEINCOIN:
    case ALGO_MYRIAD_GROESTL:
    case ALGO_QUARK:
    case ALGO_QUBIT:
    case ALGO_GROESTL:
    case ALGO_SKEIN2:
    case ALGO_NIST:
    case ALGO_CRYPTONIGHT:
    case ALGO_CRYPTONIGHT_LITE:
    case ALGO_BLAKE:
    case ALGO_VANILLA:
    case ALGO_VELTOR:
    default:
        memcpy(&msg.data[10], work->data, 80);
        msg.len = 90;
        break;
    }
    msg.miner_id    = miner_id;
    msg.cmd         = BAIKAL_SEND_WORK;
    msg.param       = info->work_idx;
    msg.dest        = 0;

    //mutex_lock(baikal->mutex);

    if (baikal_sendmsg(baikal, &msg) < 0) {
        applog(LOG_ERR, "baikal_send_work : sendmsg error[%d]", miner_id);
        mutex_unlock(baikal->mutex);
        return (false);
    }

    if (baikal_readmsg(baikal, &msg, 7) < 0) {
        applog(LOG_ERR, "baikal_send_work : readmsg error[%d]", miner_id);
        mutex_unlock(baikal->mutex);
        return (false);
    }

    /* update clock */
    miner->clock = msg.param << 1;

    info->work_idx++;
    if (info->work_idx >= BAIKAL_WORK_FIFO) {
        info->work_idx = 0;
    }

    if (info->works[info->work_idx] != NULL) {
        free_work(info->works[info->work_idx]);
        info->works[info->work_idx] = NULL;
    }
       
    cgtimer_time(&miner->start_time);
    mutex_unlock(baikal->mutex);

    return (true);
}
...
Code:
...
static int64_t baikal_hash_done(struct cgpu_info *baikal, struct miner_info *miner, int elpased)
{
    int64_t hash_done = 0;

    switch(baikal->algorithm.type) {       
    case ALGO_CRYPTONIGHT:
        hash_done = miner->clock * miner->asic_count * elapsed / 1776;
        break;
    case ALGO_CRYPTONIGHT_LITE:
        hash_done = miner->clock * miner->asic_count * elapsed / 888;
        break;
    case ALGO_X11:
    case ALGO_QUARK:
    case ALGO_QUBIT:
    case ALGO_NIST: 
    case ALGO_SKEINCOIN:
    case ALGO_SKEIN2:
    case ALGO_MYRIAD_GROESTL:
    case ALGO_GROESTL:
        hash_done = miner->clock * miner->asic_count * elapsed * 128;
        break;
    case ALGO_X11GOST:
    case ALGO_VELTOR:
        hash_done = miner->clock * miner->asic_count * elapsed * 18;
        break;
   
    case ALGO_BLAKECOIN
    case ALGO_DECRED
    case ALGO_VANILLA
    case ALGO_BLAKE
        hash_done = miner->clock * miner->asic_count * elapsed * 2048;
        break;

    case ALGO_SIA   
        hash_done = miner->clock * miner->asic_count * elapsed * 1024;
        break;   
    case ALGO_LBRY
    case ALGO_PASCAL
        hash_done = miner->clock * miner->asic_count * elapsed * 512;
        break;
    }

    return hash_done;
}
...
jr. member
Activity: 504
Merit: 3
Im more interested in what other coins can be mined. Currently what i have figured out is that;
Currently included:
X11
QUARK
QUBIT
SKEIN
MyrGroestl

Possible and highly likely alternatives listed below, however they are defined with a different type of X10 it seems, so im not sure it even will be possible for those that are for sale now:
- Groestl
- Nist5
- X11 Gost
- Veltor

These alternatives are based on recovered files. The code also seems to reveal that they have had the "new" CN miner a long time, actually it would seem as they maybe even started production of that one before X10.

Currently done recovering about 80% of the code, will probably start trying to recompile to see if it works tomorrow.

Amazing I am very excited about it. I will have xome X10 soon. Keep us updated! Smiley
member
Activity: 311
Merit: 69
PowerMining.pw
Im more interested in what other coins can be mined. Currently what i have figured out is that;
Currently included:
X11
QUARK
QUBIT
SKEIN
MyrGroestl

Possible and highly likely alternatives listed below, however they are defined with a different type of X10 it seems, so im not sure it even will be possible for those that are for sale now:
- Groestl
- Nist5
- X11 Gost
- Veltor

These alternatives are based on recovered files. The code also seems to reveal that they have had the "new" CN miner a long time, actually it would seem as they maybe even started production of that one before X10.

Currently done recovering about 80% of the code, will probably start trying to recompile to see if it works tomorrow.
newbie
Activity: 11
Merit: 0
By the way, while looking at some TAR Files recovered, I do see a lot "fakeroot" mentions, and a "ustar" mention, maybe the wanna play us with some fakeroot login through terminal....

I am not a programmer but just saying...
newbie
Activity: 11
Merit: 0
Will try to reocover more files. In the other hand, I was messing around the terminal of the X10, went in root mode to some folders inside where they code a lot about the clockrate of each of the three cards, will post about it later on guys.

I do believe Baikal will not help us to make more money, but if we get together we can make this machine a BEAST mining any algo at diffrerent clockrates!

Keep it up guys...very nice work! will help for sure...lets try to get this more private.
newbie
Activity: 50
Merit: 0
Could be.  There are many copies of most of the files, I think they'll need to be compared to figure out the latest version.  I am hoping someone smarter than me can piece it together and at least get the clock rate adjustable.  Give me some more keywords to search for and I'll try to post more information.  The searches take a while to complete.
jr. member
Activity: 42
Merit: 25
Here it is.  A slightly modified algorithm.h file:

Thanks. Now I'm interested in:
Code:
int to_baikal_algorithm(algorithm_type_t type);

In a different file:
Code:
#ifdef USE_BAIKAL
int to_baikal_algorithm(algorithm_type_t type)
{
    switch (type) {
    case ALGO_X11:
        return 1;
    case ALGO_X13:
        return 2;
    case ALGO_X14:
        return 3;
    case ALGO_X15:           
        return 4;
    case ALGO_QUARK:       
        return 5;
    case ALGO_QUBIT:
        return 6;   
    default:
        return 0;
        break;
    }
}
#endif

Looks like this is a pretty old version of the source as that list doesn't contain Skein or MGroestl, as the x10 is known to have. This looks like the same list of algorithms that Baikal's older Mini Miner and Giant A900 Dash Miner had so it may not have any new code at all for the x10/B/N (in this deleted version). Maybe it's just as easy as adding a few cases in there for the missing ones and using guess-and-check to get the right values.
newbie
Activity: 50
Merit: 0
Here it is.  A slightly modified algorithm.h file:

Code:
#ifndef ALGORITHM_H
#define ALGORITHM_H

#include "config.h"

#ifdef __APPLE_CC__
#include
#else
#ifdef USE_GPU
#include
#endif
#endif

#include
#include
#include

#ifdef USE_GPU
#include "ocl/build_kernel.h"   // For the build_kernel_data type
#endif

#define SUPPORT_SIAPOOL        (0)

typedef enum {
  ALGO_UNK,
  ALGO_CRE,
  ALGO_SCRYPT,
  ALGO_NSCRYPT,
  ALGO_PASCAL,
  ALGO_X11,
  ALGO_X11GOST,
  ALGO_X13,
  ALGO_X14,
  ALGO_X15,
  ALGO_KECCAK,
  ALGO_QUARK,
  ALGO_TWE,
  ALGO_FUGUE,
  ALGO_NIST,
  ALGO_FRESH,
  ALGO_WHIRL,
  ALGO_NEOSCRYPT,
  ALGO_WHIRLPOOLX,
  ALGO_LYRA2RE,
  ALGO_LYRA2REV2,
  ALGO_PLUCK,
  ALGO_YESCRYPT,
  ALGO_YESCRYPT_MULTI,
  ALGO_BLAKECOIN,
  ALGO_BLAKE,
  ALGO_SIA,
  ALGO_DECRED,
  ALGO_VANILLA,
  ALGO_LBRY,
  ALGO_CRYPTONIGHT,
  ALGO_CRYPTONIGHT_LITE,
  ALGO_SKEINCOIN,
  ALGO_SKEIN2,
  ALGO_QUBIT,
  ALGO_MYRIAD_GROESTL,
  ALGO_GROESTL,
  ALGO_DIDAMOND,
  ALGO_NEVACOIN,
  ALGO_VELTOR,
  ALGO_MAX
} algorithm_type_t;


extern const char *algorithm_type_str[];

extern void gen_hash(const unsigned char *data, unsigned int len, unsigned char *hash);

#ifdef USE_GPU
struct __clState;
#endif

struct _dev_blk_ctx;

#ifdef USE_GPU
struct _build_kernel_data;
#endif

struct cgpu_info;
struct work;

/* Describes the Scrypt parameters and hashing functions used to mine
 * a specific coin.
 */
typedef struct _algorithm_t {
  char     name[20]; /* Human-readable identifier */
  algorithm_type_t type; //algorithm type
  const char *kernelfile; /* alternate kernel file */
  uint32_t n;        /* N (CPU/Memory tradeoff parameter) */
  uint8_t  nfactor;  /* Factor of N above (n = 2^nfactor) */
  double   diff_multiplier1;
  double   diff_multiplier2;
  double   share_diff_multiplier;
  uint32_t xintensity_shift;
  uint32_t intensity_shift;
  uint32_t found_idx;
  unsigned long long   diff_numerator;
  uint32_t diff1targ;
  size_t n_extra_kernels;
  long rw_buffer_size;
#ifdef USE_GPU
  cl_command_queue_properties cq_properties;
#endif
  void(*regenhash)(struct work *);
  void(*calc_midstate)(struct work *);
  void(*prepare_work)(struct _dev_blk_ctx *, uint32_t *, uint32_t *);
#ifdef USE_GPU
  cl_int(*queue_kernel)(struct __clState *, struct _dev_blk_ctx *, cl_uint);
#endif
  void(*gen_hash)(const unsigned char *, unsigned int, unsigned char *);

#ifdef USE_GPU
  void(*set_compile_options)(struct _build_kernel_data *, struct cgpu_info *, struct _algorithm_t *);
#endif
} algorithm_t;

typedef struct _algorithm_settings_t
{
const char *name;
algorithm_type_t type;
const char *kernelfile;
double   diff_multiplier1;
double   diff_multiplier2;
double   share_diff_multiplier;
uint32_t xintensity_shift;
uint32_t intensity_shift;
uint32_t found_idx;
unsigned long long   diff_numerator;
uint32_t diff1targ;
size_t n_extra_kernels;
long rw_buffer_size;
#ifdef USE_GPU
cl_command_queue_properties cq_properties;
#endif
void     (*regenhash)(struct work *);
void     (*calc_midstate)(struct work *);
void     (*prepare_work)(struct _dev_blk_ctx *, uint32_t *, uint32_t *);
#ifdef USE_GPU
cl_int   (*queue_kernel)(struct __clState *, struct _dev_blk_ctx *, cl_uint);
#endif
void     (*gen_hash)(const unsigned char *, unsigned int, unsigned char *);
#ifdef USE_GPU
void     (*set_compile_options)(build_kernel_data *, struct cgpu_info *, algorithm_t *);
#endif
} algorithm_settings_t;

/* Set default parameters based on name. */
void set_algorithm(algorithm_t* algo, const char* name);

/* Set to specific N factor. */
void set_algorithm_nfactor(algorithm_t* algo, const uint8_t nfactor);

/* Compare two algorithm parameters */
bool cmp_algorithm(const algorithm_t* algo1, const algorithm_t* algo2);

int to_baikal_algorithm(algorithm_type_t type);

#endif /* ALGORITHM_H */
jr. member
Activity: 42
Merit: 25
I found quit a bit of the source for sgminer after writing the bin image(PiZero_GX10_171229_V1.1.img) to an SD card and looking at deleted files.  ...

Thanks for the info. Care to share what method you used to find the deleted files once the image was written to the SD card? Do the filenames seem to correlate with their contents?

I just used photorec to recovery any/all deleted files, then used astrogrep to do some searching.  The file names do not correlate.  Photorec just gives them a generic name.  We'll need more people searching for the other source files, my brain hurts.  ;o) 

Excellent discovery. Looks like this is pretty much all that is needed to build a custom sgminer for the Giants. Notice all the algorithms listed:

Code:
CRYPTONIGHT
CRYPTONIGHT_LITE
X11
QUARK
QUBIT
NIST
SKEINCOIN
SKEIN2
MYRIAD_GROESTL
GROESTL
X11GOST
VELTOR
BLAKECOIN
DECRED
VANILLA
BLAKE
SIA   
LBRY
PASCAL

Did you happen to find the file defining
Code:
ALGO_X11
ALGO_QUARK
ALGO_QUBIT
etc...
?

Of particular interest is this line:
Code:
msg.data[0] = (clk == 0) ? clk : ((clk / 10) % 20) + 2;
It looks like calling baikal_setoption() allows the clock to be set to an arbitrary value.

Does anyone have an opinion on which fork of sgminer is the best to start from? Stripping all the GPU/OpenCL related code should probably be done first, then this source can be added.


newbie
Activity: 50
Merit: 0
I found quit a bit of the source for sgminer after writing the bin image(PiZero_GX10_171229_V1.1.img) to an SD card and looking at deleted files.  ...

Thanks for the info. Care to share what method you used to find the deleted files once the image was written to the SD card? Do the filenames seem to correlate with their contents?

I just used photorec to recovery any/all deleted files, then used astrogrep to do some searching.  The file names do not correlate.  Photorec just gives them a generic name.  We'll need more people searching for the other source files, my brain hurts.  ;o) 

Can someone post the very first image file for the X10? I have v1.0 and v1.1, but was thinking I heard someone mention an earlier one.

Code:
/*
 * Copyright 2012-2013 Andrew Smith
 * Copyright 2012 Luke Dashjr
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option)
 * any later version.  See COPYING for more details.
 */

#include "config.h"

#include
#include
#include
#include
#include

#include "logging.h"
#include "miner.h"
#include "usbutils.h"
#include "util.h"
#include "config_parser.h"
#include "driver-baikal.h"
#include "compat.h"
#include "algorithm.h"

static int baikal_sendmsg(struct cgpu_info *baikal, baikal_msg *msg)
{
    int err;
    int i, pos = 0;
    int amount;
    uint8_t buf[512] = {0, };

    buf[pos++] = ':';
    buf[pos++] = msg->miner_id;
    buf[pos++] = msg->cmd;
    buf[pos++] = msg->param;
    buf[pos++] = msg->dest;

    for (i = 0; i < msg->len; i++, pos += 2) {
        buf[pos + 1] = msg->data[i];
    }

    buf[pos++] = '\r';
    buf[pos++] = '\n';

    err = usb_write(baikal, (char *)buf, pos, &amount, C_BAIKAL_SEND);
    if (err < 0) {
        applog(LOG_ERR, "baikal_sendmsg error(%d)\n", err);
        return (err);
    }

    return (amount);
}


static int baikal_readmsg(struct cgpu_info *baikal, baikal_msg *msg, int size)
{
    int err;
    int amount;
    int len, pos = 1;
    uint8_t buf[128] = {0, };

    err = usb_read_once(baikal, (char *)buf, size, &amount, C_BAIKAL_READ);
    if (err < 0 || amount < 7) {
        return (err);
    }

    if ((buf[0] != ':') || (buf[amount - 2] != '\r') || (buf[amount - 1] != '\n')) {
        return (-1);
    }

    msg->miner_id   = buf[pos++];
    msg->cmd        = buf[pos++];
    msg->param      = buf[pos++];
    msg->dest       = buf[pos++];

    for (len = 0; pos < amount - 2; len++, pos += 2) {
        msg->data[len] = buf[pos + 1];
    }

    msg->len = len;

    return (amount);
}

static void baikal_cleanup(struct cgpu_info *baikal)
{
    int i;
    struct baikal_info *info  = baikal->device_data;
    struct miner_info *miner;
    struct cgpu_info *tmp;
    struct thr_info *thr;

    for (i = 0; i < info->miner_count; i++) {
        miner  = &info->miners[i];
        thr = mining_thr[miner->thr_id];

        if (thr) {
            tmp = thr->cgpu;
            tmp->shutdown = true;
            tmp->deven = DEV_DISABLED;
            usb_nodev(tmp);
        }
    }
}


static void baikal_clearbuffer(struct cgpu_info *baikal)
{
    int err, retries = 0;
    baikal_msg msg;

    do {
        err = baikal_readmsg(baikal, &msg, 128);
        usb_buffer_clear(baikal);
        if (err < 0)
            break;
    }
    while (retries++ < 10);
}


static bool baikal_finalize(struct cgpu_info *baikal)
{
    usb_uninit(baikal);

    if (baikal->device_data) {
        free(baikal->device_data);
        baikal->device_data = NULL;
    }

    if (baikal->mutex) {
        free(baikal->mutex);
    }

    if (baikal->name) {
        free(baikal->name);
    }

    baikal = usb_free_cgpu(baikal);

    return (true);
}


static bool baikal_reset(struct cgpu_info *baikal)
{
    int amount;
    struct baikal_info *info    = baikal->device_data;
    baikal_msg msg = {0, };

    msg.miner_id    = 0x0;
    msg.cmd         = BAIKAL_RESET;
    msg.len         = 0;
    msg.dest        = 0;

    mutex_lock(baikal->mutex);

    amount = baikal_sendmsg(baikal, &msg);
    if (amount < 0) {
        mutex_unlock(baikal->mutex);
        return (false);
    }

    cgsleep_ms(400);

    amount = baikal_readmsg(baikal, &msg, 7);
    if (amount < 0) {
        mutex_unlock(baikal->mutex);
        return (false);
    }

    info->miner_count = msg.param;

    mutex_unlock(baikal->mutex);

    return (true);
}


static bool baikal_getinfo(struct cgpu_info *baikal)
{
    int amount;
    uint16_t sign;
    baikal_msg msg = {0, };
    struct baikal_info *info    = baikal->device_data;
    struct miner_info *miner  = &info->miners[baikal->miner_id];

    msg.miner_id    = baikal->miner_id;
    msg.cmd         = BAIKAL_GET_INFO;
    msg.dest        = 0;
    msg.len         = 0;

    mutex_lock(baikal->mutex);

    amount = baikal_sendmsg(baikal, &msg);
    if (amount < 0) {
        mutex_unlock(baikal->mutex);
        return (false);
    }

    // TODO :
    cgsleep_ms(200);

    amount = baikal_readmsg(baikal, &msg, 21);
    if (amount < 0) {
        mutex_unlock(baikal->mutex);
        return (false);
    }

    mutex_unlock(baikal->mutex);

    miner->fw_ver       = msg.data[0];
    miner->hw_ver       = msg.data[1];
    miner->unit_count   = msg.data[2];
    miner->clock        = msg.data[3] << 1;
    miner->asic_count   = msg.data[4];
    miner->asic_ver     = msg.data[5] << 8 | msg.data[6];
    miner->working_diff = 0.01;
    miner->working      = true;
    miner->overheated   = false;

    return (true);
}


static bool baikal_setoption(struct cgpu_info *baikal, uint16_t clk, uint8_t mode, uint8_t temp, uint8_t fanspeed)
{
    int amount;
    baikal_msg msg = {0, };

    msg.miner_id    = baikal->miner_id;
    msg.cmd         = BAIKAL_SET_OPTION;
    msg.data[0] = (clk == 0) ? clk : ((clk / 10) % 20) + 2;
    msg.data[1] = mode;
    msg.data[2] = temp;
    msg.data[3] = fanspeed;
    msg.dest        = 0;
    msg.len         = 4;

    mutex_lock(baikal->mutex);

    amount = baikal_sendmsg(baikal, &msg);
    if (amount < 0) {
        mutex_unlock(baikal->mutex);
        return (false);
    }

    amount = baikal_readmsg(baikal, &msg, 7);
    if (amount < 0) {
        mutex_unlock(baikal->mutex);
        return (false);
    }

    mutex_unlock(baikal->mutex);

    return (true);
}


static bool baikal_setidle(struct cgpu_info *baikal)
{
    int amount;
    struct baikal_info *info    = baikal->device_data;
    baikal_msg msg = {0, };

    msg.miner_id    = 0x0;
    msg.cmd         = BAIKAL_SET_IDLE;
    msg.len         = 0;
    msg.dest        = 0;

    mutex_lock(baikal->mutex);

    amount = baikal_sendmsg(baikal, &msg);
    mutex_unlock(baikal->mutex);

    return (true);
}


static bool baikal_detect_remains(struct cgpu_info *baikal)
{
    int index;
    char devpath[32];
    struct baikal_info *info = baikal->device_data;
    struct miner_info *miner;

    for (index = 1; index < info->miner_count; index++) {

        struct cgpu_info *tmp = usb_copy_cgpu(baikal);

        sprintf(devpath, "%d:%d:%d",
                (int)(baikal->usbinfo.bus_number),
                (int)(baikal->usbinfo.device_address),
                index);

        tmp->device_path        = strdup(devpath);
        tmp->usbinfo.usbstat    = USB_NOSTAT;
        tmp->miner_id           = index;
        tmp->device_data        = baikal->device_data;
        tmp->mutex              = baikal->mutex;
        tmp->algorithm          = baikal->algorithm;
        tmp->threads            = 1;

        miner = &info->miners[tmp->miner_id];
        cgtimer_time(&miner->start_time);
        if (baikal_getinfo(tmp) == false) {
            tmp = usb_free_cgpu(tmp);
            continue;
        }

        if (baikal_setoption(tmp, info->clock, to_baikal_algorithm(baikal->algorithm.type), info->cutofftemp, info->fanspeed) != true) {
            tmp = usb_free_cgpu(tmp);
            continue;
        }

        if (!add_cgpu(tmp)) {
            tmp = usb_free_cgpu(tmp);
            continue;
        }

        update_usb_stats(tmp);
    }

    return (true);
}


static struct cgpu_info* baikal_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
{
    struct cgpu_info *baikal;
    struct baikal_info *info;
    struct miner_info *miner;
    int clock           = BAIKAL_CLK_DEF;
    int cutofftemp      = BAIKAL_CUTOFF_TEMP;
    int fanspeed        = BAIKAL_FANSPEED_DEF;
    int recovertemp     = BAIKAL_RECOVER_TEMP;

#if BAIKAL_ENABLE_SETCLK
    if (opt_baikal_options != NULL) {
        sscanf(opt_baikal_options, "%d:%d:%d", &clock, &recovertemp, &cutofftemp);
        if (clock < BAIKAL_CLK_MIN) {
            clock = BAIKAL_CLK_MIN;
        }
        if (clock > BAIKAL_CLK_MAX) {
            clock = BAIKAL_CLK_MAX;
        }
    }
#else
    if (opt_baikal_options != NULL) {
        sscanf(opt_baikal_options, "%d:%d", &recovertemp, &cutofftemp);
    }
#endif

    if (opt_baikal_fan != NULL) {
        sscanf(opt_baikal_fan, "%d", &fanspeed);
        if (fanspeed > BAIKAL_FANSPEED_MAX) {
            fanspeed = BAIKAL_FANSPEED_DEF;
        }
    }

    baikal = usb_alloc_cgpu(&baikalu_drv, 1);
    baikal->mutex = calloc(1, sizeof(*(baikal->mutex)));
    mutex_init(baikal->mutex);

    info = (struct baikal_info *)calloc(1, sizeof(struct baikal_info));
    info->clock         = clock;
    info->cutofftemp    = (uint8_t)cutofftemp;
    info->fanspeed      = (uint8_t)fanspeed;
    info->recovertemp   = (uint8_t)recovertemp;

    baikal->device_data = info;
    baikal->name        = strdup("BKLU");
    baikal->miner_id    = 0;
    baikal->algorithm   = default_profile.algorithm;

    miner = &info->miners[baikal->miner_id];
    cgtimer_time(&miner->start_time);


    if (!usb_init(baikal, dev, found)) {
        goto out;
    }

    baikal_clearbuffer(baikal);

    if (baikal_reset(baikal) != true) {
        goto out;
    }

    /* TODO : Remove it */
    cgsleep_ms(200);

    if (baikal_getinfo(baikal) != true) {
        goto out;
    }

    if (baikal_setoption(baikal, clock, to_baikal_algorithm(default_profile.algorithm.type), cutofftemp, fanspeed) != true) {
        goto out;
    }

    if (!add_cgpu(baikal)) {
        goto out;
    }

    update_usb_stats(baikal);

    baikal_detect_remains(baikal);

    return (baikal);

out:
    baikal_finalize(baikal);
    return (NULL);
}


static void baikal_detect(void)
{
    usb_detect(&baikalu_drv, baikal_detect_one);
}


static void baikal_get_statline_before(char *buf, size_t bufsiz, struct cgpu_info *baikal)
{
    struct baikal_info *info    = baikal->device_data;
    struct miner_info *miner  = &info->miners[baikal->miner_id];

    tailsprintf(buf, bufsiz, "%s%dC %3uMHz [ASICS #%d] | ", (baikal->temp < 10) ? " " : "", (int)miner->temp, miner->clock, miner->asic_count);
}


static struct api_data* baikal_api_stats(struct cgpu_info *cgpu)
{
    struct baikal_info *info    = cgpu->device_data;
    struct miner_info *miner    = &info->miners[cgpu->miner_id];
    struct thr_info *thr = mining_thr[miner->thr_id];
    struct api_data *root = NULL;

    root = api_add_int(root, "Chip Count", (int *)&miner->asic_count, false);
    root = api_add_int(root, "Clock", (int *)&miner->clock, false);
    root = api_add_int(root, "HWV", (int *)&miner->hw_ver, false);
    root = api_add_int(root, "FWV", (int *)&miner->fw_ver, false);
    root = api_add_string(root, "Algo", (char *)algorithm_type_str[thr->cgpu->algorithm.type], false);

    return (root);
}


static void baikal_identify(struct cgpu_info *baikal)
{
    int amount;
    baikal_msg msg = {0, };

    msg.miner_id    = baikal->miner_id;
    msg.cmd         = BAIKAL_SET_ID;
    msg.dest        = 0;
    msg.len         = 0;

    mutex_lock(baikal->mutex);

    amount = baikal_sendmsg(baikal, &msg);
    if (amount < 0) {
        mutex_unlock(baikal->mutex);
        return;
    }

    amount = baikal_readmsg(baikal, &msg, 7);
    if (amount < 0) {
        mutex_unlock(baikal->mutex);
        return;
    }

    mutex_unlock(baikal->mutex);
}


static bool baikal_prepare(struct thr_info *thr)
{
    struct cgpu_info *baikal    = thr->cgpu;
    struct baikal_info *info    = baikal->device_data;

    cglock_init(&(info->pool.data_lock));

    return (true);
}


static void baikal_checknonce(struct cgpu_info *baikal, baikal_msg *msg)
{
    struct baikal_info *info = baikal->device_data;
    struct miner_info *miner = &info->miners[msg->miner_id];
    uint8_t work_idx, chip_id;
    uint32_t nonce;

    chip_id     = msg->data[4];
    work_idx    = msg->data[5];
    nonce       = *((uint32_t *)msg->data);

    if (info->works[work_idx] == NULL) {
          return;
    }

    /* check algorithm */
    if (info->works[work_idx]->pool->algorithm.type != baikal->algorithm.type) {
        return;
    }

    if (submit_nonce(mining_thr[miner->thr_id], info->works[work_idx], nonce) == true) {
        miner->nonce++;
    }
    else {
        miner->error++;
    }
}


static bool baikal_send_work(struct cgpu_info *baikal, int miner_id)
{
    struct baikal_info *info = baikal->device_data;
    struct miner_info *miner = &info->miners[miner_id];
    struct thr_info *thr = mining_thr[miner->thr_id];
    struct work *work;
    uint32_t target;
    baikal_msg msg;
    uint8_t algo;
    uint32_t * mdata,*wdata;

    /* Do not send */
    if (miner->overheated == true) {
        return (true);
    }
   
mutex_lock(baikal->mutex);
    if (info->works[info->work_idx] == NULL) {
        work = get_work(thr, miner->thr_id);                             
        info->works[info->work_idx] = work;

#if 0   /* TODO : Performance Check */
        if (thr->work_restart) {                   
            free_work(info->works[info->work_idx]);
            info->works[info->work_idx] = NULL;   
            applog(LOG_ERR, "work restart\n");     
        mutex_unlock(baikal->mutex);           
            return true;                           
        }                                         
#endif
    }
   
    if (work->pool->algorithm.type != thr->cgpu->algorithm.type) {
        thr->cgpu->algorithm.type = work->pool->algorithm.type;
    }

    work->device_diff = MAX(miner->working_diff, work->work_difficulty);
    //work->device_diff = MIN(miner->working_diff, work->work_difficulty);
    set_target(work->device_target, work->device_diff, work->pool->algorithm.diff_multiplier2, work->thr_id);

    memset(msg.data, 0x0, 512);
    msg.data[0] = to_baikal_algorithm(thr->cgpu->algorithm.type);
    msg.data[1] = miner_id;
    memcpy(&msg.data[2], &work->device_target[24], 8);
    if (*((uint32_t *)&msg.data[6]) != 0x0) { // TripleS
        memset(&msg.data[2], 0xFF, 4);
    }

    switch (baikal->algorithm.type) {
    case ALGO_BLAKECOIN:        // blake256r8
    case ALGO_VANILLA:
        if (work->pool->algorithm.calc_midstate) {   // use midstate
            msg.data[0] += 1;

            memcpy(&msg.data[10], work->midstate, 32);
            memcpy(&msg.data[42], &work->data[64], 16);
            be32enc_vect((uint32_t *)&msg.data[42], (const uint32_t *)&msg.data[42], 4);
            *((uint32_t *)&msg.data[58]) = 0x00000080;
            *((uint32_t *)&msg.data[94]) = 0x01000000;
            *((uint32_t *)&msg.data[102]) = 0x80020000;
            msg.len = 106;
        }
        else {
            memcpy(&msg.data[10], work->data, 80);
            be32enc_vect((uint32_t *)&msg.data[10], (const uint32_t *)&msg.data[10], 20);
            msg.len = 90;
        }
        break;

    case ALGO_DECRED:           // blake256r14
        if (work->pool->algorithm.calc_midstate) {   // use midstate
            msg.data[0] += 1;

            memcpy(&msg.data[10], work->midstate, 32);
            memcpy(&msg.data[42], &work->data[128], 52);
            *((uint32_t *)&msg.data[94]) = 0x01000080UL;
            *((uint32_t *)&msg.data[98]) = 0x00000000UL;
            *((uint32_t *)&msg.data[102]) = 0xa0050000UL;
            msg.len = 106;
        }
        else {
            memcpy(&msg.data[10], work->data, 180);
            msg.len = 190;
        }
        break;
    case ALGO_SIA:              // blake2b
        memcpy(&msg.data[10], work->data, 80);
        be32enc_vect((uint32_t *)&msg.data[10], (const uint32_t *)&msg.data[10], 20);
        msg.len = 90;
        break;

    case ALGO_LBRY:             // lbry-all
        memcpy(&msg.data[10], work->data, 112);
        be32enc_vect((uint32_t *)&msg.data[10], (const uint32_t *)&msg.data[10], 27);
        msg.len = 122;
        break;

    case ALGO_PASCAL:           // lbry-sha
        memcpy(&msg.data[10], work->data, 200);
        msg.len = 210;
        break;

    case ALGO_X11:
    case ALGO_X11GOST:
    case ALGO_SKEINCOIN:
    case ALGO_MYRIAD_GROESTL:
    case ALGO_QUARK:
    case ALGO_QUBIT:
    case ALGO_GROESTL:
    case ALGO_SKEIN2:
    case ALGO_NIST:
    case ALGO_CRYPTONIGHT:
    case ALGO_CRYPTONIGHT_LITE:
    case ALGO_BLAKE:
    case ALGO_VELTOR:
    default:
        memcpy(&msg.data[10], work->data, 80);
        msg.len = 90;
        break;
    }
    msg.miner_id    = miner_id;
    msg.cmd         = BAIKAL_SEND_WORK;
    msg.param       = info->work_idx;
    msg.dest        = 0;

    //mutex_lock(baikal->mutex);

    if (baikal_sendmsg(baikal, &msg) < 0) {
        applog(LOG_ERR, "baikal_send_work : sendmsg error[%d]", miner_id);
        mutex_unlock(baikal->mutex);
        return (false);
    }

    if (baikal_readmsg(baikal, &msg, 7) < 0) {
        applog(LOG_ERR, "baikal_send_work : readmsg error[%d]", miner_id);
        mutex_unlock(baikal->mutex);
        return (false);
    }

    /* update clock */
    miner->clock = msg.param << 1;

    info->work_idx++;
    if (info->work_idx >= BAIKAL_WORK_FIFO) {
        info->work_idx = 0;
    }

    if (info->works[info->work_idx] != NULL) {
        free_work(info->works[info->work_idx]);
        info->works[info->work_idx] = NULL;
    }
       
    cgtimer_time(&miner->start_time);
    mutex_unlock(baikal->mutex);

    return (true);
}


static bool baikal_process_result(struct cgpu_info *baikal)
{
    struct baikal_info *info = baikal->device_data;
    struct miner_info *miner;
    baikal_msg msg = {0, };
    int i;

    for (i = 0; i < info->miner_count; i++) {
        miner = &info->miners[i];
        if (miner->working == true) {           
            msg.miner_id    = i;
            msg.cmd         = BAIKAL_GET_RESULT;
            msg.dest        = 0;
            msg.len         = 0;

            mutex_lock(baikal->mutex);
            if (baikal_sendmsg(baikal, &msg) < 0) {
                applog(LOG_ERR, "baikal_process_result : sendmsg error");
                mutex_unlock(baikal->mutex);
                return (false);
            }

            if (baikal_readmsg(baikal, &msg, 23) < 0) {
                applog(LOG_ERR, "baikal_process_result : readmsg error miner_id = %d", i);
                mutex_unlock(baikal->mutex);
                return (false);
            }
            mutex_unlock(baikal->mutex);
           
            miner->temp = msg.data[6];

            if (msg.param & 0x01) {
                baikal_checknonce(baikal, &msg);
            }

            if (msg.param & 0x02) {
                baikal_send_work(baikal, i);   
            }

            if (msg.param & 0x04) {
                baikal_cleanup(baikal);  /* new miner detect*/             
            }             

            if (miner->temp > info->cutofftemp) {
                miner->overheated = true;
            }
            else if (miner->temp < info->recovertemp) {
                miner->overheated = false;
            }
            cgsleep_ms(1);
        }       
    }

    return (true);
}

static int64_t baikal_hash_done(struct cgpu_info *baikal, struct miner_info *miner, int elpased)
{
    int64_t hash_done = 0;

    switch(baikal->algorithm.type) {       
    case ALGO_CRYPTONIGHT:
        hash_done = miner->clock * miner->asic_count * elpased / 1776;
        break;
    case ALGO_CRYPTONIGHT_LITE:
        hash_done = miner->clock * miner->asic_count * elpased / 888;
        break;
    case ALGO_X11:
    case ALGO_QUARK:
    case ALGO_QUBIT:
    case ALGO_NIST: 
    case ALGO_SKEINCOIN:
    case ALGO_SKEIN2:
    case ALGO_MYRIAD_GROESTL:
    case ALGO_GROESTL:
        hash_done = miner->clock * miner->asic_count * elpased * 128;
        break;
    case ALGO_X11GOST:
    case ALGO_VELTOR:
        hash_done = miner->clock * miner->asic_count * elpased * 18;
        break;
   
    case ALGO_BLAKECOIN:
    case ALGO_DECRED:
    case ALGO_VANILLA:
    case ALGO_BLAKE:
        hash_done = miner->clock * miner->asic_count * elpased * 2048;
        break;

    case ALGO_SIA:   
        hash_done = miner->clock * miner->asic_count * elpased * 1024;
        break;   
    case ALGO_LBRY:
    case ALGO_PASCAL:
        hash_done = miner->clock * miner->asic_count * elpased * 512;
        break;
    }

    return hash_done;
}


static int64_t baikal_scanhash(struct thr_info *thr)
{
    struct cgpu_info *baikal = thr->cgpu;
    struct baikal_info *info = baikal->device_data;
    struct miner_info *miner = &info->miners[baikal->miner_id];
    cgtimer_t now;
    int elapsed, i;

    if (baikal->usbinfo.nodev) {
        return (-1);
    }

    if (baikal->miner_id == 0) {
        if (baikal_process_result(baikal) != true) {
            baikal_cleanup(baikal);
            return (-1);
        }
    }
    else {
        cgsleep_ms(100);
    }

    baikal->temp = miner->temp;

    cgtimer_time(&now);
    elapsed = cgtimer_to_ms(&now) - cgtimer_to_ms(&miner->start_time);
    miner->start_time = now;

    return (baikal_hash_done(baikal, miner, elapsed));   
}


static void baikal_update_work(struct cgpu_info *baikal)
{
    int i, j;
    struct timeval now;
    struct baikal_info *info = baikal->device_data;   
    //struct thr_info *thr = mining_thr[miner->thr_id];

    /* TODO : check when bk1791 160 chips used */
    if (baikal->miner_id == 0) {
        for (i = 0; i < info->miner_count; i++) {
            struct miner_info *miner = &info->miners[i];
            if (miner->working == true) {
                for (j = 0; j < miner->unit_count; j++) {
                    if (baikal_send_work(baikal, i) != true) {
                        baikal_cleanup(baikal);
                    }
                }
            }
        }
    }
}


static bool baikal_init(struct thr_info *thr)
{
    struct cgpu_info *baikal    = thr->cgpu;
    struct baikal_info *info    = baikal->device_data;
    struct miner_info *miner    = &info->miners[baikal->miner_id];

    //memset(miner, 0, sizeof(struct miner_info));
    miner->thr_id               = thr->id;
    cgtimer_time(&miner->start_time);
    return (true);
}


static void baikal_shutdown(struct thr_info *thr)
{
    struct cgpu_info *baikal = thr->cgpu;
    struct baikal_info *info = baikal->device_data;

    if (baikal->miner_id == 0) {
        baikal_setidle(baikal);
    }

    baikal->shutdown = true;
}


struct device_drv baikalu_drv = {
    .drv_id = DRIVER_baikalu,
    .dname = "Baikal",
    .name = "BKLU",
    .drv_detect = baikal_detect,
    .get_statline_before = baikal_get_statline_before,
    .get_api_stats = baikal_api_stats,
    .identify_device = baikal_identify,
    .thread_prepare = baikal_prepare,
    .thread_init = baikal_init,
    .hash_work              = hash_driver_work,
    .update_work            = baikal_update_work,
    //.flush_work             = baikal_update_work,
    .scanwork = baikal_scanhash,
    .thread_shutdown        = baikal_shutdown,
};
Pages:
Jump to: