Bitcoin Forum
May 06, 2024, 07:31:22 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Warning: One or more bitcointalk.org users have reported that they strongly believe that the creator of this topic is a scammer. (Login to see the detailed trust ratings.) While the bitcointalk.org administration does not verify such claims, you should proceed with extreme caution.
Pages: « 1 2 3 4 5 6 7 8 [9] 10 11 12 13 14 15 16 »  All
  Print  
Author Topic: Baikal X10 ⚡OVERCLOCK⚡ Claim reward 0.2 BTC for TUTORIAL HOW TO :)⚡⚡⚡⚡  (Read 22701 times)
ismurdegus
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
March 04, 2018, 08:26:20 AM
 #161

I have some high resolution picture

https://imgur.com/a/MeXWH
1714980682
Hero Member
*
Offline Offline

Posts: 1714980682

View Profile Personal Message (Offline)

Ignore
1714980682
Reply with quote  #2

1714980682
Report to moderator
If you want to be a moderator, report many posts with accuracy. You will be noticed.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714980682
Hero Member
*
Offline Offline

Posts: 1714980682

View Profile Personal Message (Offline)

Ignore
1714980682
Reply with quote  #2

1714980682
Report to moderator
CNoteFan
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
March 06, 2018, 03:38:29 AM
 #162

Did anybody manage to restore the driver-baikalu.c source file? It would help a lot to understand how it is working with sgminer.

I wish Baikal would release the sgminer source code. 

Anyone know if it falls under the same licensing as cgminer?
https://bitcointalk.org/index.php?topic=2694602.msg28367617#msg28367617
dmanukr
Jr. Member
*
Offline Offline

Activity: 75
Merit: 1


View Profile
March 06, 2018, 04:16:06 AM
 #163

Did anybody manage to restore the driver-baikalu.c source file? It would help a lot to understand how it is working with sgminer.

I wish Baikal would release the sgminer source code. 

Anyone know if it falls under the same licensing as cgminer?
https://bitcointalk.org/index.php?topic=2694602.msg28367617#msg28367617

Don't count on them doing that.. they're using a version sgminer/5.6.3-l which must be a proprietary fork

Is it not possible to get it from the sd card?  That should be where it resides? 
adra12
Newbie
*
Offline Offline

Activity: 43
Merit: 0


View Profile
March 07, 2018, 06:00:17 PM
 #164

I wish Baikal would release the sgminer source code. 

Anyone know if it falls under the same licensing as cgminer?
https://bitcointalk.org/index.php?topic=2694602.msg28367617#msg28367617

In that case the initiation was started at bitcointalk, so they could end it very quickly if the source was not released.

You can check the original sgminer homepage:
https://github.com/sgminer-dev/sgminer
License: GPLv3. See COPYING for details.

Baikal just doesn't give a shit about it. Unfortunately no one can force them to release the source code, but they would need to do so.
adra12
Newbie
*
Offline Offline

Activity: 43
Merit: 0


View Profile
March 12, 2018, 04:04:14 PM
 #165

I would like to share the bash history of an X10 machine. I have commented the commands, so you should be able to understand it even if you are not familiar with Linux commands.

If you notice a mistake or you have a suggestion, then please let me know. I can still edit the file.

https://pastebin.com/qit9sA9M

dibidi
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
March 19, 2018, 11:35:01 PM
 #166

I would like to share the bash history of an X10 machine. I have commented the commands, so you should be able to understand it even if you are not familiar with Linux commands.

If you notice a mistake or you have a suggestion, then please let me know. I can still edit the file.

https://pastebin.com/qit9sA9M



Good morning.
Can I apply it in the same way as in url?
Does it work properly on x10?
Is there a command to add SGMINER Options in x10 miner setting?
I would appreciate your reply.
Thank you.
adra12
Newbie
*
Offline Offline

Activity: 43
Merit: 0


View Profile
March 20, 2018, 09:24:48 AM
 #167


Good morning.
Can I apply it in the same way as in url?
Does it work properly on x10?
Is there a command to add SGMINER Options in x10 miner setting?
I would appreciate your reply.
Thank you.

