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

Sparse image format + Some fixes #5

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

abozhinov444
Copy link

No description provided.

Copy link
Contributor

@ndechesne ndechesne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some very initial comments.. i haven't reviewed the bulk of the series yet..

please make sure you have signed-off line, and better commit logs. you also need to split patches into individual logical chunks when appropriate.

@@ -46,11 +46,11 @@
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <libxml/parser.h>
#include <libxml/tree.h>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed (and does not correspond to what you have in the commit log).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libxml/parser.h is unneeded and the libxml/tree.h is included in util.h.
util.h is new header which declares xml parsing wrapper functions, which were previously declared in qdl.h. I don't see by what reason qdl I/O API should be mixed with XML parsing API.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated patch with commit message with all reasons.

firehose.c Outdated
@@ -153,7 +153,8 @@ static int firehose_read(struct qdl_device *qdl, int wait, int (*response_parser
for (node = nodes; node; node = node->next) {
if (xmlStrcmp(node->name, (xmlChar*)"log") == 0) {
firehose_response_log(node);
} else if (xmlStrcmp(node->name, (xmlChar*)"response") == 0) {
}
else if (xmlStrcmp(node->name, (xmlChar*)"response") == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do not change code style. or if you do , then you need to do it consistently and in a separate patch anyways.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will push patch with reverted code style.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated patch with reverted code style.

@@ -102,7 +101,7 @@ int patch_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl, s
int ret;

for (patch = patches; patch; patch = patch->next) {
if (strcmp(patch->filename, "DISK"))
if (xmlStrcmp(patch->filename, (const xmlChar *)"DISK"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you justify why/how xmlStrcmp() is better than strcmp()? it would have been a good idea to provide that info in the commit message, btw.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better because XML API returns xmlChar which is unsigned char. As we use libxml2 there is no reason to use normal strcmp.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to mention that the standard does not specify if plain char is signed or unsigned.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated patch with commit message with all reasons.

@@ -156,11 +155,11 @@ int program_execute(struct qdl_device *qdl, int (*apply)(struct qdl_device *qdl,
int program_find_bootable_partition(void)
{
struct program *program;
const char *label;
char *label;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we should use const, when pointer holds dynamically allocated data and dynamically assigned value?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated patch with commit message with all reasons.

@@ -0,0 +1,10 @@
#ifndef __UTIL_H__
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change does not relate to this commit subject

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update commit message to be more informational.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated patch with commit message with all reasons.

@@ -94,7 +94,7 @@ unsigned attr_as_unsigned(xmlNode *node, const char *attr, int *errors)
return (unsigned int) strtoul((char*)value, NULL, 10);
}

const char *attr_as_string(xmlNode *node, const char *attr, int *errors)
xmlChar *attr_as_string(xmlNode *node, const char *attr, int *errors)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function converts a xml attribute into a string. i don't understand why you want to use xmlChar, since the purpose is to extract information from xml.

Copy link
Author

@abozhinov444 abozhinov444 Oct 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better because XML API returns xmlChar which is unsigned char. As we use libxml2 there is no reason to use other types. With this change things becomes more clear for use.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated patch with commit message with all reasons.

firehose.c Outdated
@@ -103,6 +103,8 @@ static void firehose_response_log(xmlNode *node)

value = xmlGetProp(node, (xmlChar*)"value");
printf("LOG: %s\n", value);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

un-needed empty line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be removed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated patch with removed extra line.

firehose.c Outdated

value = xmlGetProp(node, (xmlChar*)"value");
return !!xmlStrcmp(value, (xmlChar*)"ACK");
ret = !!xmlStrcmp(value, (xmlChar*)"ACK");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated patch with removed extra line.

@@ -215,9 +221,14 @@ static int firehose_configure_response_parser(xmlNode *node)
size_t max_size;

value = xmlGetProp(node, (xmlChar*)"value");
if (!value)
return -EINVAL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure that EINVAL will be interpretated correctly by callers here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before my patch it returns also -EINVAL.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right. sorry i missed that ;-)

sahara.c Outdated
@@ -196,8 +196,8 @@ static int sahara_done(struct qdl_device *qdl, struct sahara_pkt *pkt)

int sahara_run(struct qdl_device *qdl, char *prog_mbn)
{
struct sahara_pkt *pkt;
char buf[4096];
struct sahara_pkt *pkt = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these 2 lines are not related to commit log.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated patch with removed extra initialization.

Copy link
Collaborator

@andersson andersson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comment inline.

In particular I think it would be nice if you could split this into "freeing of resources", "style changes" and "initialize xml parser".

Thanks,
Bjorn

program.c Outdated
if (programes_last)
free(programes_last);

programes_last = program;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a second variable to track the "next" element as you free up the current "program".

for (program = programs; program; program = next) {
next = program->next;
free(program);
}

program.c Outdated

for (program = programes; program; program = program->next) {
if (program->filename)
xmlFree(program->filename);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Analog to standard free() it's valid to pass NULL to this function, so remove the extra conditionals before each one of these.

patch.c Outdated
patches_last = NULL;

for (patch = patches; patch; patch = patch->next) {
if (patch->filename)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as for program_unload() below (just read your patch backwards).

@@ -305,3 +305,22 @@ int ufs_provisioning_execute(struct qdl_device *qdl,
}
return apply_ufs_epilogue(qdl, ufs_epilogue_p, true);
}

void ufs_unload(void)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as program_unload().

@@ -464,6 +477,8 @@ int main(int argc, char **argv)

prog_mbn = argv[optind++];

xmlInitParser();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to fall into the same category as the other fixes in this patch; you have freeing of memory, some style changes and this.

I think it would be nice if this was 3 different patches.

Copy link
Collaborator

@andersson andersson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that going towards standard types would be a better choice, but after reading your patch I'm happy with the result. Let's use xmlChar in all places that deals with xml data.

But you have listed three different things you changed in your commit message, that's a good reason to split this into three distinct patches. Please do so.

Copy link
Collaborator

@andersson andersson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@andersson andersson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume you mean that you removed some parts of the API that we don't need.

Otherwise it would be good to track this delta by first adding a verbatim copy of the files, then add a commit that migrates the code to what we want and finally one that adds it to the Makefile.

@blenk92
Copy link

blenk92 commented Oct 29, 2019

I tried this implementation (with valgrind) and I'm seeing this:

==29674== Invalid read of size 8
==29674==    at 0x483F71C: memmove (vg_replace_strmem.c:1271)
==29674==    by 0x10B92C: firehose_program_sparse (firehose.c:330)
==29674==    by 0x10E5FF: callback_stream_skip (output_stream.c:113)
==29674==    by 0x10E38A: write_all_blocks (sparse.c:110)
==29674==    by 0x10E4DC: sparse_stream_callback (sparse.c:141)
==29674==    by 0x10BD2E: firehose_program (firehose.c:444)
==29674==    by 0x10D37E: program_execute (program.c:136)
==29674==    by 0x10C0F2: firehose_run (firehose.c:698)
==29674==    by 0x10AAC8: main (qdl.c:517)
==29674==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==29674== 
==29674== 
==29674== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==29674==  Access not within mapped region at address 0x0
==29674==    at 0x483F71C: memmove (vg_replace_strmem.c:1271)
==29674==    by 0x10B92C: firehose_program_sparse (firehose.c:330)
==29674==    by 0x10E5FF: callback_stream_skip (output_stream.c:113)
==29674==    by 0x10E38A: write_all_blocks (sparse.c:110)
==29674==    by 0x10E4DC: sparse_stream_callback (sparse.c:141)
==29674==    by 0x10BD2E: firehose_program (firehose.c:444)
==29674==    by 0x10D37E: program_execute (program.c:136)
==29674==    by 0x10C0F2: firehose_run (firehose.c:698)
==29674==    by 0x10AAC8: main (qdl.c:517)
==29674==  If you believe this happened as a result of a stack
==29674==  overflow in your program's main thread (unlikely but
==29674==  possible), you can try to increase the size of the
==29674==  main thread stack using the --main-stacksize= flag.
==29674==  The main thread stack size used in this run was 8388608.
==29674== 
...

@abozhinov444
Copy link
Author

I tried this implementation (with valgrind) and I'm seeing this:

==29674== Invalid read of size 8
==29674==    at 0x483F71C: memmove (vg_replace_strmem.c:1271)
==29674==    by 0x10B92C: firehose_program_sparse (firehose.c:330)
==29674==    by 0x10E5FF: callback_stream_skip (output_stream.c:113)
==29674==    by 0x10E38A: write_all_blocks (sparse.c:110)
==29674==    by 0x10E4DC: sparse_stream_callback (sparse.c:141)
==29674==    by 0x10BD2E: firehose_program (firehose.c:444)
==29674==    by 0x10D37E: program_execute (program.c:136)
==29674==    by 0x10C0F2: firehose_run (firehose.c:698)
==29674==    by 0x10AAC8: main (qdl.c:517)
==29674==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==29674== 
==29674== 
==29674== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==29674==  Access not within mapped region at address 0x0
==29674==    at 0x483F71C: memmove (vg_replace_strmem.c:1271)
==29674==    by 0x10B92C: firehose_program_sparse (firehose.c:330)
==29674==    by 0x10E5FF: callback_stream_skip (output_stream.c:113)
==29674==    by 0x10E38A: write_all_blocks (sparse.c:110)
==29674==    by 0x10E4DC: sparse_stream_callback (sparse.c:141)
==29674==    by 0x10BD2E: firehose_program (firehose.c:444)
==29674==    by 0x10D37E: program_execute (program.c:136)
==29674==    by 0x10C0F2: firehose_run (firehose.c:698)
==29674==    by 0x10AAC8: main (qdl.c:517)
==29674==  If you believe this happened as a result of a stack
==29674==  overflow in your program's main thread (unlikely but
==29674==  possible), you can try to increase the size of the
==29674==  main thread stack using the --main-stacksize= flag.
==29674==  The main thread stack size used in this run was 8388608.
==29674== 
...

I am splitting patches, now due to latest review and will address this issue.

This change is due to difference between
code style on base source and libsparse
source.
This change is due to project structure.
 - output_file.c to output_stream.c
 - output_file.h to output_stream.h
 - removed unused code
 - removed crc support
 - removed gz compression support
 - renamed all "file" named structures and
   functions to "stream" in output_stream.c
 seperate header, they should not be mixed with
 qdl I/O API. In result there is a new util.h header.
 strcmp to xmlStrcmp. Also removed const qualifiers on
 dynamically assigned variables.
     strcmp to xmlStrcmp and free to xmlFree. Also
     removed const qualifiers on dynamically assigned
     variables.
@abozhinov444
Copy link
Author

Hi Bjorn,
i have split all the patches. Also base source is there. Now it is much better. Also i have fixed mentioned above issue.

Regards,
Atanas

@blenk92
Copy link

blenk92 commented Oct 30, 2019

Hi Bjorn,
i have split all the patches. Also base source is there. Now it is much better. Also i have fixed mentioned above issue.

Regards,
Atanas

Tried it, seems to work for me now ;-)

@abozhinov444
Copy link
Author

Thank you, for the feedback.

@obbardc
Copy link

obbardc commented Jun 16, 2022

@abozhinov444 Do you have a chance to rebase onto HEAD ?

obbardc added a commit to obbardc/qdl that referenced this pull request Jun 29, 2022
Based on original work from linux-msm#5

Signed-off-by: Christopher Obbard <[email protected]>
@jwinarske
Copy link

Is this PR getting merged? What's the status?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants