Skip to content

Commit

Permalink
modify the packaging scripts and add packaging support for SG2044 fir…
Browse files Browse the repository at this point in the history
…mware
  • Loading branch information
wu-jian-hang authored and xingxg2022 committed Nov 27, 2024
1 parent 7d5fa90 commit a60c5e4
Show file tree
Hide file tree
Showing 16 changed files with 1,969 additions and 19 deletions.
Empty file.
Empty file.
38 changes: 19 additions & 19 deletions scripts/envsetup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1465,30 +1465,30 @@ function clean_rv_firmware()

function build_rv_firmware_bin()
{
version=$(date "+%Y%m%d%H%M%S")
RELEASED_NOTE_PATH=$RV_TOP_DIR/bootloader-riscv/release-note
build_rv_firmware
source $RV_SCRIPTS_DIR/make_pack_tool.sh $CHIP

gcc -g -Werror $RV_SCRIPTS_DIR/gen_spi_flash.c -o $RV_FIRMWARE_INSTALL_DIR/gen_spi_flash
if [ ! -e "$RELEASED_NOTE_MD" ] || [ ! -s "$RELEASED_NOTE_MD" ];then
version="1.0.0"
else
version=$(awk 'END {split($1, a, "_"); print a[1]}' $RELEASED_NOTE_MD)
fi

pushd $RV_FIRMWARE_INSTALL_DIR

rm -f firmware*.bin
cp $RV_FIRMWARE/fip.bin ./
dtb_group=$(ls *.dtb | awk '{print ""$1" "$1" 0x601000 0x020000000 "}')

./gen_spi_flash $dtb_group \
fw_dynamic.bin fw_dynamic.bin 0x660000 0x00000000 \
riscv64_Image riscv64_Image 0x6b0000 0x02000000 \
SG2042.fd SG2042.fd 0x02000000 0x02000000 \
zsbl.bin zsbl.bin 0x2a00000 0x40000000 \
initrd.img initrd.img 0x2b00000 0x30000000

mv spi_flash.bin firmware-$version.bin
rm -f gen_spi_flash

cp firmware-$version.bin image-bmc
$RV_SCRIPTS_DIR/gen-tar-for-bmc.sh image-bmc -o obmc-bios.tar.gz -m ast2600-sophgo -v $version -s
rm -f image-bmc
rm -f firmware*.bin *.xml
./make_xml *.dtb
mkdir -p $RV_SCRIPTS_DIR/build/ && cp ./*.xml $RV_SCRIPTS_DIR/build/
./pack *.xml
rm -f make_xml pack

mv firmware.bin firmware-$version.bin
if [ "$CHIP" = "mango" ];then
cp firmware-$version.bin image-bmc
$RV_SCRIPTS_DIR/gen-tar-for-bmc.sh image-bmc -o obmc-bios.tar.gz -m ast2600-sophgo -v $version -s
fi
rm -f image-bmc *.xml

popd
}
Expand Down
13 changes: 13 additions & 0 deletions scripts/make_pack_tool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if [ "$1" = "mango" ];then
gcc $RV_SCRIPTS_DIR/make_xml.c -DSG2042 -o $RV_FIRMWARE_INSTALL_DIR/make_xml
gcc $RV_SCRIPTS_DIR/pack/pack.c -DSG2042 -o $RV_FIRMWARE_INSTALL_DIR/pack
RELEASED_NOTE_MD="$RELEASED_NOTE_PATH/sg2042_release_note.md"
cp $RV_FIRMWARE/fip.bin $RV_FIRMWARE_INSTALL_DIR/
elif [ "$1" = "sg2044" ];then
gcc $RV_SCRIPTS_DIR/make_xml.c -DSG2044 -o $RV_FIRMWARE_INSTALL_DIR/make_xml
gcc $RV_SCRIPTS_DIR/pack/pack.c -DSG2044 -o $RV_FIRMWARE_INSTALL_DIR/pack
RELEASED_NOTE_MD="$RELEASED_NOTE_PATH/sg2044_release_note.md"
cp $RV_FIRMWARE/fsbl.bin $RV_FIRMWARE_INSTALL_DIR/
fi
158 changes: 158 additions & 0 deletions scripts/make_xml.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include "pack/ezxml/ezxml.h"
#include "pack/ezxml/ezxml.c"

#define BUFFERSIZE 16

#define SG2042_DTB_OFFSET 0x601000
#define SG2042_DTB_LOADER "0x20000000"
#define SG2044_DTB_OFFSET 0x500000
#define SG2044_DTB_LOADER "0x88000000"

void format_xml(const char *input,char *output){
const char *ptr = input;
char *out_ptr = output;
int indent=0,marked=0;
while(*ptr){
if(*ptr=='>'){
if(*(ptr+1)=='<'){
if(*(ptr+2)=='/'){
*out_ptr++=*ptr++;
indent-=1;
marked=1;
}
else{
if(marked){
*out_ptr++=*ptr++;
marked=0;
}
else{
indent+=1;
*out_ptr++=*ptr++;
}
}
*out_ptr++='\n';
memset(out_ptr,'\t',indent);
out_ptr+=indent;
}
else{
marked=1;
*out_ptr++=*ptr++;
}
}else{
*out_ptr++=*ptr++;
}
}
*out_ptr = '\0';
}

int ezxml_set_element(ezxml_t parent,char *child,char *name,char *offset,char *loader,char* size){
ezxml_t component=ezxml_add_child(parent,child,0);
if (component==NULL){
ezxml_free(parent);
return -1;
}
if(name){
ezxml_set_txt(ezxml_add_child(component, "name", 0), name);
ezxml_set_txt(ezxml_add_child(component, "file", 0), name);
}
if(offset){
ezxml_set_txt(ezxml_add_child(component,"offset" , 0), offset);
}
if(loader){
ezxml_set_txt(ezxml_add_child(component,"loader" , 0), loader);
}
if(size){
ezxml_set_txt(ezxml_add_child(component,"size" , 0), size);
}
return 0;
}

void ezxml_set_component(ezxml_t parent,char *comp_name,char *comp_offset,char *comp_loader){
ezxml_set_element(parent,"component",comp_name,comp_offset,comp_loader,NULL);
}

int main(int argc, char* argv[]) {

struct stat file_stat;
int ret,i;
char* file_name,*out_put;
char *ld_dtb;
char sflash_offset[argc-1][BUFFERSIZE];
uint64_t of_dtb;
ezxml_t xml = ezxml_new("firmware");
if (xml==NULL){
printf("generate xml file failed!");
return -1;
}
// generate xml file
#ifdef SG2042
of_dtb=SG2042_DTB_OFFSET;
ld_dtb=SG2042_DTB_LOADER;
ezxml_set_txt(ezxml_add_child(xml, "name", 0), "SG2042");
ezxml_set_txt(ezxml_add_child(xml, "size", 0), "0x4000000");
// add efie
ezxml_set_element(xml,"efie",NULL,"0x600000",NULL,"4096");
//add fip.bin
ezxml_set_element(xml,"fip","fip.bin","0x00030000",NULL,NULL);
//add zsbl.bin
ezxml_set_component(xml,"zsbl.bin","0x2a00000","0x40000000");
//add fw_dynamic.bin
ezxml_set_component(xml,"fw_dynamic.bin","0x660000","0x00000000");
//add riscv64_Image
ezxml_set_component(xml,"riscv64_Image","0x6b0000","0x02000000");
//add initrd.img
ezxml_set_component(xml,"initrd.img","0x2b00000","0x30000000");
out_put="sg2042-layout.xml";
#elif defined(SG2044)
of_dtb=SG2044_DTB_OFFSET;
ld_dtb=SG2044_DTB_LOADER;
ezxml_set_txt(ezxml_add_child(xml, "name", 0), "SG2044");
ezxml_set_txt(ezxml_add_child(xml, "size", 0), "0x4000000");
// add efie
ezxml_set_element(xml,"efie",NULL,"0x80000",NULL,"4096");
//add zsbl.bin
ezxml_set_component(xml,"zsbl.bin","0x2f0000","0x40000000");
//add fsbl.bin
ezxml_set_component(xml,"fsbl.bin","0x81000","0x7010080000");
//add fw_dynamic.bin
ezxml_set_component(xml,"fw_dynamic.bin","0x15d000","0x80000000");
//add SG2044.fd
ezxml_set_component(xml,"SG2044.fd","0x600000","0x80200000");
out_put="sg2044-layout.xml";
#endif

// add device-tree
for (i=0;i<argc-1;i++){
sprintf(sflash_offset[i], "0x%lX", of_dtb);
file_name=argv[i+1];
ret=stat(file_name,&file_stat);
if (ret || !file_stat.st_size) {
printf("can't get file %s size %ld\n", file_name,file_stat.st_size);
return -1;
}
ezxml_set_component(xml,file_name,sflash_offset[i],ld_dtb);
of_dtb += file_stat.st_size;
}
FILE *fp = fopen(out_put, "w");
if (fp==NULL){
ezxml_free(xml);
printf("can't create and open %s !",out_put);
return -1;
}
else if (fp) {
// ret=fprintf(fp, "<?xml version=\"1.0\"?>\n");
const char *raw_xml = ezxml_toxml(xml);
char formatted_xml[8192];
format_xml(raw_xml, formatted_xml);
fprintf(fp, "%s", formatted_xml);
fclose(fp);
}
ezxml_free(xml);
return 0;
}
4 changes: 4 additions & 0 deletions scripts/pack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pack
pack.elf
*.o
*.map
8 changes: 8 additions & 0 deletions scripts/pack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# PC Pack Tools
This tool is used to pack binary.

# How to compile
just gcc.

# How to use
pack *.xml
63 changes: 63 additions & 0 deletions scripts/pack/ezxml/GNUmakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Makefile
#
# Copyright 2005 Aaron Voisine <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

CC = gcc
AR = ar
RM = rm -f
CFLAGS = -Wall -O2
DEBUG_CFLAGS = -O0 -g
OBJS = ezxml.o
LIB = libezxml.a
TEST = ezxmltest
ifdef NOMMAP
CFLAGS += -D EZXML_NOMMAP
endif
ifdef DEBUG
CFLAGS += $(DEBUG_CFLAGS)
endif

all: $(LIB)

$(LIB): $(OBJS)
$(AR) rcs $(LIB) $(OBJS)

nommap: CFLAGS += -D EZXML_NOMMAP
nommap: all

debug: CFLAGS += $(DEBUG_CFLAGS)
debug: all

test: CFLAGS += $(DEBUG_CFLAGS)
test: $(TEST)

$(TEST): CFLAGS += -D EZXML_TEST
$(TEST): $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS)

ezxml.o: ezxml.h ezxml.c

.c.o:
$(CC) $(CFLAGS) -c -o $@ $<

clean:
$(RM) $(OBJS) $(LIB) $(TEST) *~
62 changes: 62 additions & 0 deletions scripts/pack/ezxml/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Makefile
#
# Copyright 2004, 2005 Aaron Voisine <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

CC = gcc
AR = ar
RM = rm -f
CFLAGS = -Wall -O2
OBJS = ezxml.o
LIB = libezxml.a
TEST = ezxmltest

.if defined(NOMMAP) || make(nommap)
CFLAGS += -D EZXML_NOMMAP
.endif
.if defined(DEBUG) || make(debug) || make(test)
CFLAGS += -O0 -g
.endif
.if make($(TEST)) || make(test)
CFLAGS += -D EZXML_TEST
.endif

all: $(LIB)

$(LIB): $(OBJS)
$(AR) rcs $(LIB) $(OBJS)

test: $(TEST)

debug: all

nommap: all

$(TEST): $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS)

ezxml.o: ezxml.h ezxml.c

.c.o:
$(CC) $(CFLAGS) -c -o $@ $<

clean:
$(RM) $(OBJS) $(LIB) $(TEST) *~
Loading

0 comments on commit a60c5e4

Please sign in to comment.