These commands are just for reference if you intend to reverse-engineer their work step by step.

Unless you have the source code of sgminer and the firmware, it is pointless to issue the same commands as you don't have the same files.
dmanukr
Jr. Member
*
Offline Offline

Activity: 75
Merit: 1


View Profile
March 21, 2018, 01:37:32 AM
 #168

...
These commands are just for reference if you intend to reverse-engineer their work step by step.

Unless you have the source code of sgminer and the firmware, it is pointless to issue the same commands as you don't have the same files.

Isn't the firmware in the flashcard that is used?  The sgminer code may also be in that since it would be impractical to embed permanently into a rom, don't you think?  Anyone have any experience with this?
CNoteFan
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
March 21, 2018, 02:30:45 AM
 #169

Has anyone tried to "undelete" from the SD after writing the image to it?  Perhaps the source is still there, just "deleted?"
adra12
Newbie
*
Offline Offline

Activity: 43
Merit: 0


View Profile
March 21, 2018, 10:21:51 AM
 #170

Isn't the firmware in the flashcard that is used?  The sgminer code may also be in that since it would be impractical to embed permanently into a rom, don't you think?  Anyone have any experience with this?

By the time you get your miner the firmware is flashed to the microcontroller. You can still obtain it, but it is as useful as the compiled sgminer. You can only edit it with a Hex editor, but development is not possible without the source code.
Finsterkamm
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
March 21, 2018, 11:43:54 AM
 #171

@CNoteFan:
It's hardly ever possible. Most likely developers are sitting on PC doing cross-development for OrangePi.
After that they release image for flashing there only binaries residues. No even traces of source code.
CNoteFan
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
March 21, 2018, 03:05:40 PM
 #172

@CNoteFan:
It's hardly ever possible. Most likely developers are sitting on PC doing cross-development for OrangePi.
After that they release image for flashing there only binaries residues. No even traces of source code.



From the link above, some of the bash history from @adra12:

Code:
// Open the following file with VIM text editor for editing
vi driver-baikalu.c
 
// View sgminer CLI
sudo screen -r
 
// List content
ls
 
// List content
ls
 
// Delete this folder
rm -rf sgminer/
adra12
Newbie
*
Offline Offline

Activity: 43
Merit: 0


View Profile
March 21, 2018, 04:13:44 PM
 #173


From the link above, some of the bash history from @adra12:

Code:
// Open the following file with VIM text editor for editing
vi driver-baikalu.c
 
// View sgminer CLI
sudo screen -r
 
// List content
ls
 
// List content
ls
 
// Delete this folder
rm -rf sgminer/

That means that sgminer was compiled on the machine, and they deleted the folder with the source code. Still there are no traces of the source code of the firmware. And both of them are needed.
CNoteFan
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
March 21, 2018, 07:35:45 PM
 #174


From the link above, some of the bash history from @adra12:

Code:
// Open the following file with VIM text editor for editing
vi driver-baikalu.c
 
// View sgminer CLI
sudo screen -r
 
// List content
ls
 
// List content
ls
 
// Delete this folder
rm -rf sgminer/

That means that sgminer was compiled on the machine, and they deleted the folder with the source code. Still there are no traces of the source code of the firmware. And both of them are needed.

For the meantime, I'd be happy with just some of the source!
dibidi
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
March 22, 2018, 09:03:50 AM
 #175


From the link above, some of the bash history from @adra12:

Code:
// Open the following file with VIM text editor for editing
vi driver-baikalu.c
 
// View sgminer CLI
sudo screen -r
 
// List content
ls
 
// List content
ls
 
// Delete this folder
rm -rf sgminer/

That means that sgminer was compiled on the machine, and they deleted the folder with the source code. Still there are no traces of the source code of the firmware. And both of them are needed.

I have a question. adra12
If you checked the firmware source code, did you check all three X10 firmware?
I know that there are three firmware versions in October, November, and December.
I have only the firmware in November, December. There is no firmware in October.
All three firmware did not have sgminer source code?
adra12
Newbie
*
Offline Offline

