Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kdimg support. #1

Merged
merged 15 commits into from
Jan 17, 2025
102 changes: 50 additions & 52 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
tags: [ "v*" ]
branches:
- main
- dev
- feat/**

jobs:
Expand Down Expand Up @@ -45,37 +46,28 @@ jobs:
ls -alh build

- name: Compress artifacts
if: github.ref != 'refs/heads/dev'
run: |
cd ${{ github.workspace }}/build/dist
zip -r K230BurningTool-Windows-${{ env.REVISION }}.zip *

- uses: actions/upload-artifact@v4
if: github.ref != 'refs/heads/dev'
with:
name: "K230BurningTool-Windows-${{ env.REVISION }}"
path: ${{ github.workspace }}/build/dist/K230BurningTool-Windows-${{ env.REVISION }}.zip
if-no-files-found: error
compression-level: 0

- name: Build AvalonNano3 for Windows
if: github.ref != 'refs/heads/dev'
run: |
rm -rf ${{ github.workspace }}/build && mkdir -p ${{ github.workspace }}/build
docker run --name qt6 -v "${PWD}:/home/user/project:ro" stateoftheartio/qt6:6.7-mingw-aqt /bin/bash -c 'export CI=1; qt-cmake ./project -G Ninja -B ./build -DBUILD_FOR_AVALON_NANO3=1; cmake --build ./build; cmake --install ./build; ls -alh ./build'
docker cp qt6:/home/user/build/dist ${{ github.workspace }}/build
docker rm qt6
ls -alh build

- name: Compress AvalonNano3 artifacts
run: |
cd ${{ github.workspace }}/build/dist
zip -r K230BurningTool-AvalonNano3-Windows-${{ env.REVISION }}.zip *

- uses: actions/upload-artifact@v4
with:
name: "K230BurningTool-AvalonNano3-Windows-${{ env.REVISION }}"
path: ${{ github.workspace }}/build/dist/K230BurningTool-AvalonNano3-Windows-${{ env.REVISION }}.zip
if-no-files-found: error
compression-level: 0

build-for-linux:
runs-on: ubuntu-latest
concurrency:
Expand Down Expand Up @@ -121,37 +113,16 @@ jobs:
ls -alh build

- uses: actions/upload-artifact@v4
if: github.ref != 'refs/heads/dev'
with:
name: "K230BurningTool-Linux-x86_64-${{ env.REVISION }}"
path: ${{ github.workspace }}/build/K230BurningTool-Linux-x86_64-${{ env.REVISION }}.AppImage
if-no-files-found: error
compression-level: 0

- name: Build AvalonNano3 for Linux
run: |
rm -rf ${{ github.workspace }}/build && mkdir -p ${{ github.workspace }}/build
docker run --name qt6 --privileged -v /dev/fuse:/dev/fuse -v "${PWD}:/home/user/project:ro" stateoftheartio/qt6:6.6-gcc-aqt /bin/bash -c '
export CI=1
sudo apt update
sudo apt install -y libgl-dev libvulkan-dev libssl-dev libudev-dev fuse file
sudo curl -L https://github.com/probonopd/linuxdeployqt/releases/download/continuous/linuxdeployqt-continuous-x86_64.AppImage -o /usr/bin/linuxdeployqt
sudo chmod +x /usr/bin/linuxdeployqt
qt-cmake ./project -G Ninja -B ./build -DBUILD_FOR_AVALON_NANO3=1; cmake --build ./build; cmake --install ./build; ls -alh ./build
'
docker cp qt6:/home/user/build/K230BurningTool-x86_64.AppImage ${{ github.workspace }}/build
docker rm qt6
mv ${{ github.workspace }}/build/K230BurningTool-x86_64.AppImage ${{ github.workspace }}/build/K230BurningTool-AvalonNano3-Linux-x86_64-${{ env.REVISION }}.AppImage
ls -alh build

- uses: actions/upload-artifact@v4
with:
name: "K230BurningTool-AvalonNano3-Linux-x86_64-${{ env.REVISION }}"
path: ${{ github.workspace }}/build/K230BurningTool-AvalonNano3-Linux-x86_64-${{ env.REVISION }}.AppImage
if-no-files-found: error
compression-level: 0

build-for-macos:
runs-on: macos-13
if: github.ref != 'refs/heads/dev'
concurrency:
group: ${{ github.repository }}-${{ github.workflow }}-macOS
cancel-in-progress: true
Expand Down Expand Up @@ -207,23 +178,50 @@ jobs:
if-no-files-found: error
compression-level: 0

- name: Build AvalonNano3 for macOS
run: |
export PATH="$PATH:$IQTA_TOOLS/Ninja:$IQTA_TOOLS/CMake/CMake.app/Contents/bin"
cc --version
rm -rf ${{ github.workspace }}/build && mkdir -p ${{ github.workspace }}/build
cd build
qt-cmake .. -G Ninja -DBUILD_FOR_AVALON_NANO3=1
ninja --verbose
ninja install
mv ${{ github.workspace }}/build/gui/K230BurningTool.dmg ${{ github.workspace }}/build/gui/K230BurningTool-AvalonNano3-macOS-${{ env.REVISION }}-unsigned.dmg

- uses: actions/upload-artifact@v4
with:
name: "K230BurningTool-AvalonNano3-macOS-${{ env.REVISION }}"
path: ${{ github.workspace }}/build/gui/*.dmg
if-no-files-found: error
compression-level: 0
# - name: Set up Developer ID certificate
# run: |
# # Decode the Developer ID certificate
# echo "${{ secrets.DEVELOPER_ID_CERT }}" | base64 --decode > developer_id.p12

# # Create a keychain and import the certificate
# security create-keychain -p tempkeychain build.keychain
# security default-keychain -s build.keychain
# security unlock-keychain -p tempkeychain build.keychain
# security import developer_id.p12 -k build.keychain -P "${{ secrets.DEVELOPER_ID_PASSWORD }}" -T /usr/bin/codesign
# security set-key-partition-list -S apple-tool:,apple: -s -k tempkeychain build.keychain

# - name: Sign the DMG
# run: |
# # Sign the DMG file
# codesign --deep --force --verify --verbose --sign "Developer ID Application: Your Name (TeamID)" ${{ github.workspace }}/build/gui/K230BurningTool-macOS-${{ env.REVISION }}-unsigned.dmg

# - name: Notarize the DMG
# run: |
# # Upload DMG for notarization
# xcrun altool --notarize-app \
# --primary-bundle-id "com.example.yourapp" \
# --username "${{ secrets.APPLE_ID }}" \
# --password "${{ secrets.APPLE_ID_PASSWORD }}" \
# --file ${{ github.workspace }}/build/gui/K230BurningTool-macOS-${{ env.REVISION }}-unsigned.dmg

# # Wait for notarization to complete
# echo "Waiting for notarization to complete..."
# sleep 120 # Adjust sleep time as needed
# xcrun altool --notarization-history 0 -u "${{ secrets.APPLE_ID }}" -p "${{ secrets.APPLE_ID_PASSWORD }}"

# - name: Staple Notarization Ticket
# run: |
# # Staple the notarization ticket to the DMG
# xcrun stapler staple ${{ github.workspace }}/build/gui/K230BurningTool-macOS-${{ env.REVISION }}-unsigned.dmg
# mv ${{ github.workspace }}/build/gui/K230BurningTool-macOS-${{ env.REVISION }}-unsigned.dmg ${{ github.workspace }}/build/gui/K230BurningTool-macOS-${{ env.REVISION }}.dmg

# - name: Upload Signed DMG
# uses: actions/upload-artifact@v4
# with:
# name: "K230BurningTool-macOS-${{ env.REVISION }}"
# path: ${{ github.workspace }}/build/gui/K230BurningTool-macOS-${{ env.REVISION }}.dmg
# if-no-files-found: error
# compression-level: 0

release:
if: startsWith(github.ref, 'refs/tags/')
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ docs/*.pdf
__pycache__
dist
*.egg-info

.clangd
.cache
54 changes: 38 additions & 16 deletions canaan-burn/burn/k230/k230_burn.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@

enum kburn_pkt_cmd {
KBURN_CMD_NONE = 0,
KBURN_CMD_REBOOT = 0x01,
KBURN_CMD_REBOOT = 0x01,

KBURN_CMD_DEV_PROBE = 0x10,
KBURN_CMD_DEV_GET_INFO = 0x11,
KBURN_CMD_DEV_GET_INFO = 0x11,

KBURN_CMD_WRITE_LBA = 0x20,
KBURN_CMD_ERASE_LBA = 0x21,
KBURN_CMD_ERASE_LBA = 0x20,

KBURN_CMD_MAX,
KBURN_CMD_WRITE_LBA = 0x21,
KBURN_CMD_WRITE_LBA_CHUNK = 0x22,

KBURN_CMD_MAX,
};

enum kburn_pkt_result {
Expand All @@ -34,14 +36,14 @@ enum kburn_pkt_result {
KBURN_RESULT_MAX,
};

#define KBUNR_USB_PKT_SIZE (64)
#define KBUNR_USB_PKT_SIZE (60)

#pragma pack(push,1)

struct kburn_usb_pkt {
uint16_t cmd;
uint16_t result; /* only valid in csw */
uint8_t data_size;
uint16_t data_size;
};

