From 6ee792e561969bc25445a582a448cd7f0e00067a Mon Sep 17 00:00:00 2001 From: alpine9000 Date: Tue, 1 Mar 2016 15:30:01 +1100 Subject: [PATCH] Converted makeadf to be consistent with imagecon --- tools/makeadf | Bin 8784 -> 0 bytes tools/makeadf/Makefile | 16 ++++++++++ tools/makeadf/makeadf.c | 64 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+) delete mode 100755 tools/makeadf create mode 100644 tools/makeadf/Makefile create mode 100644 tools/makeadf/makeadf.c diff --git a/tools/makeadf b/tools/makeadf deleted file mode 100755 index f7c7e5843c788bc97836673e1bea039463184e96..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8784 zcmeHNU2GIp6uwiouoT+e8h?s{8PF9}q$LqW1=3V=^bXbMANV zIp?1Homm*}<=el0yS0unWesB|S{P$tw5e9cPB9fd#x|kpXq+GFdtQ58JNz<@Hj2^+ zZ;L3-k1*tXNPBIl(M0&u!d{UWxiO?88clO<8xuD59BGa>x)GbfRF*aaA>1GVcEXD} zx9nWZst+~CyV~KzyI)$k*mVfXcx&Z=6OWG@$*f^wtU2CI8SkL9CoEHSMpon(w`?Pm3~GzQ^(EaNFF@a^N(UlVk^c@h8gp18t!I?1i$saPh-v$nY+ zURdVm#v|Muk8*T{^JMhj;;Ay;4(UMH8;@eGcY{H59?zswnY269yx+HEJa$R)2Se}v z1h=j;^z!d?aNwmEwf+J3H+H?( z4gr*)X`I4zp_PH@r#8P8?*sG(G_oV1_|)8bQ{2_01b_S_RtSx$XtYLm&N91`iCFi@ z@#F|F$$e;)$J@Uvn>K&3j};0RqbGO&P4ufX{%>fX{%>!2gqhVZHE^KKZMv7xI-ktxB8F=VogVy{J|6$x8vf z@ZEX(7Q7(l3UigG@VD-qwnT8@y`okvXg7=6k{&M$52YMB%R*-_&0Oy)%+mPB`n0Y% zQ}garczu1UrD-a-Jhi4_YJFMJs#xwB?WPr&)T+v)wiGy-U#j8bCG?SvjQi!Aj199&?ys266=(^ujJilI-pehA{oyv;EOyZH*UkLf4# zmD*u&R$Me*CRN~$g)>VR+2cAv$Ftn z(r z+W>Mz;kf5q!&Bqjm@wiw+rV9Vlvdo4iYC%*r#MDoyK&Zp`@}!)#pAk){*A8FG$iio zI&i|_{yzX5Pq2_eH*3yK+yjJh5$oQs(tRMEvC#b=6r;l)XzB_%fTtG^G+{b(@y@@| zgz0|LJ5L8*UQGYDb&lJ5@;U?QB%WW0{PofR#((dU+** h+@X#O9#L&i%{;Ytx}xl|hV|;ny15lw@lH^3{{ZpsHSPca diff --git a/tools/makeadf/Makefile b/tools/makeadf/Makefile new file mode 100644 index 0000000..167c1f7 --- /dev/null +++ b/tools/makeadf/Makefile @@ -0,0 +1,16 @@ +MAKEADF=./bin/makeadf +SRCS=makeadf.c +HOST_WARNINGS=-pedantic-errors -Wfatal-errors -Wall -Werror -Wextra -Wno-unused-parameter -Wshadow +HOST_CFLAGS=$(HOST_WARNINGS) + +$(MAKEADF): out bin $(SRCS) + gcc $(HOST_CFLAGS) $(SRCS) -o $(MAKEADF) + +out: + mkdir out + +bin: + mkdir bin + +clean: + rm -r out bin \ No newline at end of file diff --git a/tools/makeadf/makeadf.c b/tools/makeadf/makeadf.c new file mode 100644 index 0000000..ca995a5 --- /dev/null +++ b/tools/makeadf/makeadf.c @@ -0,0 +1,64 @@ +/* + * http://eab.abime.net/showpost.php?p=895070&postcount=6 + * Makes a disk image of 901120 (0xdc000) bytes. + * Calculates boot block checksum. + */ + +#include +#include +#include + +#define DISKSIZE (0xdc000) + +uint8_t image[DISKSIZE]; + + +static void boot_chksum(uint8_t *p) +{ + uint32_t oldchk,chk=0; + int i; + + memset(p+4,0,4); + for (i=0; i<1024; i+=4) { + oldchk = chk; + chk += ((uint32_t)p[i+0] << 24) | ((uint32_t)p[i+1] << 16) | + ((uint32_t)p[i+2] << 8) | p[i+3]; + if (chk < oldchk) + ++chk; /* carry */ + } + + chk = ~chk; + p[4] = (uint8_t)((chk >> 24) & 0xff); + p[5] = (uint8_t)((chk >> 16) & 0xff); + p[6] = (uint8_t)((chk >> 8) & 0xff); + p[7] = (uint8_t)(chk & 0xff); +} + + +int main(int argc,char *argv[]) +{ + FILE *f; + int rc = 1; + size_t len; + + if (argc == 2) { + if ((f = fopen(argv[1],"rb"))) { + len = fread(image,1,DISKSIZE,f); + if (len > 0) { + if (len < DISKSIZE) + memset(image+len,0,DISKSIZE-len); + boot_chksum(image); + fwrite(image,1,DISKSIZE,stdout); + rc = 0; + } + else + fprintf(stderr,"Image read error!\n"); + } + else + fprintf(stderr,"Cannot open '%s'!\n",argv[0]); + } + else + fprintf(stderr,"Usage: %s \n",argv[0]); + + return rc; +}