Skip to content

Build H2 with Picolibc#10

Open
quic-k wants to merge 3 commits into
masterfrom
build-with-pico
Open

Build H2 with Picolibc#10
quic-k wants to merge 3 commits into
masterfrom
build-with-pico

Conversation

@quic-k
Copy link
Copy Markdown
Contributor

@quic-k quic-k commented Apr 20, 2026

No description provided.

colmode
colmode previously requested changes May 5, 2026
Copy link
Copy Markdown

@colmode colmode left a comment

Choose a reason for hiding this comment

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

Looks good overall, but we might want to merge this after erich's makefile changes rather than the other way around.

r1 = #__boot_net_phys_offset__
memw(r1) = r0
jump _start // picolibc CRT entry (replaces hexagon_pre_main)

Copy link
Copy Markdown
Contributor Author

@quic-k quic-k May 5, 2026

Choose a reason for hiding this comment

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

we can, but since we are not including any C header, we don't have __PICOLIBC__
so for simplicity I created 2 files

maybe I will have to use the PICOLIBC=1 flag to define a macro, which we can use
or do you have something else in mind?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"PICOLIBC=1 flag to define a macro", yes. But since this is all transitional and we'll eventually use only pico I think that leaving it as is would be fine.

r1 = #__boot_net_phys_offset__
memw(r1) = r0
jump _start // picolibc CRT entry (replaces hexagon_pre_main)

Copy link
Copy Markdown
Contributor Author

@quic-k quic-k May 5, 2026

Choose a reason for hiding this comment

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

we can, but since we are not including any C header, we don't have __PICOLIBC__
so for simplicity I created 2 files

maybe I will have to use the PICOLIBC=1 flag to define a macro, which we can use
or do you have something else in mind?

@quic-k
Copy link
Copy Markdown
Contributor Author

quic-k commented May 5, 2026

Looks good overall, but we might want to merge this after erich's makefile changes rather than the other way around.

thanks for the review, ping me whenever that is merged, I will have to resolve merge conflicts

Also, we don't yet have a way to run unit tests with pico since those tools aren't on github. Best to run make testall locally and then comment here when it passes.

sure, so far I have built H2 successfully and used the install artifacts to run Picolibc testsuite which passes
will look into getting H2 unit tests working with Picolibc

@bryanb-h2
Copy link
Copy Markdown
Contributor

Looks good overall, but we might want to merge this after erich's makefile changes rather than the other way around.

Hey, look; our first comment from a non-qc account :)

@quic-k
Copy link
Copy Markdown
Contributor Author

quic-k commented May 7, 2026

why is hexagon_standalone.h being used? @bryanb-h2

#include <hexagon_standalone.h>

#include <hexagon_standalone.h>

@bryanb-h2
Copy link
Copy Markdown
Contributor

bryanb-h2 commented May 7, 2026

why is hexagon_standalone.h being used? @bryanb-h2

#include <hexagon_standalone.h>

#include <hexagon_standalone.h>

Because most of the unit tests run with standalone with a test harness for testing only one function -- avoids booting the kernel to simplify debug. We need a substitute for standalone but we haven't addressed this yet. The unit tests don't even use features of standalone. Using the default dinkum build is just a convenient way to link with crt0 and get to main(). We actually have a min_crt0 in the h2 repo. Just need to dust that off and change how we link unit tests.

Here it is, entirely:

/*

  • Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.

  • SPDX-License-Identifier: BSD-3-Clause-Clear
    */

    .section .start,"awx",@progbits

.global _start

.global hexagon_pre_main

#_start:

jump start

hexagon_pre_main:
r0 = ##SDA_BASE
gp = r0
r29 = ##stack
{
r0 = r29
r1 = #1
call main
}

jump start

.data
.p2align 8
.space 1024

stack:
.word stack
.word 0

@quic-k
Copy link
Copy Markdown
Contributor Author

quic-k commented May 7, 2026

Because most of the unit tests run with standalone with a test harness for testing only one function -- avoids booting the kernel to simplify debug.

yeah, for debugging that is better, but booter tests would have been easier for me to get passing

We need a substitute for standalone but we haven't addressed this yet. The unit tests don't even use features of standalone. Using the default dinkum build is just a convenient way to link with crt0 and get to main(). We actually have a min_crt0 in the h2 repo. Just need to dust that off and change how we link unit tests.

is this planned to be done soon? or am I supposed to do this in this PR? maybe I could but this sounds like lot of debugging
:\

@bryanb-h2
Copy link
Copy Markdown
Contributor

Because most of the unit tests run with standalone with a test harness for testing only one function -- avoids booting the kernel to simplify debug.

yeah, for debugging that is better, but booter tests would have been easier for me to get passing

We need a substitute for standalone but we haven't addressed this yet. The unit tests don't even use features of standalone. Using the default dinkum build is just a convenient way to link with crt0 and get to main(). We actually have a min_crt0 in the h2 repo. Just need to dust that off and change how we link unit tests.

is this planned to be done soon? or am I supposed to do this in this PR? maybe I could but this sounds like lot of debugging :\

Not unless you're really keen to do it. I just filed QDSP-57392 for this.

Copy link
Copy Markdown
Contributor