struct kburn_usb_pkt_wrap {
Expand Down Expand Up @@ -69,6 +71,7 @@ struct kburn_t {
char error_msg[128];

int ep_in, ep_out;
uint16_t ep_out_mps;
uint64_t capacity;
uint64_t dl_total, dl_size, dl_offset;
};
Expand Down Expand Up @@ -105,10 +108,12 @@ static int __get_endpoint(kburn_t *kburn)

dir = (ep->bEndpointAddress &
LIBUSB_ENDPOINT_DIR_MASK);
if (dir == LIBUSB_ENDPOINT_IN)
if (dir == LIBUSB_ENDPOINT_IN) {
kburn->ep_in = ep->bEndpointAddress;
else
} else {
kburn->ep_out = ep->bEndpointAddress;
kburn->ep_out_mps = ep->wMaxPacketSize;
}
}
}
}
Expand Down Expand Up @@ -141,6 +146,12 @@ static int kburn_write_data(kburn_t *kburn, void *data, int length)
return KBrunUsbCommError;
}

if(0x00 == (length % kburn->ep_out_mps)) {
if(LIBUSB_SUCCESS != (rc = libusb_bulk_transfer(node->usb->handle, kburn->ep_out, data, 0, &size, kburn->medium_info.timeout_ms))) {
debug_print(KBURN_LOG_ERROR, "Error - can't write bulk data ZLP, error %s", libusb_strerror((enum libusb_error)rc));
}
}