Activity: 43
Merit: 0


View Profile
March 22, 2018, 10:03:27 AM
 #176

I have a question. adra12
If you checked the firmware source code, did you check all three X10 firmware?
I know that there are three firmware versions in October, November, and December.
I have only the firmware in November, December. There is no firmware in October.
All three firmware did not have sgminer source code?

I only have the following image file:
PiZero_GX10_171229_V1.1.img

And the microcontroller firmware I have is exactly the same like this one:
http://leteckaposta.cz/473537086

It would be nice to have the previous image, sgminer, firmware files for comparison.
CNoteFan
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
March 23, 2018, 12:13:45 AM
 #177

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. 
Not sure if this has already been discovered.  Not sure if there's enough to actually compile a working version.

Here's some of what I found:

Code:
#ifndef __DEVICE_BAIKAL_H__
#define __DEVICE_BAIKAL_H__

#include "miner.h"

#define BAIKAL_MAXMINERS     (16)
#define BAIKAL_MAXASICS         (200)
#define BAIKAL_WORK_FIFO        (255)

#define BAIKAL_CLK_MIN  (150)
#define BAIKAL_CLK_DEF  (300)
#define BAIKAL_CLK_MAX     (300)
#define BAIKAL_CUTOFF_TEMP      (85)
#define BAIKAL_FANSPEED_DEF     (100)
#define BAIKAL_FANSPEED_MAX     (100)
#define BAIKAL_RECOVER_TEMP     (60)

#define BAIKAL_RESET     (0x01)
#define BAIKAL_GET_INFO         (0x02)
#define BAIKAL_SET_OPTION     (0x03)
#define BAIKAL_SEND_WORK     (0x04)
#define BAIKAL_GET_RESULT     (0x05)
#define BAIKAL_SET_ID     (0x06)
#define BAIKAL_SET_IDLE     (0x07)

#define BAIKAL_MINER_TYPE_NONE  (0x00)
#define BAIKAL_MINER_TYPE_MINI  (0x01)
#define BAIKAL_MINER_TYPE_CUBE  (0x02)

#define BAIKAL_ENABLE_SETCLK    (0)

struct asic_info {
    uint32_t nonce;
    uint32_t error;
};

struct miner_info {
    int     thr_id;
    int     asic_count; 
    int     unit_count;
int temp; 
    int     clock;
    bool    working;
    bool    overheated;
    uint8_t fw_ver;
    uint8_t hw_ver;
    uint8_t asic_ver;   
    uint32_t nonce;
    uint32_t error;   
    double working_diff;   
    struct asic_info asics[BAIKAL_MAXASICS];
    cgtimer_t start_time;
};


struct baikal_info {
    struct pool pool;
    int miner_count;
    int clock;
    uint8_t cutofftemp;
    uint8_t fanspeed; // percent
    uint8_t recovertemp;
pthread_t *process_thr;
    uint8_t work_idx;
    struct work *works[BAIKAL_WORK_FIFO];
    struct miner_info miners[BAIKAL_MAXMINERS];

    uint8_t miner_type;
};

typedef struct {
    uint8_t     miner_id;
    uint8_t     cmd;
    uint8_t     param;
    uint8_t     dest;
    uint8_t     data[512];
    uint32_t    len;
} baikal_msg;


#endif /* __DEVICE_BAIKAL_H__ */
CNoteFan
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
March 23, 2018, 01:00:58 AM
 #178

Looks like they decided to leave out the part that allows us to adjust the clock frequency...
Code:
...
#define BAIKAL_ENABLE_SETCLK    (0)
...
Code:
...
#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);
...
tboy32c
Jr. Member
*
Offline Offline

Activity: 42
Merit: 25


View Profile
March 23, 2018, 12:31:07 PM
 #179

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?
CNoteFan
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
March 23, 2018, 01:30:22 PM
 #180

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 <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#include <pthread.h>

#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: « 1 2 3 4 5 6 7 8 [9] 10 11 12 13 14 15 16 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!