Skip to content

Commit

Permalink
support LZMA compressed ramdisk
Browse files Browse the repository at this point in the history
  • Loading branch information
asdfugil committed Oct 30, 2023
1 parent 7d27b7e commit 35c5468
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/shell/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*
*/
#include <pongo.h>
#include <lzma/lzmadec.h>

extern volatile char gBootFlag;

Expand Down Expand Up @@ -56,16 +57,35 @@ uint32_t ramdisk_size;
*/

void ramdisk_cmd() {
void ramdisk_cmd(const char* cmd, char* args) {
if (!loader_xfer_recv_count) {
iprintf("please upload a ramdisk before issuing this command\n");
return;
}
if (ramdisk_buf) free(ramdisk_buf);
ramdisk_buf = malloc(loader_xfer_recv_count);
if (!ramdisk_buf) panic("couldn't reserve heap for ramdisk");
ramdisk_size = loader_xfer_recv_count;
memcpy(ramdisk_buf, loader_xfer_recv_data, ramdisk_size);
if (args[0] != '\0') {
size_t tmp_ramdisk_size;
if ((tmp_ramdisk_size = (int)strtoul(args, NULL, 0)) != 0) {
printf("args: %s, tmp_ramdisk_size: %u\n", args, tmp_ramdisk_size);
if (ramdisk_buf) free(ramdisk_buf);
ramdisk_buf = malloc(tmp_ramdisk_size);
if (!ramdisk_buf) panic("couldn't reserve heap for ramdisk");
int lzma_result = unlzma_decompress(ramdisk_buf, &tmp_ramdisk_size, loader_xfer_recv_data, loader_xfer_recv_count);
if (lzma_result != SZ_OK) {
printf("ramdisk decompression failed\n");
return;
}
ramdisk_size = (uint32_t)tmp_ramdisk_size;
} else {
printf("ramdisk usage: ramdisk [uncompressed size if compressed]\n");
return;
}
} else {
if (ramdisk_buf) free(ramdisk_buf);
ramdisk_buf = malloc(loader_xfer_recv_count);
if (!ramdisk_buf) panic("couldn't reserve heap for ramdisk");
ramdisk_size = loader_xfer_recv_count;
memcpy(ramdisk_buf, loader_xfer_recv_data, ramdisk_size);
}
loader_xfer_recv_count = 0;
}

Expand Down

0 comments on commit 35c5468

Please sign in to comment.