return KBurnNoErr;
}

Expand Down Expand Up @@ -276,6 +287,16 @@ uint64_t kburn_get_erase_size(struct kburn_t *kburn)
return 0;
}

uint64_t kburn_get_medium_blk_size(struct kburn_t *kburn)
{
if(kburn->medium_info.valid) {
return kburn->medium_info.blk_size;
}
debug_print(KBURN_LOG_ERROR, "unknown meidum type");

return 0;
}

bool kburn_parse_erase_config(struct kburn_t *kburn, uint64_t *offset, uint64_t *size)
{
uint64_t o, s;
Expand All @@ -287,8 +308,8 @@ bool kburn_parse_erase_config(struct kburn_t *kburn, uint64_t *offset, uint64_t
return false;
}

o = round_down(o, kburn->medium_info.erase_size);
s = round_up(s, kburn->medium_info.erase_size);
o = round_up(o, kburn->medium_info.erase_size);
s = round_down(s, kburn->medium_info.erase_size);

*offset = o;
*size = s;
Expand Down Expand Up @@ -349,7 +370,7 @@ void kburn_reset_chip(kburn_t *kburn)
bool kburn_probe(kburn_t *kburn, kburnUsbIspCommandTaget target, uint64_t *chunk_size)
{
uint8_t data[2];
uint64_t result[1];
uint64_t result[2];
int result_size = sizeof(result);

data[0] = target;
Expand All @@ -367,9 +388,10 @@ bool kburn_probe(kburn_t *kburn, kburnUsbIspCommandTaget target, uint64_t *chunk
return false;
}

debug_print(KBURN_LOG_INFO, "kburn probe, out chunksize %" PRId64 ", in chunksize %" PRId64 "\n", result[0], result[1]);

if(chunk_size) {
*chunk_size = result[0];
debug_print(KBURN_LOG_INFO, "kburn probe, chunksize %" PRId64 "\n", *chunk_size);
}

return true;
Expand Down Expand Up @@ -454,11 +476,11 @@ bool kburn_erase(struct kburn_t *kburn, uint64_t offset, uint64_t size, int max_
return KBurnNoErr == kburn_parse_resp(&csw, kburn, KBURN_CMD_ERASE_LBA, NULL, NULL);
}

bool kburn_write_start(struct kburn_t *kburn, uint64_t offset, uint64_t size)
bool kburn_write_start(struct kburn_t *kburn, uint64_t part_offset, uint64_t part_size, uint64_t file_size)
{
uint64_t cfg[2] = {offset, size};
uint64_t cfg[3] = {part_offset, file_size, part_size};

if((offset + size) > kburn->medium_info.capacity) {
if((part_offset + part_size) > kburn->medium_info.capacity) {
debug_print(KBURN_LOG_ERROR, "kburn write medium exceed");
strncpy(kburn->error_msg, "kburn write medium exceed", sizeof(kburn->error_msg));
return false;
Expand Down
3 changes: 2 additions & 1 deletion canaan-burn/include/public/k230_burn.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ PUBLIC kburnUsbIspCommandTaget kburn_get_medium_type(struct kburn_t *kburn);
PUBLIC uint64_t kburn_get_capacity(kburn_t *kburn);
PUBLIC uint64_t kburn_get_erase_size(struct kburn_t *kburn);
PUBLIC bool kburn_parse_erase_config(struct kburn_t *kburn, uint64_t *offset, uint64_t *size);
PUBLIC uint64_t kburn_get_medium_blk_size(struct kburn_t *kburn);

PUBLIC bool kburn_erase(struct kburn_t *kburn, uint64_t offset, uint64_t size, int max_retry);

PUBLIC bool kburn_write_start(kburn_t *kburn, uint64_t offset, uint64_t size);
PUBLIC bool kburn_write_start(struct kburn_t *kburn, uint64_t part_offset, uint64_t part_size, uint64_t file_size);
PUBLIC bool kburn_write_chunk(struct kburn_t *kburn, void *data, uint64_t size);
PUBLIC bool kbrun_write_end(struct kburn_t *kburn);

Expand Down
Binary file modified gui/resources/loader/loader_mmc.bin
Binary file not shown.
Binary file modified gui/resources/loader/loader_spi_nand.bin
Binary file not shown.
Binary file modified gui/resources/loader/loader_spi_nor.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion gui/src/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<property name="minimumSize">
<size>
<width>0</width>
<height>230</height>
<height>300</height>
</size>
</property>
</widget>
Expand Down
11 changes: 7 additions & 4 deletions gui/src/common/BurnImageItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
struct BurnImageItem
{
bool operator < (const struct BurnImageItem& other) const {
return address < other.address;
return partOffset < other.partOffset;
}

char altName[32];
uint32_t address;
uint32_t size;
QString partName;
uint32_t partOffset;
uint32_t partSize;
uint32_t partEraseSize;

QString fileName;
uint32_t fileSize;
};
Loading
Loading