@bryanb-h2 bryanb-h2 left a comment

Choose a reason for hiding this comment

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

The merge conflicts with master were complicated in some places. Please check if I screwed something up.

Comment thread booter/booter.c
}

if (NULL == (pmap->base.raw = (h2_u32_t)realloc((void *)(pmap->base.raw), sizeof(H2K_linear_fmt_t) * (end + npages + 1)))) {
if (0 == (pmap->base.raw = (h2_u32_t)realloc((void *)(pmap->base.raw), sizeof(H2K_linear_fmt_t) * (end + npages + 1)))) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why 0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

booter.c:673:11: warning: comparison between pointer and integer ('void *' and 'h2_u32_t' (aka 'unsigned int')) [-Wpointer-integer-compare]
  673 |         if (NULL == (pmap->base.raw = (h2_u32_t)realloc((void *)(pmap->base.raw), sizeof(H2K_linear_fmt_t) * (end + npages + 1)))) {
      |             ~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So pico defines NULL differently? I thought that def was part of the tools and we don't get the same warning when building with the existing dinkum tools.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in Pico toolchain NULL in preprocessed to ((void*)0) (comes from clang's stddef.h)
existing tools might be just defining NULL to 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok, then the right thing to do is probably this, which works with dinkum also:

diff --git a/booter/booter.c b/booter/booter.c
index 071702bc6..93fcf9adc 100644
--- a/booter/booter.c
+++ b/booter/booter.c
@@ -670,7 +670,7 @@ void add_linear_trans(unsigned int idx, unsigned long va, unsigned long long pa,
vm_params[idx].pmap_added = 1;
}

  • if (NULL == (pmap->base.raw = (h2_u32_t)realloc((void *)(pmap->base.raw), sizeof(H2K_linear_fmt_t) * (end + npages + 1)))) {
  • if (NULL == (void *)(pmap->base.raw = (h2_u32_t)realloc((void *)(pmap->base.raw), sizeof(H2K_linear_fmt_t) * (end + npages + 1)))) {
    error("realloc pmap->base", NULL);
    }
    base = (H2K_linear_fmt_t *)(pmap->base.raw);

Comment thread booter/Makefile

CFLAGS = $(OPTIMIZE) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Wall -Werror -Wno-builtin-requires-header -g -I. -I$(INSTALLPATH)/include -I$(KERNEL_BUILD_DIR)/include
LDFLAGS = -L$(INSTALLPATH)/lib -moslib=h2 -Qunused-arguments
ifeq ($(PICOLIBC),1)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about pulling all these if pico sections into one make include file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, I could do something like that
but maybe I should wait till H2 unit tests are cleaned up, so I don't have to rebase multiple times?

quic-k added 3 commits May 20, 2026 16:43
Replace all patsubst %/install,%/build/...,$(INSTALLPATH) expressions
with $(INSTALLPATH)/../build/... across kernel, libs, booter, and stake
Makefiles so that a user-supplied INSTALLPATH without a trailing
/install
no longer causes same-file cp errors, circular dependencies, or missing
generated headers.

Signed-off-by: Kushal Pal <kushpal@qti.qualcomm.com>
libs/locks and libs/syscall/wrapper were writing .o files and archives
directly into the source tree. Add BUILD_DIR := $(INSTALLPATH)/../build/...
to both Makefiles and update libs/Makefile to reference the archives from
the build tree rather than the source tree.

Signed-off-by: Kushal Pal <kushpal@qti.qualcomm.com>
Signed-off-by: Kushal Pal <kushpal@qti.qualcomm.com>
@quic-k quic-k force-pushed the build-with-pico branch from 786255c to d68962a Compare May 20, 2026 11:21
Copy link
Copy Markdown
Contributor Author

@quic-k quic-k left a comment

Choose a reason for hiding this comment

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

I have rebased on master

Comment thread booter/booter.c
}

if (NULL == (pmap->base.raw = (h2_u32_t)realloc((void *)(pmap->base.raw), sizeof(H2K_linear_fmt_t) * (end + npages + 1)))) {
if (0 == (pmap->base.raw = (h2_u32_t)realloc((void *)(pmap->base.raw), sizeof(H2K_linear_fmt_t) * (end + npages + 1)))) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

booter.c:673:11: warning: comparison between pointer and integer ('void *' and 'h2_u32_t' (aka 'unsigned int')) [-Wpointer-integer-compare]
  673 |         if (NULL == (pmap->base.raw = (h2_u32_t)realloc((void *)(pmap->base.raw), sizeof(H2K_linear_fmt_t) * (end + npages + 1)))) {
      |             ~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Comment thread booter/Makefile

CFLAGS = $(OPTIMIZE) -mv$(TOOLARCH) -DARCHV=$(ARCHV) -Wall -Werror -Wno-builtin-requires-header -g -I. -I$(INSTALLPATH)/include -I$(KERNEL_BUILD_DIR)/include
LDFLAGS = -L$(INSTALLPATH)/lib -moslib=h2 -Qunused-arguments
ifeq ($(PICOLIBC),1)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, I could do something like that
but maybe I should wait till H2 unit tests are cleaned up, so I don't have to rebase multiple times?

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.

3 participants