-
Notifications
You must be signed in to change notification settings - Fork 77
Add mktag kernel #35
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
Open
dmascord
wants to merge
1
commit into
openwrt:master
Choose a base branch
from
dmascord:add_mktag_kernel
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add mktag kernel #35
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-or-later | ||
| /* | ||
| * mktag_kernel.c - utility to write the tag_kernel file for TP Link Deco X20 jffs2 filesystem lookup | ||
| * | ||
| * Copyright (C) 2024 Damien Mascord <[email protected]> | ||
| */ | ||
|
|
||
| #include <arpa/inet.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <stdint.h> | ||
| #include <unistd.h> | ||
| #include <sys/stat.h> | ||
|
|
||
| int fpread(void *buffer, size_t size, size_t nitems, size_t offset, FILE *fp); | ||
|
|
||
| typedef struct __attribute__((scalar_storage_order("little-endian"))) _LINUX_FILE_TAG | ||
| { | ||
| int32_t rootfsLen; | ||
| int32_t binCrc32; | ||
| int32_t reserved[126]; | ||
| }LINUX_FILE_TAG; | ||
|
|
||
| void usage(void) __attribute__ (( __noreturn__ )); | ||
|
|
||
| void usage(void) | ||
| { | ||
| fprintf(stderr, "Usage: mktag_kernel [-s <rootfsLen>] [-o <outputfile>] [-t (test mode)]\n"); | ||
| exit(EXIT_FAILURE); | ||
| } | ||
|
|
||
| int main(int argc, char **argv) | ||
| { | ||
| char buf[1024]; /* keep this at 1k or adjust garbage calc below */ | ||
| FILE *in = stdin, *out = stdout; | ||
| char *ofn = NULL, *rootfsLen = NULL; | ||
| size_t n; | ||
| int c, first_block = 1; | ||
| unsigned char tag_buf[sizeof(LINUX_FILE_TAG)]; | ||
| LINUX_FILE_TAG * pKern_tag = (LINUX_FILE_TAG *)tag_buf; | ||
| int testMode = 0; | ||
|
|
||
| while ((c = getopt(argc, argv, "s:o:h:t")) != -1) { | ||
| switch (c) { | ||
| case 's': | ||
| rootfsLen = optarg; | ||
| break; | ||
| case 'o': | ||
| ofn = optarg; | ||
| break; | ||
| case 't': | ||
| testMode = 1; | ||
| break; | ||
| case 'h': | ||
| default: | ||
| usage(); | ||
| } | ||
| } | ||
|
|
||
| if (ofn && !(out = fopen(ofn, "wb"))) { | ||
| fprintf(stderr, "can not open \"%s\" for writing\n", ofn); | ||
| usage(); | ||
| } | ||
|
|
||
| memset(tag_buf, 0, sizeof(LINUX_FILE_TAG)); | ||
|
|
||
| if (!rootfsLen) | ||
| { | ||
| usage(); | ||
| } | ||
|
|
||
| pKern_tag->rootfsLen = strtol(rootfsLen, NULL, 10); | ||
| pKern_tag->binCrc32 = 0; | ||
|
|
||
| if (testMode) | ||
| { | ||
| for (int xx = 0; xx < sizeof(LINUX_FILE_TAG); xx++) | ||
| { | ||
| printf("%.2X", ((unsigned char *)pKern_tag)[xx]); | ||
| } | ||
| printf("\n"); | ||
| } | ||
|
|
||
| int flag = 0; | ||
| flag = fwrite(pKern_tag, sizeof(LINUX_FILE_TAG), 1, out); | ||
| fflush(out); | ||
| fclose(out); | ||
|
|
||
| if (testMode) | ||
| { | ||
| if (ofn && !(out = fopen(ofn, "rb"))) { | ||
| fprintf(stderr, "can not open \"%s\" for reading\n", ofn); | ||
| usage(); | ||
| } | ||
| //clear it out | ||
| memset(tag_buf, 0, sizeof(LINUX_FILE_TAG)); | ||
| fpread(tag_buf, 1, sizeof(LINUX_FILE_TAG), 0, out); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| int fpread(void *buffer, size_t size, size_t nitems, size_t offset, FILE *fp) | ||
| { | ||
| printf("fpread %d %d %d \n", size, nitems, offset); | ||
| int seekPosition = fseek(fp, offset, SEEK_SET); | ||
| printf("seekPosition: %d\n", seekPosition); | ||
| if(seekPosition != 0) | ||
| { | ||
| printf("unable to seek to %d\n", offset); | ||
| return 0; | ||
| } | ||
| int returnValue = fread(buffer, size, nitems, fp); | ||
| printf("returnValue %d:\n",returnValue); | ||
| for (int i = 0; i < nitems; i++) | ||
| { | ||
| printf("%.2X", ((unsigned char *)buffer)[i]); | ||
| } | ||
| printf(".\n"); | ||
| return returnValue; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tool just writes the root fs length into the first 4 bytes and nulls the rest. I think we can do this better in a shell script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will have a look into it, are there any endianess helpers so that the struct is written the correct way?